diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:39:59 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:39:59 +0000 |
| commit | fb4f2630056bf4c61c82785c9cc94946b4696d5f (patch) | |
| tree | e2c2114392b59facd949f68eba4ab16b70c06c5e /util/nvmutil/nvmutil.c | |
| parent | 9ef92b3b25c2e774e9469e70a16e8e07d9e1b7a7 (diff) | |
Revert "util/nvmutil: don't use fsync()"
This reverts commit bdb43afac6edef21a15f99b8c3beac01be8b86f7.
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 77f7e412..3cea175d 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1109,7 +1109,12 @@ copy_gbe(void) if (gbe_tmp_size != gbe_file_size) err(EIO, "%s: %s: not the same size", fname, tname); - sync(); + /* + * fsync tmp gbe file, because we will compare + * its contents to what was read (for safety) + */ + if (fsync(tmp_fd) == -1) + err(errno, "%s: fsync (tmpfile copy)", tname); r = rw_file_exact(tmp_fd, bufcmp, gbe_file_size, 0, IO_PREAD, NO_LOOP_EAGAIN, LOOP_EINTR, @@ -1796,7 +1801,13 @@ write_to_gbe_bin(void) write_gbe_file(); - sync(); + /* + * We may otherwise read from + * cache, so we must sync. + */ + if (fsync(tmp_fd) == -1) + err(errno, "%s: fsync (pre-verification)", + tname); check_written_part(0); check_written_part(1); @@ -2033,7 +2044,8 @@ gbe_mv(void) if (r < 0) goto ret_gbe_mv; - sync(); + if (fsync(dest_fd) == -1) + goto ret_gbe_mv; if (x_i_close(dest_fd) == -1) goto ret_gbe_mv; @@ -2147,7 +2159,9 @@ fsync_dir(const char *path) goto err_fsync_dir; } - sync(); + /* sync file on disk */ + if (fsync(dfd) == -1) + goto err_fsync_dir; if (x_i_close(dfd) == -1) goto err_fsync_dir; @@ -3090,7 +3104,7 @@ x_i_rename(const char *src, const char *dst) return -1; } - sync(); + fsync(dfd); x_i_close(sfd); x_i_close(dfd); |
