diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-14 02:21:51 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-01-14 23:18:33 +0100 |
commit | 01b725684f6ba54f0db815669e4e07eb0e02fedb (patch) | |
tree | 26dc8954b513cbc33347f3c9ae1fbbfc0a776f7e /src/shared/util.c | |
parent | 45030287af1e8e76b0feb1cfc3011a0ef2b37d0d (diff) |
machined: use the FS_IMMUTABLE_FL file flag, if available, to implement a "read-only" concept for raw disk images, too
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 9fd2d89556..857bb1b726 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -7791,9 +7791,31 @@ int chattr_path(const char *p, bool b, unsigned mask) { if (mask == 0) return 0; - fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); if (fd < 0) return -errno; return chattr_fd(fd, b, mask); } + +int read_attr_fd(int fd, unsigned *ret) { + assert(fd >= 0); + + if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0) + return -errno; + + return 0; +} + +int read_attr_path(const char *p, unsigned *ret) { + _cleanup_close_ int fd = -1; + + assert(p); + assert(ret); + + fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return read_attr_fd(fd, ret); +} |