]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: reorganize source file handling in copy_range
authorEric Sandeen <sandeen@redhat.com>
Wed, 10 Jul 2019 15:37:25 +0000 (11:37 -0400)
committerEric Sandeen <sandeen@redhat.com>
Wed, 10 Jul 2019 15:37:25 +0000 (11:37 -0400)
Rename and rearrange some of the vars related to using an open
file number as the source file, so that we don't temporarily
store a non-fd number in a var called "fd," and do the fd
assignment in a consistent code location.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/copy_file_range.c

index 4a0e7a7759c0373409336483c5193dc351a71459..b7b9fd88e77bdc3c154d63d813c31ff0bf0cdd10 100644 (file)
@@ -84,7 +84,8 @@ copy_range_f(int argc, char **argv)
        int opt;
        int ret;
        int fd;
-       int src_file_arg = 1;
+       int src_path_arg = 1;
+       int src_file_nr = 0;
        size_t fsblocksize, fssectsize;
 
        init_cvtnum(&fsblocksize, &fssectsize);
@@ -113,26 +114,27 @@ copy_range_f(int argc, char **argv)
                        }
                        break;
                case 'f':
-                       fd = atoi(argv[1]);
-                       if (fd < 0 || fd >= filecount) {
-                               printf(_("value %d is out of range (0-%d)\n"),
-                                       fd, filecount-1);
+                       src_file_nr = atoi(argv[1]);
+                       if (src_file_nr < 0 || src_file_nr >= filecount) {
+                               printf(_("file value %d is out of range (0-%d)\n"),
+                                       src_file_nr, filecount - 1);
                                return 0;
                        }
-                       fd = filetable[fd].fd;
-                       /* Expect no src_file arg */
-                       src_file_arg = 0;
+                       /* Expect no src_path arg */
+                       src_path_arg = 0;
                        break;
                }
        }
 
-       if (optind != argc - src_file_arg)
+       if (optind != argc - src_path_arg)
                return command_usage(&copy_range_cmd);
 
-       if (src_file_arg) {
+       if (src_path_arg) {
                fd = openfile(argv[optind], NULL, IO_READONLY, 0, NULL);
                if (fd < 0)
                        return 0;
+       } else {
+               fd = filetable[src_file_nr].fd;
        }
 
        if (src == 0 && dst == 0 && len == 0) {