]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chattr-util: add inode_type_can_chattr() helper
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Aug 2025 20:38:30 +0000 (22:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Sep 2025 19:58:00 +0000 (21:58 +0200)
src/basic/chattr-util.c
src/basic/chattr-util.h

index 8e15b56ea39f98f56bad9b98ac1033365a92e57c..9a4e97327e0962a59d2df2ac735e21cfa232563a 100644 (file)
@@ -41,7 +41,7 @@ int chattr_full(
          * drivers, where the ioctl might have different effects. Notably, DRM is using the same
          * ioctl() number. */
 
-        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
+        if (!inode_type_can_chattr(st.st_mode))
                 return -ENOTTY;
 
         if (mask == 0 && !ret_previous && !ret_final)
@@ -140,7 +140,7 @@ int read_attr_fd(int fd, unsigned *ret) {
         if (fstat(fd, &st) < 0)
                 return -errno;
 
-        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
+        if (!inode_type_can_chattr(st.st_mode))
                 return -ENOTTY;
 
         _cleanup_close_ int fd_close = -EBADF;
@@ -248,3 +248,7 @@ int set_proj_id_recursive(int fd, uint32_t proj_id) {
                         set_proj_id_cb,
                         UINT32_TO_PTR(proj_id));
 }
+
+bool inode_type_can_chattr(mode_t mode) {
+        return IN_SET(mode & S_IFMT, S_IFREG, S_IFDIR);
+}
index 50f97971f9cf8ac890cb2bc1c27f34bf6f355f12..543843db2c2a4e3f3b9c689f2ba86882ca221bd5 100644 (file)
@@ -63,3 +63,5 @@ int set_proj_id_recursive(int fd, uint32_t proj_id);
 static inline int chattr_secret(int fd, ChattrApplyFlags flags) {
         return chattr_full(fd, NULL, CHATTR_SECRET_FLAGS, CHATTR_SECRET_FLAGS, NULL, NULL, flags|CHATTR_FALLBACK_BITWISE);
 }
+
+bool inode_type_can_chattr(mode_t mode);