summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorGoffredo Baroncelli <kreijack@inwind.it>2015-03-16 20:33:49 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-19 22:20:12 -0400
commit5b9fbd354eddd80051de3cd17510d6be60274931 (patch)
treec5f54884acbd308f9cbce1e19fc6896696d1adb4 /src/shared/util.c
parent0ea37920e7ff6c548dd3388ec4a63b4d130674b4 (diff)
Add change_attr_fd()
Add change_attr_fd() function to modify the file/directory attribute.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5cbbe8fb7d..ad548da82a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -7843,6 +7843,28 @@ int chattr_path(const char *p, bool b, unsigned mask) {
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;
+}
+
int read_attr_fd(int fd, unsigned *ret) {
assert(fd >= 0);