From 90fae0b46cd28bc43aa04874c16f12b230f8cd79 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Aug 2025 14:27:05 +0200 Subject: [PATCH] stat-util: add helper inode_type_can_hardlink() --- src/basic/stat-util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 347d885a19f..17e712200a2 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -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); +} -- 2.47.3