From f5a7247afbaae2b15659c15dec0ff8f395f08a33 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 5 Feb 2026 16:42:20 +0100 Subject: [PATCH] stat-util: add statx_verify_directory() helper, similar to stat_verify_directory() but for statx --- src/basic/stat-util.c | 15 +++++++++++++++ src/basic/stat-util.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 9eaf17624a9..d5df4acc287 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -90,6 +90,21 @@ int stat_verify_directory(const struct stat *st) { return 0; } +int statx_verify_directory(const struct statx *stx) { + assert(stx); + + if (!FLAGS_SET(stx->stx_mask, STATX_TYPE)) + return -ENODATA; + + if (S_ISLNK(stx->stx_mode)) + return -ELOOP; + + if (!S_ISDIR(stx->stx_mode)) + return -ENOTDIR; + + return 0; +} + int fd_verify_directory(int fd) { if (IN_SET(fd, AT_FDCWD, XAT_FDROOT)) return 0; diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 97dedd4b80b..65af98e76a7 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -11,6 +11,7 @@ int verify_regular_at(int fd, const char *path, bool follow); int fd_verify_regular(int fd); int stat_verify_directory(const struct stat *st); +int statx_verify_directory(const struct statx *stx); int fd_verify_directory(int fd); int is_dir_at(int fd, const char *path, bool follow); int is_dir(const char *path, bool follow); -- 2.47.3