]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-util: introduce fstab_has_fstype() helper
authorFranck Bui <fbui@suse.com>
Mon, 26 Jun 2017 13:22:10 +0000 (15:22 +0200)
committerFranck Bui <fbui@suse.com>
Tue, 27 Jun 2017 08:04:46 +0000 (10:04 +0200)
src/shared/fstab-util.c
src/shared/fstab-util.h

index 5675b0beac67579c0d456f513fbdb238715ea8c9..ec2e868ca8ebae2cde906252a5e9ba42e1c6283b 100644 (file)
 #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;
index bae8c0a894ac057015bd2f16cec64659e0da01e4..bbf04413513baacc7c27d61a4abf0c89170fbe58 100644 (file)
@@ -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);