From: Mike Yuan Date: Wed, 26 Jul 2023 04:04:07 +0000 (+0800) Subject: fstab-util: add fstab_is_mount_point_full which takes a source path to compare X-Git-Tag: v254~17^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99299d0d5a722812cedc0a23e4987f90a257c2d2;p=thirdparty%2Fsystemd.git fstab-util: add fstab_is_mount_point_full which takes a source path to compare --- diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 6efdcd68965..4ffec25c754 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -63,23 +63,53 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) { return false; } -int fstab_is_mount_point(const char *mount) { +static int fstab_is_mount_point_of(const char *what_fstab, const char *path) { + _cleanup_free_ char *node = NULL; + + assert(what_fstab); + assert(path); + + node = fstab_node_to_udev_node(what_fstab); + if (!node) + return -ENOMEM; + + if (path_equal(node, path)) + return true; + + if (is_device_node(path) && is_device_node(node)) + return devnode_same(node, path); + + return false; +} + +int fstab_is_mount_point_full(const char *where, const char *path) { _cleanup_endmntent_ FILE *f = NULL; - struct mntent *m; + int r; + + assert(where); f = setmntent(fstab_path(), "re"); if (!f) return errno == ENOENT ? false : -errno; for (;;) { + struct mntent *me; + errno = 0; - m = getmntent(f); - if (!m) + me = getmntent(f); + if (!me) return errno != 0 ? -errno : false; - if (path_equal(m->mnt_dir, mount)) - return true; + if (path_equal(where, me->mnt_dir)) { + if (!path) + return true; + + r = fstab_is_mount_point_of(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 5979b476b67..cb3686bee3f 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -7,9 +7,13 @@ #include "macro.h" bool fstab_is_extrinsic(const char *mount, const char *opts); -int fstab_is_mount_point(const char *mount); int fstab_has_fstype(const char *fstype); +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); +} + int fstab_filter_options( const char *opts, const char *names,