]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Some of the libhandle routines were not clear whether they were working
authorMandy Kirkconnell <alkirkco@sgi.com>
Fri, 13 Feb 2004 19:12:27 +0000 (19:12 +0000)
committerMandy Kirkconnell <alkirkco@sgi.com>
Fri, 13 Feb 2004 19:12:27 +0000 (19:12 +0000)
on fshandles or file handles.  This mod renames open_by_handle() to
open_by_fshandle() and updates any calling applications to now call
open_by_fshandle() instead.  A new open_by_handle() has been created.

path_to_fshandle() was trying to maintain a hash of fshandles but the
hash was only storing a max of 2 fshandles at a time.  This has been
fixed so the hash can hold multiple fs handles.
define open_by_fshandle()

include/handle.h
libhandle/handle.c
libhandle/jdm.c

index 91357d2788c6e8977a84937f74a69ac6f703bd3a..51839a9a64b1889dc7830776f558a2fd5c5c9796 100644 (file)
@@ -41,10 +41,11 @@ struct fsdmidata;
 struct attrlist_cursor;
 
 extern int  path_to_handle (char *__path, void **__hanp, size_t *__hlen);
-extern int  path_to_fshandle (char *__path, void **__hanp, size_t *__hlen);
+extern int  path_to_fshandle (char *__path, void **__fshanp, size_t *__fshlen);
 extern int  handle_to_fshandle (void *__hanp, size_t __hlen, void **__fshanp,
                                size_t *__fshlen);
 extern void free_handle (void *__hanp, size_t __hlen);
+extern int  open_by_fshandle (void *__fshanp, size_t __fshlen, int __rw);
 extern int  open_by_handle (void *__hanp, size_t __hlen, int __rw);
 extern int  readlink_by_handle (void *__hanp, size_t __hlen, void *__buf,
                                size_t __bs);
index dd6949becb05b78ca7eaf52997ca7b9b189591b7..3b5f8ea61cec5085a4cfb7255e6cc3802ad9d151 100644 (file)
@@ -80,13 +80,14 @@ static struct fdhash *fdhash_head;
 int
 path_to_fshandle(
        char            *path,          /* input,  path to convert */
-       void            **hanp,         /* output, pointer to data */
-       size_t          *hlen)          /* output, size of returned data */
+       void            **fshanp,       /* output, pointer to data */
+       size_t          *fshlen)        /* output, size of returned data */
 {
        int             result;
        int             fd;
        comarg_t        obj;
        struct fdhash   *fdhp;
+       struct fdhash   *tmphp=NULL;
 
        fd = open(path, O_RDONLY);
        if (fd < 0)
@@ -94,7 +95,7 @@ path_to_fshandle(
 
        obj.path = path;
        result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_FSHANDLE,
-                               obj, hanp, hlen);
+                               obj, fshanp, fshlen);
        if (result >= 0) {
                fdhp = malloc(sizeof(struct fdhash));
                if (fdhp == NULL) {
@@ -105,12 +106,22 @@ path_to_fshandle(
                fdhp->fsfd = fd;
                fdhp->fnxt = NULL;
                strncpy(fdhp->fspath, path, sizeof(fdhp->fspath));
-               memcpy(fdhp->fsh, *hanp, FSIDSIZE);
-
-               if (fdhash_head)
-                       fdhash_head->fnxt = fdhp;
-               else
-                       fdhash_head       = fdhp;
+               memcpy(fdhp->fsh, *fshanp, FSIDSIZE);
+
+               if (fdhash_head) {
+                       for( tmphp=fdhash_head; tmphp; tmphp=tmphp->fnxt ) {
+                               if ( fdhp->fsfd == tmphp->fsfd ) {
+                                       free (fdhp);     /* already in hash */
+                                       break;
+                               }
+                       }
+                       if (tmphp == NULL) {     /* not in hash, add it now */
+                               fdhp->fnxt = fdhash_head;
+                               fdhash_head = fdhp;
+                       }
+               } else {
+                       fdhash_head = fdhp;
+               }
        }
 
        return result;
@@ -210,17 +221,46 @@ obj_to_handle(
        return 0;
 }
 
+int
+open_by_fshandle(
+       void            *fshanp,
+       size_t          fshlen,
+       int             rw)
+{
+       int             fsfd;
+       char            *path;
+       xfs_fsop_handlereq_t hreq;
+
+       if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
+               return -1;
+
+       hreq.fd       = 0;
+       hreq.path     = NULL;
+       hreq.oflags   = rw | O_LARGEFILE;
+       hreq.ihandle  = fshanp;
+       hreq.ihandlen = fshlen;
+       hreq.ohandle  = NULL;
+       hreq.ohandlen = NULL;
+
+       return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
+}
+
 int
 open_by_handle(
        void            *hanp,
        size_t          hlen,
        int             rw)
 {
-       int             fd;
+       int             fsfd;
        char            *path;
+       void            *fshanp;
+       size_t          fshlen;
        xfs_fsop_handlereq_t hreq;
 
-       if ((fd = handle_to_fsfd(hanp, &path)) < 0)
+       if (handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0)
+               return -1;
+
+       if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
                return -1;
 
        hreq.fd       = 0;
@@ -231,7 +271,7 @@ open_by_handle(
        hreq.ohandle  = NULL;
        hreq.ohandlen = NULL;
 
-       return xfsctl(path, fd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
+       return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
 }
 
 int
index c93a3988d8b414c10717563b0753f85ac7fc8d15..7a6f14ed4aa2d14347abb1212b8041f4c1d63223 100644 (file)
@@ -45,7 +45,7 @@ typedef struct fshandle {
        char fsh_space[FSHANDLE_SZ];
 } fshandle_t;
 
-/* private file handle - for use by open_by_handle */
+/* private file handle - for use by open_by_fshandle */
 #define FILEHANDLE_SZ          24
 #define FILEHANDLE_SZ_FOLLOWING        14
 #define FILEHANDLE_SZ_PAD      2
@@ -134,7 +134,7 @@ jdm_open( jdm_fshandle_t *fshp, xfs_bstat_t *statp, intgen_t oflags )
        intgen_t fd;
 
        jdm_fill_filehandle( &filehandle, fshandlep, statp );
-       fd = open_by_handle( ( void * )&filehandle,
+       fd = open_by_fshandle( ( void * )&filehandle,
                             sizeof( filehandle ),
                             oflags );
        return fd;