]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: clean up the funshare command a bit
authorDarrick J. Wong <djwong@kernel.org>
Wed, 28 Jul 2021 23:01:23 +0000 (19:01 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 28 Jul 2021 23:01:23 +0000 (19:01 -0400)
Add proper argument parsing to the funshare command so that when you
pass it nonexistent --help it will print the help instead of complaining
that it can't convert that to a number.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/prealloc.c

index 2ae8afe967c02b425a44529d87f60a181afd7fa9..a8831c1b25de10e3aaf273eddd97383267f80b0d 100644 (file)
@@ -346,16 +346,24 @@ funshare_f(
        char            **argv)
 {
        xfs_flock64_t   segment;
+       int             c;
        int             mode = FALLOC_FL_UNSHARE_RANGE;
-       int             index = 1;
 
-       if (!offset_length(argv[index], argv[index + 1], &segment)) {
+       while ((c = getopt(argc, argv, "")) != EOF) {
+               switch (c) {
+               default:
+                       command_usage(&funshare_cmd);
+               }
+       }
+       if (optind != argc - 2)
+               return command_usage(&funshare_cmd);
+
+       if (!offset_length(argv[optind], argv[optind + 1], &segment)) {
                exitcode = 1;
                return 0;
        }
 
-       if (fallocate(file->fd, mode,
-                       segment.l_start, segment.l_len)) {
+       if (fallocate(file->fd, mode, segment.l_start, segment.l_len)) {
                perror("fallocate");
                exitcode = 1;
                return 0;