From 45030287af1e8e76b0feb1cfc3011a0ef2b37d0d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 14 Jan 2015 02:04:17 +0100 Subject: [PATCH] util: the chattr flags field is actually unsigned, judging by kernel sources Unlike some client code suggests... --- src/shared/copy.c | 4 ++-- src/shared/copy.h | 4 ++-- src/shared/util.c | 14 +++++++++++--- src/shared/util.h | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/shared/copy.c b/src/shared/copy.c index b681f6f10..0239a5806 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -359,7 +359,7 @@ int copy_file_fd(const char *from, int fdt, bool try_reflink) { return r; } -int copy_file(const char *from, const char *to, int flags, mode_t mode, int chattr_flags) { +int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags) { int fdt, r; assert(from); @@ -389,7 +389,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, int chat return 0; } -int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, int chattr_flags) { +int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags) { _cleanup_free_ char *t; int r; diff --git a/src/shared/copy.h b/src/shared/copy.h index e4e307912..8de0cfba3 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -25,8 +25,8 @@ #include int copy_file_fd(const char *from, int to, bool try_reflink); -int copy_file(const char *from, const char *to, int flags, mode_t mode, int chattr_flags); -int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, int chattr_flags); +int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags); +int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags); int copy_tree(const char *from, const char *to, bool merge); int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge); int copy_directory_fd(int dirfd, const char *to, bool merge); diff --git a/src/shared/util.c b/src/shared/util.c index 1210900bc..9fd2d8955 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -7758,11 +7758,14 @@ int same_fd(int a, int b) { return fa == fb; } -int chattr_fd(int fd, bool b, int mask) { - int old_attr, new_attr; +int chattr_fd(int fd, bool b, 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; @@ -7780,9 +7783,14 @@ int chattr_fd(int fd, bool b, int mask) { return 0; } -int chattr_path(const char *p, bool b, int mask) { +int chattr_path(const char *p, bool b, unsigned mask) { _cleanup_close_ int fd = -1; + assert(p); + + if (mask == 0) + return 0; + fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); if (fd < 0) return -errno; diff --git a/src/shared/util.h b/src/shared/util.h index 850019ab9..e58a17a82 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -1074,7 +1074,7 @@ 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, int mask); -int chattr_path(const char *p, bool b, int mask); +int chattr_fd(int fd, bool b, unsigned mask); +int chattr_path(const char *p, bool b, unsigned mask); #define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim }) -- 2.30.2