From: Mike Yuan Date: Sat, 29 Jul 2023 12:00:55 +0000 (+0800) Subject: fstab-util: add fstab_has_node X-Git-Tag: v255-rc1~893^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24c0078a846c0e8dd7cc65f0a4a90ba05864434b;p=thirdparty%2Fsystemd.git fstab-util: add fstab_has_node --- diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 4ffec25c754..67e718b6eaa 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -63,7 +63,7 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) { return false; } -static int fstab_is_mount_point_of(const char *what_fstab, const char *path) { +static int fstab_is_same_node(const char *what_fstab, const char *path) { _cleanup_free_ char *node = NULL; assert(what_fstab); @@ -86,7 +86,7 @@ int fstab_is_mount_point_full(const char *where, const char *path) { _cleanup_endmntent_ FILE *f = NULL; int r; - assert(where); + assert(where || path); f = setmntent(fstab_path(), "re"); if (!f) @@ -100,14 +100,15 @@ int fstab_is_mount_point_full(const char *where, const char *path) { if (!me) return errno != 0 ? -errno : false; - if (path_equal(where, me->mnt_dir)) { - if (!path) - return true; + if (where && !path_equal(where, me->mnt_dir)) + continue; - r = fstab_is_mount_point_of(me->mnt_fsname, path); - if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))) - return r; - } + if (!path) + return true; + + r = fstab_is_same_node(me->mnt_fsname, path); + if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))) + return r; } return false; diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index cb3686bee3f..a1c079fd417 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -13,6 +13,9 @@ int fstab_is_mount_point_full(const char *where, const char *path); static inline int fstab_is_mount_point(const char *where) { return fstab_is_mount_point_full(where, NULL); } +static inline int fstab_has_node(const char *path) { + return fstab_is_mount_point_full(NULL, path); +} int fstab_filter_options( const char *opts,