util/nvmutil: only write parts that are modified

Old behaviour: always write both gbe sections.

New behaviour: only write back what was changed.
fsdg20230625
Leah Rowe 2023-01-17 10:23:21 +00:00
parent d0fa08d58d
commit 8dea350a62
1 changed files with 13 additions and 12 deletions

View File

@ -439,21 +439,22 @@ writeGbeFile(int *fd, const char *filename)
int partnum; int partnum;
errno = 0; errno = 0;
if (pwrite((*fd), (uint8_t *) gbe[0], SIZE_4KB, 0) != SIZE_4KB) for (partnum = 0; partnum < 2; partnum++) {
err(errno, "%s", filename); if (nvmPartModified[partnum]) {
if (pwrite((*fd), (uint8_t *) gbe[1], SIZE_4KB, SIZE_4KB) != SIZE_4KB) printf("Part %d modified\n", partnum);
} else {
fprintf (stderr,
"Part %d NOT modified\n", partnum);
continue;
}
if (pwrite((*fd), (uint8_t *) gbe[partnum], SIZE_4KB,
partnum << 12) != SIZE_4KB)
err(errno, "%s", filename); err(errno, "%s", filename);
}
if (close((*fd))) if (close((*fd)))
err(errno, "%s", filename); err(errno, "%s", filename);
if (errno != 0) if (errno != 0)
err(errno, "%s", filename); err(errno, "%s", filename);
for (partnum = 0; partnum < 2; partnum++) { printf("File `%s` successfully re-written.\n", filename);
if (nvmPartModified[partnum])
printf("Part %d modified\n", partnum);
else
fprintf (stderr,
"Part %d NOT modified\n", partnum);
}
printf("File `%s` successfully modified\n", filename);
} }