summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-08 20:47:35 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 07:53:43 +0100
commit6c00c6cee5a32b6af0e4c589d74c6974be50aa20 (patch)
tree5a0af75b9a3cb4c0515e563c640dc8e1bee1280c /src/shared
parent0e464d5b334e691a7502b1ca4305c4d85e5b6acb (diff)
util: merge change_attr_fd() and chattr_fd()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/copy.c2
-rw-r--r--src/shared/util.c36
-rw-r--r--src/shared/util.h5
3 files changed, 8 insertions, 35 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c
index 775a33985..1282cb88b 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 d7e4318de..ffde3ff8f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -7634,7 +7634,7 @@ int fd_setcrtime(int fd, usec_t usec) {
return 0;
}
-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);
@@ -7645,21 +7645,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);
@@ -7671,29 +7667,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 2154623af..427b52ef1 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -1057,9 +1057,8 @@ int fd_getcrtime(int fd, usec_t *usec);
int path_getcrtime(const char *p, usec_t *usec);
int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags);
-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);