From: Alejandro Colomar Date: Wed, 22 Apr 2026 09:14:20 +0000 (+0200) Subject: lib/, src/: Move statfs(2) call out of is_btrfs() X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7a4faaaf46314547cc5e6c8264c3a11753ef9352;p=thirdparty%2Fshadow.git lib/, src/: Move statfs(2) call out of is_btrfs() This simplifies the return value of is_btrfs() into a boolean. Signed-off-by: Alejandro Colomar --- diff --git a/lib/btrfs.c b/lib/btrfs.c index fe20cf306..065c79387 100644 --- a/lib/btrfs.c +++ b/lib/btrfs.c @@ -60,12 +60,13 @@ int btrfs_remove_subvolume(const char *path) */ int btrfs_is_subvolume(const char *path) { - struct stat st; - int ret; + struct stat st; + struct statfs sfs; - ret = is_btrfs(path); - if (ret <= 0) - return ret; + if (statfs(path, &sfs) == -1) + return -1; + if (!is_btrfs(&sfs)) + return 0; if (stat(path, &st) == -1) return -1; @@ -78,16 +79,8 @@ int btrfs_is_subvolume(const char *path) } -/* Adapted from btrfsprogs */ -int is_btrfs(const char *path) +bool +is_btrfs(const struct statfs *sfs) { - struct statfs sfs; - int ret; - - ret = statfs(path, &sfs); - if (ret == -1) - return -1; - - return sfs.f_type == BTRFS_SUPER_MAGIC; + return sfs->f_type == BTRFS_SUPER_MAGIC; } - diff --git a/lib/prototypes.h b/lib/prototypes.h index 9a03e3125..42aa29230 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ extern int isexpired (const struct passwd *, /*@null@*/const struct spwd *); extern int btrfs_create_subvolume(const char *path); extern int btrfs_remove_subvolume(const char *path); extern int btrfs_is_subvolume(const char *path); -extern int is_btrfs(const char *path); +extern bool is_btrfs(const struct statfs *sfs); #endif /* basename() renamed to Basename() to avoid libc name space confusion */ diff --git a/src/useradd.c b/src/useradd.c index df679d287..5ce6cd6a2 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -2265,6 +2266,7 @@ static void create_home(const struct option_flags *flags) #if WITH_BTRFS if (subvolflg && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) { char *btrfs_check = strdup(path); + struct statfs sfs; if (!btrfs_check) { fprintf(stderr, @@ -2273,13 +2275,18 @@ static void create_home(const struct option_flags *flags) fail_exit(E_HOMEDIR, process_selinux); } stpcpy(&btrfs_check[strlen(path) - strlen(cp) - 1], ""); - if (is_btrfs(btrfs_check) <= 0) { + if (statfs(btrfs_check, &sfs) == -1) { + fprintf(stderr, "%s: statfs(\"%s\"): %s\n", + Prog, btrfs_check, strerrno()); + fail_exit(E_HOMEDIR, process_selinux); + } + free(btrfs_check); + if (!is_btrfs(&sfs)) { fprintf(stderr, _("%s: home directory \"%s\" must be mounted on BTRFS\n"), Prog, path); fail_exit(E_HOMEDIR, process_selinux); } - free(btrfs_check); // make subvolume to mount for user instead of directory if (btrfs_create_subvolume(path)) { fprintf(stderr,