]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: move inode command arg handling to top
authorEric Sandeen <sandeen@sandeen.net>
Sun, 2 Oct 2016 23:47:47 +0000 (10:47 +1100)
committerDave Chinner <david@fromorbit.com>
Sun, 2 Oct 2016 23:47:47 +0000 (10:47 +1100)
As it stands, collecting the inode number and testing args validity
is all tangled up; for example the test for "-n" having no inode is
buried in an else after a large code block which handles something
else.

Get inode number argument collection and testing out of the way
before doing anything else.

Clean up the error message if a non-numeric inode arg is given.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/open.c

index c8c82b773e102523d553d50c7430f7ca08fb7722..ba8b24325aad4c7f15cb05f529cf25fb21fa23f3 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -813,7 +813,7 @@ inode_f(
 {
        __s32                   count = 0;
        __u64                   lastino = 0;
-       __u64                   userino = 0;
+       __u64                   userino = NULLFSINO;
        char                    *p;
        int                     c;
        int                     verbose = 0;
@@ -835,27 +835,32 @@ inode_f(
                }
        }
 
-       /*
-        * Inode number can be passed with or without extra arguments, so we
-        * should handle inode numbers passed by user out of getopt()
-        */
+       /* Last arg (if present) should be an inode number */
        if (optind < argc) {
-
-               if (ret_next) {
-                       cmd = XFS_IOC_FSBULKSTAT;
-               } else {
-                       if ((argc > 2) && !verbose)
-                               return command_usage(&inode_cmd);
-                       else
-                               cmd = XFS_IOC_FSBULKSTAT_SINGLE;
-               }
-
                userino = strtoull(argv[optind], &p, 10);
                if ((*p != '\0')) {
-                       printf(_("[num] must be a numeric value\n"));
+                       printf(_("%s is not a numeric inode value\n"),
+                               argv[optind]);
                        exitcode = 1;
                        return 0;
                }
+               optind++;
+       }
+
+       /* Extra junk? */
+       if (optind < argc)
+               return command_usage(&inode_cmd);
+
+       /* -n option requires an inode number */
+       if (ret_next && userino == NULLFSINO)
+               return command_usage(&inode_cmd);
+
+       if (userino != NULLFSINO) {
+
+               if (ret_next)   /* get next inode */
+                       cmd = XFS_IOC_FSBULKSTAT;
+               else            /* get this inode */
+                       cmd = XFS_IOC_FSBULKSTAT_SINGLE;
 
                bulkreq.lastip = &userino;
                bulkreq.icount = 1;
@@ -885,9 +890,6 @@ inode_f(
                        printf("%llu\n", userino);
                return 0;
 
-       /* -n option must not be used stand alone */
-       } else if (ret_next) {
-               return command_usage(&inode_cmd);
        }
 
        /* We are finding last inode in use */