mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-25 13:29:03 +02:00
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>
This commit is contained in:
@@ -2815,7 +2815,7 @@ new_tmpfile(int *fd, int local, const char *path)
|
|||||||
if (fd_tmp == -1)
|
if (fd_tmp == -1)
|
||||||
goto err_new_tmpfile;
|
goto err_new_tmpfile;
|
||||||
|
|
||||||
if (x_i_fchmod(fd_tmp, 0600) == -1)
|
if (fchmod(fd_tmp, 0600) == -1)
|
||||||
goto err_new_tmpfile;
|
goto err_new_tmpfile;
|
||||||
|
|
||||||
flags = fcntl(fd_tmp, F_GETFL);
|
flags = fcntl(fd_tmp, F_GETFL);
|
||||||
@@ -3048,80 +3048,6 @@ x_i_memcmp(const void *a, const void *b, unsigned long n)
|
|||||||
return 0;
|
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
|
int
|
||||||
x_i_fsync(int fd)
|
x_i_fsync(int fd)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
check_cmd(cmd_helper_cat);
|
check_cmd(cmd_helper_cat);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* system prototypes
|
||||||
|
*/
|
||||||
|
int fchmod(int fd, mode_t mode);
|
||||||
|
|
||||||
#ifndef NVMUTIL_H
|
#ifndef NVMUTIL_H
|
||||||
#define NVMUTIL_H
|
#define NVMUTIL_H
|
||||||
|
|
||||||
@@ -465,11 +470,6 @@ void *x_v_memcpy(void *dst,
|
|||||||
const void *src, unsigned long n);
|
const void *src, unsigned long n);
|
||||||
int x_i_memcmp(const void *a,
|
int x_i_memcmp(const void *a,
|
||||||
const void *b, unsigned long n);
|
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);
|
int x_i_fsync(int fd);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user