allow it to accept the text form of a file handle
[xfstests-dev.git] / dmapi / src / suite1 / cmd / get_fileattr.c
index 3856ae905f56d79af8d469b1d0f1d7b9c118c9a0..26d6ece137335813c98fb3d7954fba90a8792755 100644 (file)
@@ -48,7 +48,7 @@ char  *Progname;
 static void
 usage(void)
 {
-       fprintf(stderr, "Usage: %s [-a|-A] [-s sid] [-t token] pathname\n",
+       fprintf(stderr, "Usage: %s [-a|-A] [-s sid] [-t token] {pathname|handle}\n",
                Progname);
        exit(1);
 }
@@ -61,14 +61,17 @@ main(
 {
        dm_sessid_t     sid = DM_NO_SESSION;
        dm_token_t      token = DM_NO_TOKEN;
-/*     char            buffer[500];*/
+#if 0
+       char            buffer[500];
+#endif
        void            *hanp;
        size_t          hlen;
        dm_stat_t       dmstat;
-       char            *pathname;
+       char            *pathname_obj;
        int             a_flag = 0;
        char            *name;
        int             opt;
+       int             validate = 0;
 
        if (Progname = strrchr(argv[0], '/')) {
                Progname++;
@@ -77,7 +80,7 @@ main(
        }
 
        opterr = 0;
-       while ((opt = getopt(argc, argv, "Aas:t:")) != EOF) {
+       while ((opt = getopt(argc, argv, "Aas:t:v")) != EOF) {
                switch (opt) {
                case 'A':
                        a_flag = 2;
@@ -91,6 +94,9 @@ main(
                case 't':
                        token = atol(optarg);
                        break;
+               case 'v':
+                       validate = 1;
+                       break;
                case '?':
                        usage();
                }
@@ -98,28 +104,29 @@ main(
        if (optind + 1 != argc) {
                usage();
        }
-       pathname = argv[optind];
+       pathname_obj = argv[optind];
 
        if (dm_init_service(&name) == -1)  {
-               fprintf(stderr, "Can't inititalize the DMAPI\n");
+               fprintf(stderr, "Can't initialize the DMAPI\n");
                exit(1);
        }
        if (sid == DM_NO_SESSION)
                find_test_session(&sid);
 
+       /* Get the file's handle or convert the external handle. */
+
+       if (opaque_to_handle(pathname_obj, &hanp, &hlen)) {
+               fprintf(stderr, "can't get handle for %s\n", pathname_obj);
+               exit(1);
+       }
+
        if (!a_flag) {
-               fprintf(stdout, "path            %s\n", pathname);
+               fprintf(stdout, "path/handle            %s\n", pathname_obj);
 
                /* Get the file's state, print it, then verify it against
                   what is in the file's stat block.
                */
 
-               if (dm_path_to_handle(pathname, &hanp, &hlen)) {
-                       fprintf(stderr, "dm_path_to_handle failed, %s\n",
-                               strerror(errno));
-                       exit(1);
-               }
-
                if (dm_get_fileattr(sid, hanp, hlen, token,
        DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT,
                    &dmstat)) {
@@ -129,8 +136,9 @@ main(
                }
 
                print_state(&dmstat);
-               (void)validate_state(&dmstat, pathname, 1);
-/* XXX Shut off for now
+               if(validate)
+                       (void)validate_state(&dmstat, pathname_obj, 1);
+#if 0
        } else {
                if ((rc = filesys_bulkscan_init(pathname, &scanp)) != 0) {
                        fprintf(stderr, "filesys_bulkscan failed, %s\n",
@@ -163,7 +171,7 @@ main(
                                fileio_err_image(rc));
                        exit(1);
                }
-XXX Shut off for now.  */
+#endif
        }
        exit(0);
 }