From 89184fbce5896c16b687084812fceda5964d6a18 Mon Sep 17 00:00:00 2001 From: Andrew Gildfind Date: Fri, 9 Feb 2001 07:45:14 +0000 Subject: [PATCH] No Message Supplied --- include/handle.h | 1 + include/jdm.h | 43 +++++++++++++++++++----------- include/xfs_fs.h | 17 +++++++++--- libhandle/handle.c | 66 ++++++++++++++++++++++++---------------------- libhandle/jdm.c | 63 ++++++++++++++++++------------------------- 5 files changed, 102 insertions(+), 88 deletions(-) diff --git a/include/handle.h b/include/handle.h index 0400a7046..98b16575c 100644 --- a/include/handle.h +++ b/include/handle.h @@ -41,6 +41,7 @@ extern int path_to_fshandle (char *__path, void **__hanp, size_t *__hlen); extern int fd_to_handle (int __fd, void **__hanp, size_t *__hlen); extern int handle_to_fshandle (void *__hanp, size_t __hlen, void **__fshanp, size_t *__fshlen); +extern int handle_to_fsfd (void *__hanp); extern void free_handle (void *__hanp, size_t __hlen); extern int open_by_handle (void *__hanp, size_t __hlen, int __rw); extern int readlink_by_handle (void *__hanp, size_t __hlen, void *__buf, diff --git a/include/jdm.h b/include/jdm.h index 3d2012018..f49140cc9 100644 --- a/include/jdm.h +++ b/include/jdm.h @@ -33,24 +33,35 @@ #define __JDM_H__ typedef int intgen_t; -typedef void jdm_fshandle_t; +typedef void jdm_fshandle_t; /* filesystem handle */ +typedef void jdm_filehandle_t; /* filehandle */ struct xfs_bstat; -extern jdm_fshandle_t *jdm_getfshandle (char *mntpnt); -extern intgen_t jdm_open (jdm_fshandle_t *fsh, struct xfs_bstat *sp, - intgen_t oflags); -extern intgen_t jdm_readlink (jdm_fshandle_t *fsh, struct xfs_bstat *sp, - char *bufp, size_t bufsz); - -#ifdef EXTATTR - -struct attrlist_cursor; -extern intgen_t jdm_attr_multi (jdm_fshandle_t *fsh, struct xfs_bstat *sp, - char *bufp, int rtrvcnt, int flags); -extern intgen_t jdm_attr_list (jdm_fshandle_t *fsh, struct xfs_bstat *sp, - char *bufp, size_t bufsz, int flags, - struct attrlist_cursor *cursor); -#endif /* EXTATTR */ + + +extern jdm_fshandle_t * +jdm_getfshandle( char *mntpnt); + +extern void +jdm_new_filehandle( jdm_filehandle_t **handlep, /* new filehandle */ + size_t *hlen, /* new filehandle size */ + jdm_fshandle_t *fshandlep, /* filesystem filehandle */ + struct xfs_bstat *sp); /* bulkstat info */ + +extern void +jdm_delete_filehandle( jdm_filehandle_t *handlep,/* filehandle to delete */ + size_t hlen); /* filehandle size */ + +extern intgen_t +jdm_open( jdm_fshandle_t *fshandlep, + struct xfs_bstat *sp, + intgen_t oflags); + +extern intgen_t +jdm_readlink( jdm_fshandle_t *fshandlep, + struct xfs_bstat *sp, + char *bufp, + size_t bufsz); /* macro for determining the size of a structure member */ #define sizeofmember( t, m ) sizeof( ( ( t * )0 )->m ) diff --git a/include/xfs_fs.h b/include/xfs_fs.h index 13413eb93..0a0a481c3 100644 --- a/include/xfs_fs.h +++ b/include/xfs_fs.h @@ -332,6 +332,7 @@ typedef struct xfs_fsop_handlereq { * code path. */ /*#define INDUCE_IO_ERROR*/ + #if (defined(DEBUG) || defined(INDUCE_IO_ERROR)) /* * Error injection. @@ -342,6 +343,16 @@ typedef struct xfs_error_injection { } xfs_error_injection_t; #endif /* DEBUG || INDUCE_IO_ERROR */ +/* + * Compound structure for passing args through ioctl to xfs_attrctl_by_handle + */ +typedef struct xfs_fsop_attr_handlereq { + struct xfs_fsop_handlereq *hreq;/* handle request interface */ + /* structure */ + struct attr_op *ops; /* array of attribute ops */ + int count; /* number of attribute ops */ +} xfs_fsop_attr_handlereq_t; + /* * File system identifier. Should be unique (at least per machine). */ @@ -438,10 +449,10 @@ typedef struct xfs_handle { #define XFS_IOC_SET_RESBLKS _IOR ('X', 114, struct xfs_fsop_resblks) #define XFS_IOC_GET_RESBLKS _IOR ('X', 115, struct xfs_fsop_resblks) #if (defined(DEBUG) || defined(INDUCE_IO_ERROR)) -#define XFS_IOC_ERROR_INJECTION _IOW('X', 116, struct xfs_error_injection) -#define XFS_IOC_ERROR_CLEARALL _IOW('X', 117, struct xfs_error_injection) +#define XFS_IOC_ERROR_INJECTION _IOW('X', 116, struct xfs_error_injection) +#define XFS_IOC_ERROR_CLEARALL _IOW('X', 117, struct xfs_error_injection) #endif /* DEBUG || INDUCE_IO_ERROR */ - +#define XFS_IOC_ATTRCTL_BY_HANDLE _IOWR('X', 118, struct xfs_fsop_attr_handlereq) /* * ioctl command to export information not in standard interfaces * 140: IRIX statvfs.f_fstr field - UUID from the superblock diff --git a/libhandle/handle.c b/libhandle/handle.c index 390912975..80b0a0bf9 100644 --- a/libhandle/handle.c +++ b/libhandle/handle.c @@ -43,7 +43,6 @@ #include "handle.h" #include - /* just pick a value we know is more than big enough */ #define MAXHANSIZ 64 @@ -62,12 +61,23 @@ typedef union { char *path; } comarg_t; -int obj_to_handle ( - int fsfd, - int opcode, - comarg_t obj, - void **hanp, - size_t *hlen); + +int +obj_to_handle ( + int fsfd, + int opcode, + comarg_t obj, + void **hanp, + size_t *hlen); + + +/* + * Filesystem Handle -> Open File Descriptor Cache + * + * Maps filesystem handles to a corresponding open file descriptor for that + * filesystem. We need this because we're doing handle operations via ioctl + * and we need to remember the open file descriptor for each filesystem. + */ struct fdhash { int fsfd; @@ -98,7 +108,7 @@ path_to_fshandle ( obj.path = path; result = obj_to_handle (fd, XFS_IOC_PATH_TO_FSHANDLE, - obj, hanp, hlen); + obj, hanp, hlen); if (result >= 0) { fdhp = malloc(sizeof(struct fdhash)); @@ -187,6 +197,19 @@ handle_to_fshandle ( } +int +handle_to_fsfd(void *hanp) +{ + struct fdhash *fdhp; + + for (fdhp = fdhash_head; fdhp != NULL; fdhp = fdhp->fnxt) { + if (memcmp(fdhp->fsh, hanp, FSIDSIZE) == 0) + return fdhp->fsfd; + } + return -1; +} + + int obj_to_handle ( int fsfd, @@ -231,6 +254,7 @@ obj_to_handle ( } + int open_by_handle ( void *hanp, @@ -239,20 +263,9 @@ open_by_handle ( { int fd; int result; - struct fdhash *fdhp; xfs_fsop_handlereq_t hreq; - fd = -1; - - for (fdhp = fdhash_head; fdhp != NULL; fdhp = fdhp->fnxt) { - - if (memcmp(fdhp->fsh, hanp, FSIDSIZE) == 0) { - fd = fdhp->fsfd; - break; - } - } - - if (fd < 0) { + if ((fd = handle_to_fsfd(hanp)) < 0) { errno = EBADF; return -1; } @@ -278,21 +291,10 @@ readlink_by_handle ( size_t bufsiz) { int fd; - struct fdhash *fdhp; xfs_fsop_handlereq_t hreq; - fd = -1; - - for (fdhp = fdhash_head; fdhp != NULL; fdhp = fdhp->fnxt) { - - if (memcmp(fdhp->fsh, hanp, FSIDSIZE) == 0) { - fd = fdhp->fsfd; - break; - } - } - - if (fd < 0) { + if ((fd = handle_to_fsfd(hanp)) < 0) { errno = EBADF; return -1; } diff --git a/libhandle/jdm.c b/libhandle/jdm.c index aae9be18a..b36f77b27 100644 --- a/libhandle/jdm.c +++ b/libhandle/jdm.c @@ -52,9 +52,10 @@ typedef struct filehandle { xfs_ino_t fh_ino; /* 64 bit ino */ } filehandle_t; + static void jdm_fill_filehandle( filehandle_t *handlep, - fshandle_t *fshandlep, + fshandle_t *fshandlep, xfs_bstat_t *statp ) { handlep->fh_fshandle = *fshandlep; @@ -96,6 +97,30 @@ jdm_getfshandle( char *mntpnt ) return ( jdm_fshandle_t * )fshandlep; } + +/* externally visible functions */ + +void +jdm_new_filehandle( jdm_filehandle_t **handlep, + size_t *hlen, + jdm_fshandle_t *fshandlep, + xfs_bstat_t *statp) +{ + /* allocate and fill filehandle */ + *hlen = sizeof(filehandle_t); + *handlep = (filehandle_t *) malloc(*hlen); + + if (*handlep) + jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp); +} + +/* ARGSUSED */ +void +jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen ) +{ + free(handlep); +} + intgen_t jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags ) { @@ -126,39 +151,3 @@ jdm_readlink( jdm_fshandle_t *fshp, bufsz ); return rval; } - -#ifdef EXTATTR -intgen_t -jdm_attr_multi( jdm_fshandle_t *fshp, - xfs_bstat_t *statp, - char *bufp, int rtrvcnt, int flags) -{ - register fshandle_t *fshandlep = ( fshandle_t * )fshp; - filehandle_t filehandle; - intgen_t rval; - - jdm_fill_filehandle( &filehandle, fshandlep, statp ); - rval = attr_multi_by_handle ( ( void * )&filehandle, - sizeof( filehandle ), - (void *) bufp, - rtrvcnt, flags); - return rval; -} - -intgen_t -jdm_attr_list( jdm_fshandle_t *fshp, - xfs_bstat_t *statp, - char *bufp, size_t bufsz, int flags, - struct attrlist_cursor *cursor) -{ - register fshandle_t *fshandlep = ( fshandle_t * )fshp; - filehandle_t filehandle; - intgen_t rval; - - jdm_fill_filehandle( &filehandle, fshandlep, statp ); - rval = attr_list_by_handle (( void * )&filehandle, - sizeof( filehandle ), - bufp, bufsz, flags, cursor); - return rval; -} -#endif -- 2.47.2