diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-18 04:39:50 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-18 04:39:50 +0000 |
| commit | 3f2a6e749f63d3c0a8e8864081f64f6111698839 (patch) | |
| tree | ff4a884a3340113806f714f3b113cf2d8142fc90 /util/nvmutil | |
| parent | ef2d5ccdf43f6f103ee4e3cde34f4c12dc38a143 (diff) | |
util/nvmutil: use real fsync
that function i added was a load of crap. it
worked, but it was a bit dumb, and crap.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 76 | ||||
| -rw-r--r-- | util/nvmutil/nvmutil.h | 10 |
2 files changed, 6 insertions, 80 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 79ce3b5e..5becd165 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -2815,7 +2815,7 @@ new_tmpfile(int *fd, int local, const char *path) if (fd_tmp == -1) goto err_new_tmpfile; - if (x_i_fchmod(fd_tmp, 0600) == -1) + if (fchmod(fd_tmp, 0600) == -1) goto err_new_tmpfile; flags = fcntl(fd_tmp, F_GETFL); @@ -3048,80 +3048,6 @@ x_i_memcmp(const void *a, const void *b, unsigned long n) return 0; } -/* - * emulate fchmod() using file descriptor - * paths, for old unix portability. should - * work on e.g. BSD/MacOS (/dev/fd/N), - * Linux (/proc/self/fd/N) and others - */ -int -x_i_fchmod(int fd, mode_t mode) -{ - if (x_try_fdpath("/dev/fd/", fd, mode) == 0) - return 0; - - if (x_try_fdpath("/proc/self/fd/", fd, mode) == 0) - return 0; - - errno = ENOSYS; - return -1; -} - -int -x_try_fdpath(const char *prefix, int fd, mode_t mode) -{ - char path[PATH_LEN]; - - unsigned long i = 0; - unsigned long j; - - struct stat st; - - while (prefix[i]) { - if (i >= PATH_LEN - 1) - return -1; - path[i] = prefix[i]; - i++; - } - - j = x_conv_fd(path + i, (unsigned long)fd); - - if (i + j >= PATH_LEN) - return -1; - - i += j; - path[i] = '\0'; - - if (stat(path, &st) < 0) - return -1; - - return chmod(path, mode); -} - -unsigned long -x_conv_fd(char *buf, unsigned long n) -{ - char tmp[256]; - - unsigned long i = 0; - unsigned long j = 0; - - if (n == 0) { - buf[0] = '0'; - return 1; - } - - while (n > 0) { - tmp[i++] = (char)('0' + (n % 10)); - n /= 10; - } - - while (i > 0) - buf[j++] = tmp[--i]; - - return j; -} - int x_i_fsync(int fd) { diff --git a/util/nvmutil/nvmutil.h b/util/nvmutil/nvmutil.h index 119c716f..57ec6bd6 100644 --- a/util/nvmutil/nvmutil.h +++ b/util/nvmutil/nvmutil.h @@ -9,6 +9,11 @@ check_cmd(cmd_helper_cat); */ +/* + * system prototypes + */ +int fchmod(int fd, mode_t mode); + #ifndef NVMUTIL_H #define NVMUTIL_H @@ -465,11 +470,6 @@ void *x_v_memcpy(void *dst, const void *src, unsigned long n); int x_i_memcmp(const void *a, const void *b, unsigned long n); -int x_i_fchmod(int fd, mode_t mode); -int x_try_fdpath(const char *prefix, - int fd, mode_t mode); -unsigned long x_conv_fd(char *buf, - unsigned long n); int x_i_fsync(int fd); |
