]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add helper inode_type_can_hardlink()
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Aug 2025 12:27:05 +0000 (14:27 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 14 Oct 2025 09:21:46 +0000 (11:21 +0200)
src/basic/stat-util.h

index 347d885a19fbed29fefa6f84af9977afbbe54faf..17e712200a2afb5105f758ff40c67502c622d414 100644 (file)
@@ -110,3 +110,10 @@ static inline bool stat_is_set(const struct stat *st) {
 static inline bool statx_is_set(const struct statx *sx) {
         return sx && sx->stx_mask != 0;
 }
+
+static inline bool inode_type_can_hardlink(mode_t m) {
+        /* returns true for all inode types that support hardlinks on linux. Note this is effectively all
+         * inode types except for directories (and those weird misc fds such as eventfds() that have no inode
+         * type). */
+        return IN_SET(m & S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFCHR, S_IFIFO);
+}