From 270693fc92e84b264c160b64e6c66ea4196760a7 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 3 Jun 2023 13:44:04 +0100 Subject: util/nvmutil: cleanup: move logic out of main() Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'util') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 19b1d977..69cf929a 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -17,9 +17,6 @@ main(int argc, char *argv[]) err_if((errno = (!((part = PARTNUM[0] - '0') == 0 || part == 1)) || PARTNUM[1] ? EINVAL : errno)); err_if((errno = (!cmd) ? EINVAL : errno)); - - nf = ((cmd == cmd_swap) || (cmd == cmd_copy)) ? SIZE_4KB : nf; - flags = (strcmp(COMMAND, "dump") == 0) ? O_RDONLY : flags; openFiles(FILENAME); readGbeFile(FILENAME); @@ -34,7 +31,7 @@ void openFiles(const char *path) { struct stat st; - xopen(fd, path, flags); + xopen(fd, path, flags = (cmd == cmd_dump) ? O_RDONLY : flags); if ((st.st_size != SIZE_8KB)) err(errno = ECANCELED, "File `%s` not 8KiB", path); xopen(rfd, "/dev/urandom", O_RDONLY); @@ -48,6 +45,7 @@ openFiles(const char *path) void readGbeFile(const char *path) { + nf = ((cmd == cmd_swap) || (cmd == cmd_copy)) ? SIZE_4KB : nf; skipread[part ^ 1] = (cmd == &cmd_copy) | (cmd == &cmd_setchecksum) | (cmd == &cmd_brick); gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB; -- cgit v1.2.1