From: Hadi Chokr Date: Mon, 20 Jul 2026 11:57:50 +0000 (+0000) Subject: useradd: create_home(): Extract want_btrfs_subvolume() X-Git-Tag: 4.20.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=249686e24cec40f0981ed9607f61c50d22427285;p=thirdparty%2Fshadow.git useradd: create_home(): Extract want_btrfs_subvolume() Move the condition deciding whether the home directory should be created as a Btrfs subvolume into a helper function, in preparation for extending it in a following commit. While at it, remove superfluous parentheses and an unnecessary cast. No functional change. Signed-off-by: Hadi Chokr Reviewed-by: Alejandro Colomar --- diff --git a/src/useradd.c b/src/useradd.c index fd8e36b8a..9588911c2 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2131,6 +2131,17 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count, } } +#if WITH_BTRFS +static bool +want_btrfs_subvolume(const char *path) +{ + if (!subvolflg) + return false; + + return strlen(prefix_user_home) - strlen(path) <= 1; +} +#endif + /* * create_home - create the user's home directory * @@ -2186,7 +2197,7 @@ static void create_home(const struct option_flags *flags) dir_created = false; #if WITH_BTRFS - if (subvolflg && (strlen(prefix_user_home) - (int)strlen(path)) <= 1) { + if (want_btrfs_subvolume(path)) { char *btrfs_check = strdup(path); struct statfs sfs;