Allow user to specify handles, rather than paths which the tool will
[xfstests-dev.git] / dmapi / src / suite1 / cmd / handle_to_path.c
index 305023a8f5e8483361de9e1091305ee0efa75a4f..46a1cd757eeb0bc21f364fad65c36c606f1b29a6 100644 (file)
 
 #include <lib/dmport.h>
 
+#include <getopt.h>
+#ifdef linux
+#include <xfs/xfs_fs.h>
+#include <xfs/handle.h>
+#endif
+
 /*---------------------------------------------------------------------------
 
 Test program used to test the DMAPI function dm_handle_to_path().  The
 command line is:
 
-        handle_to_path [-b buflen] dirpath objpath
+        handle_to_path [-b buflen] {dirpath|dirhandle} {objpath|objhandle}
 
 There are two parameters.  The first is the pathname of a directory,
 and the second is the pathname of a file, directory, or symbolic link
@@ -72,7 +78,7 @@ char  *Progname;
 static void
 usage(void)
 {
-       fprintf(stderr, "usage:\t%s [-b buflen] dirpath objpath\n", Progname);
+       fprintf(stderr, "usage:\t%s [-b buflen] {dirpath|dirhandle} {objpath|objhandle}\n", Progname);
        exit(1);
 }
 
@@ -84,8 +90,8 @@ main(
 {
        char            *dirpath;
        char            *objpath;
-       void            *hanp1, *hanp2, *hanp1a;
-       size_t          hlen1, hlen2, hlen1a;
+       void            *hanp1, *hanp2;
+       size_t          hlen1, hlen2;
        void            *pathbufp;
        size_t          buflen = 1024;
        size_t          rlenp;
@@ -115,34 +121,18 @@ main(
        objpath = argv[optind];
 
        if (dm_init_service(&name)) {
-               fprintf(stderr, "Can't inititalize the DMAPI\n");
+               fprintf(stderr, "Can't initialize the DMAPI\n");
                return(1);
        }
 
-printf("about to call dm_path_to_handle for %s\n", dirpath);
-       if (dm_path_to_handle(dirpath, &hanp1, &hlen1)) {
-               fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
-                       dirpath, errno, strerror(errno));
-               return(1);
-       }
-printf("about to call path_to_handle for %s\n", dirpath);
-       if (path_to_handle(dirpath, &hanp1a, &hlen1a)) {
-               fprintf(stderr, "path_to_handle failed for %s, (%d) %s\n",
-                       dirpath, errno, strerror(errno));
-               return(1);
+       if (opaque_to_handle(dirpath, &hanp1, &hlen1)) {
+               fprintf(stderr, "can't get handle for dir %s\n", dirpath);
+               exit(1);
        }
-       if(hlen1 != hlen1a){
-               fprintf(stderr, "dm_path_to_handle != path_to_handle, %d != %d\n",
-                       hlen1, hlen1a);
-       }
-       if( memcmp(hanp1, hanp1a, hlen1) != 0 ){
-               fprintf(stderr, "dm_path_to_handle != path_to_handle, handles differ\n");
-       }
-printf("about to call dm_path_to_handle for %s\n", objpath);
-       if (dm_path_to_handle(objpath, &hanp2, &hlen2)) {
-               fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
-                       objpath, errno, strerror(errno));
-               return(1);
+
+       if (opaque_to_handle(objpath, &hanp2, &hlen2)) {
+               fprintf(stderr, "can't get handle for obj %s\n", objpath);
+               exit(1);
        }
 
        if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
@@ -150,7 +140,6 @@ printf("about to call dm_path_to_handle for %s\n", objpath);
                return(1);
        }
 
-printf("about to call handle_to_path\n");
        if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
            buflen, pathbufp, &rlenp)) {
                if (errno == E2BIG) {
@@ -162,10 +151,11 @@ printf("about to call handle_to_path\n");
                }
                return(1);
        }
-       fprintf(stderr, "rlenp is %d, pathbufp is %s\n", rlenp, pathbufp);
+       fprintf(stderr, "rlenp is %d, pathbufp is %s\n", rlenp, (char*)pathbufp);
        if (strlen(pathbufp) + 1 != rlenp) {
                fprintf(stderr, "rlenp is %d, should be %d\n", rlenp,
                        strlen(pathbufp) + 1);
                return(1);
        }
+       exit(0);
 }