From: Goffredo Baroncelli Date: Mon, 16 Mar 2015 19:33:49 +0000 (+0100) Subject: Add change_attr_fd() X-Git-Tag: v219.0~262 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5b9fbd354eddd80051de3cd17510d6be60274931;p=elogind.git Add change_attr_fd() Add change_attr_fd() function to modify the file/directory attribute. --- diff --git a/src/shared/util.c b/src/shared/util.c index 5cbbe8fb7..ad548da82 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); diff --git a/src/shared/util.h b/src/shared/util.h index d229e1e68..29e85bb7e 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -1053,6 +1053,7 @@ 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 read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret);