From e1d8773c5453084bd7016c070a0bbf3b9d043f6d Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 23 Feb 2026 13:41:37 +0000 Subject: nvmutil: split pwrite handling from writeGbe handle it in a separate function, for clarity. the main function just checks each part whether it changed, and then passes control to writeGbe_part. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'util') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 4720095c..ee86de14 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -18,7 +18,7 @@ void cmd_setchecksum(void), cmd_brick(void), swap(int partnum), writeGbe(void), cmd_dump(void), cmd_setmac(void), nvmalloc(void), readGbe(void), checkdir(const char *path), macf(int partnum), hexdump(int partnum), parseMacString(const char *strMac, uint16_t *mac), cmd_swap(void), - openFiles(const char *path), cmd_copy(void); + openFiles(const char *path), cmd_copy(void), writeGbe_part(int); int goodChecksum(int partnum); uint8_t hextonum(char chs), rhex(void); @@ -421,18 +421,21 @@ void writeGbe(void) { for (int p = 0; p < 2; p++) { - if ((!nvmPartChanged[p]) || (flags == O_RDONLY)) - continue; - - swap(p); /* swap bytes on big-endian host CPUs */ - if(pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize) != nf) - err(ERR(), "Couldn't write %ld bytes to '%s' part '%d'", - nf, filename, p); + if ((nvmPartChanged[p]) && (flags != O_RDONLY)) + writeGbe_part(p); } - err_if(close(fd) == -1); } +void +writeGbe_part(int p) +{ + swap(p); /* swap bytes on big-endian host CPUs */ + if(pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize) != nf) + err(ERR(), "Can't write %ld b to '%s' p%d", nf, filename, p); + +} + void swap(int partnum) { -- cgit v1.2.1