diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/copy.c | 2 | ||||
-rw-r--r-- | src/shared/util.c | 36 | ||||
-rw-r--r-- | src/shared/util.h | 5 |
3 files changed, 8 insertions, 35 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c index 775a339856..1282cb88be 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -372,7 +372,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned } if (chattr_flags != 0) - (void) chattr_fd(fdt, true, chattr_flags); + (void) chattr_fd(fdt, chattr_flags, (unsigned) -1); r = copy_file_fd(from, fdt, true); if (r < 0) { diff --git a/src/shared/util.c b/src/shared/util.c index de56d98feb..da75667c80 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -7678,7 +7678,7 @@ int same_fd(int a, int b) { return fa == fb; } -int chattr_fd(int fd, bool b, unsigned mask) { +int chattr_fd(int fd, unsigned value, unsigned mask) { unsigned old_attr, new_attr; assert(fd >= 0); @@ -7689,21 +7689,17 @@ int chattr_fd(int fd, bool b, unsigned mask) { if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0) return -errno; - if (b) - new_attr = old_attr | mask; - else - new_attr = old_attr & ~mask; - + new_attr = (old_attr & ~mask) | (value & mask); if (new_attr == old_attr) return 0; if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0) return -errno; - return 0; + return 1; } -int chattr_path(const char *p, bool b, unsigned mask) { +int chattr_path(const char *p, unsigned value, unsigned mask) { _cleanup_close_ int fd = -1; assert(p); @@ -7715,29 +7711,7 @@ int chattr_path(const char *p, bool b, unsigned mask) { if (fd < 0) return -errno; - return chattr_fd(fd, b, mask); -} - -int change_attr_fd(int fd, unsigned value, unsigned mask) { - unsigned old_attr, new_attr; - - assert(fd >= 0); - - if (mask == 0) - return 0; - - if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0) - return -errno; - - new_attr = (old_attr & ~mask) |(value & mask); - - if (new_attr == old_attr) - return 0; - - if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0) - return -errno; - - return 0; + return chattr_fd(fd, value, mask); } int read_attr_fd(int fd, unsigned *ret) { diff --git a/src/shared/util.h b/src/shared/util.h index e7a5d6366e..b41090bf70 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -1058,9 +1058,8 @@ int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags); int same_fd(int a, int b); -int chattr_fd(int fd, bool b, unsigned mask); -int chattr_path(const char *p, bool b, unsigned mask); -int change_attr_fd(int fd, unsigned value, unsigned mask); +int chattr_fd(int fd, unsigned value, unsigned mask); +int chattr_path(const char *p, unsigned value, unsigned mask); int read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret); |