From: Franck Bui Date: Mon, 26 Jun 2017 13:22:10 +0000 (+0200) Subject: fstab-util: introduce fstab_has_fstype() helper X-Git-Tag: v234~79^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c1921e9f39ce450bbd066341afc6a677ef122cb;p=thirdparty%2Fsystemd.git fstab-util: introduce fstab_has_fstype() helper --- diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 5675b0beac6..ec2e868ca8e 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -34,6 +34,26 @@ #include "strv.h" #include "util.h" +int fstab_has_fstype(const char *fstype) { + _cleanup_endmntent_ FILE *f = NULL; + struct mntent *m; + + f = setmntent("/etc/fstab", "re"); + if (!f) + return errno == ENOENT ? false : -errno; + + for (;;) { + errno = 0; + m = getmntent(f); + if (!m) + return errno != 0 ? -errno : false; + + if (streq(m->mnt_type, fstype)) + return true; + } + return false; +} + int fstab_is_mount_point(const char *mount) { _cleanup_endmntent_ FILE *f = NULL; struct mntent *m; diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index bae8c0a894a..bbf04413513 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -25,6 +25,7 @@ #include "macro.h" int fstab_is_mount_point(const char *mount); +int fstab_has_fstype(const char *fstype); int fstab_filter_options(const char *opts, const char *names, const char **namefound, char **value, char **filtered);