From 328148f324e3ade603f4676c2afed8c6d7855873 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Wed, 10 Jul 2019 11:37:25 -0400 Subject: [PATCH] xfs_io: reorganize source file handling in copy_range 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 Reviewed-by: Amir Goldstein Signed-off-by: Eric Sandeen --- io/copy_file_range.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/io/copy_file_range.c b/io/copy_file_range.c index 4a0e7a775..b7b9fd88e 100644 --- a/io/copy_file_range.c +++ b/io/copy_file_range.c @@ -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(©_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) { -- 2.47.2