diff options
author | Denys Vlasenko | 2021-06-23 12:45:51 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-06-23 12:56:40 +0200 |
commit | 96436fb36a5fa0ac8e993fb093b4788fb5448afe (patch) | |
tree | 6804eb71f9dd765b193be9875ad4974d702f3d59 /e2fsprogs/e2fs_lib.c | |
parent | e7ff017a1a8a429aabb02e80fbede1ce1126d8ea (diff) | |
download | busybox-96436fb36a5fa0ac8e993fb093b4788fb5448afe.zip busybox-96436fb36a5fa0ac8e993fb093b4788fb5448afe.tar.gz |
e2fsprogs/*: remove ioctl calling obfuscation
function old new delta
change_attributes 326 416 +90
list_attributes 222 248 +26
close_silently 22 - -22
.rodata 103722 103692 -30
fgetsetversion 74 - -74
fgetsetprojid 107 - -107
fgetsetflags 148 - -148
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 2/1 up/down: 116/-381) Total: -265 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'e2fsprogs/e2fs_lib.c')
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 119 |
1 files changed, 1 insertions, 118 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index 8d56add..0ec4eb2 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c @@ -8,8 +8,6 @@ #include "libbb.h" #include "e2fs_lib.h" -#define HAVE_EXT2_IOCTLS 1 - #if INT_MAX == LONG_MAX #define IF_LONG_IS_SAME(...) __VA_ARGS__ #define IF_LONG_IS_WIDER(...) @@ -18,14 +16,6 @@ #define IF_LONG_IS_WIDER(...) __VA_ARGS__ #endif -static void close_silently(int fd) -{ - int e = errno; - close(fd); - errno = e; -} - - /* Iterate a function on each entry of a directory */ int iterate_on_dir(const char *dir_name, int FAST_FUNC (*func)(const char *, struct dirent *, void *), @@ -45,113 +35,6 @@ int iterate_on_dir(const char *dir_name, return 0; } - -/* Get/set a file version on an ext2 file system */ -int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version) -{ -#if HAVE_EXT2_IOCTLS - int fd, r; - IF_LONG_IS_WIDER(unsigned ver;) - - fd = open(name, O_RDONLY | O_NONBLOCK); - if (fd == -1) - return -1; - if (!get_version) { - IF_LONG_IS_WIDER( - ver = (unsigned) set_version; - r = ioctl(fd, EXT2_IOC_SETVERSION, &ver); - ) - IF_LONG_IS_SAME( - r = ioctl(fd, EXT2_IOC_SETVERSION, (void*)&set_version); - ) - } else { - IF_LONG_IS_WIDER( - r = ioctl(fd, EXT2_IOC_GETVERSION, &ver); - *get_version = ver; - ) - IF_LONG_IS_SAME( - r = ioctl(fd, EXT2_IOC_GETVERSION, (void*)get_version); - ) - } - close_silently(fd); - return r; -#else /* ! HAVE_EXT2_IOCTLS */ - errno = EOPNOTSUPP; - return -1; -#endif /* ! HAVE_EXT2_IOCTLS */ -} - -int fgetsetprojid(const char *name, uint32_t *get, uint32_t set) -{ -#if HAVE_EXT2_IOCTLS - struct ext2_fsxattr fsxattr; - int fd, r; - - fd = open(name, O_RDONLY | O_NONBLOCK); - if (fd == -1) - return -1; - r = ioctl(fd, EXT2_IOC_FSGETXATTR, &fsxattr); - /* note: ^^^ may fail in 32-bit userspace on 64-bit kernel (seen on 4.12.0) */ - if (r == 0) { - if (get) { - *get = fsxattr.fsx_projid; - } else { - fsxattr.fsx_projid = set; - r = ioctl(fd, EXT2_IOC_FSSETXATTR, &fsxattr); - } - } - close_silently(fd); - return r; -#else /* ! HAVE_EXT2_IOCTLS */ - errno = EOPNOTSUPP; - return -1; -#endif /* ! HAVE_EXT2_IOCTLS */ -} - -/* Get/set a file flags on an ext2 file system */ -int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) -{ -#if HAVE_EXT2_IOCTLS - struct stat buf; - int fd, r; - IF_LONG_IS_WIDER(unsigned f;) - - if (stat(name, &buf) == 0 /* stat is ok */ - && !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) - ) { - goto notsupp; - } - fd = open(name, O_RDONLY | O_NONBLOCK); /* neither read nor write asked for */ - if (fd == -1) - return -1; - - if (!get_flags) { - IF_LONG_IS_WIDER( - f = (unsigned) set_flags; - r = ioctl(fd, EXT2_IOC_SETFLAGS, &f); - ) - IF_LONG_IS_SAME( - r = ioctl(fd, EXT2_IOC_SETFLAGS, (void*)&set_flags); - ) - } else { - IF_LONG_IS_WIDER( - r = ioctl(fd, EXT2_IOC_GETFLAGS, &f); - *get_flags = f; - ) - IF_LONG_IS_SAME( - r = ioctl(fd, EXT2_IOC_GETFLAGS, (void*)get_flags); - ) - } - - close_silently(fd); - return r; - notsupp: -#endif /* HAVE_EXT2_IOCTLS */ - errno = EOPNOTSUPP; - return -1; -} - - /* Print file attributes on an ext2 file system */ const uint32_t e2attr_flags_value[] ALIGN4 = { #ifdef ENABLE_COMPRESSION @@ -215,7 +98,7 @@ static const char e2attr_flags_lname[] ALIGN1 = "Verity" "\0" /* Another trailing NUL is added by compiler */; -void print_e2flags(FILE *f, unsigned long flags, unsigned options) +void print_e2flags(FILE *f, unsigned flags, unsigned options) { const uint32_t *fv; const char *fn; |