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,
#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 )
* code path.
*/
/*#define INDUCE_IO_ERROR*/
+
#if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
/*
* 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).
*/
#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
#include "handle.h"
#include <libxfs.h>
-
/* just pick a value we know is more than big enough */
#define MAXHANSIZ 64
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;
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));
}
+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,
}
+
int
open_by_handle (
void *hanp,
{
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;
}
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;
}
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;
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 )
{
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