From: Darrick J. Wong Date: Wed, 16 Jun 2021 23:08:47 +0000 (-0700) Subject: xfs_io: clean up the funshare command a bit X-Git-Tag: libxfs-5.14-sync_2021-07-02~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f57813d5b0c730af8d5f7c0efe990363ff0d7c15;p=xfsprogs-dev.git xfs_io: clean up the funshare command a bit 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 --- diff --git a/io/prealloc.c b/io/prealloc.c index 2ae8afe9..94cf326f 100644 --- a/io/prealloc.c +++ b/io/prealloc.c @@ -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;