summaryrefslogtreecommitdiffstats
path: root/lib/match.c
diff options
context:
space:
mode:
authorKarel Zak2011-11-15 15:17:19 +0100
committerKarel Zak2011-11-15 15:17:19 +0100
commit12089155210f8d84054cc8413d79cd2800d26929 (patch)
tree77189501ba877049f4e6051b9fd008a57c6fc434 /lib/match.c
parentlibblkid: export PTMAGIC also if only PTTYPE requested (diff)
downloadkernel-qcow2-util-linux-12089155210f8d84054cc8413d79cd2800d26929.tar.gz
kernel-qcow2-util-linux-12089155210f8d84054cc8413d79cd2800d26929.tar.xz
kernel-qcow2-util-linux-12089155210f8d84054cc8413d79cd2800d26929.zip
lib,match: split match_fstype() from libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/match.c')
-rw-r--r--lib/match.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/match.c b/lib/match.c
new file mode 100644
index 000000000..c5c48a0f6
--- /dev/null
+++ b/lib/match.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+
+#include <string.h>
+
+/*
+ * match_fstype:
+ * @type: filesystem type
+ * @pattern: filesystem name or comma delimited list of names
+ *
+ * The @pattern list of filesystem can be prefixed with a global
+ * "no" prefix to invert matching of the whole list. The "no" could
+ * also be used for individual items in the @pattern list. So,
+ * "nofoo,bar" has the same meaning as "nofoo,nobar".
+ */
+int match_fstype(const char *type, const char *pattern)
+{
+ int no = 0; /* negated types list */
+ int len;
+ const char *p;
+
+ if (!pattern && !type)
+ return 1;
+ if (!pattern)
+ return 0;
+
+ if (!strncmp(pattern, "no", 2)) {
+ no = 1;
+ pattern += 2;
+ }
+
+ /* Does type occur in types, separated by commas? */
+ len = strlen(type);
+ p = pattern;
+ while(1) {
+ if (!strncmp(p, "no", 2) && !strncmp(p+2, type, len) &&
+ (p[len+2] == 0 || p[len+2] == ','))
+ return 0;
+ if (strncmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ','))
+ return !no;
+ p = strchr(p,',');
+ if (!p)
+ break;
+ p++;
+ }
+ return no;
+}