umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
swapon_SOURCES = swapon.c xmalloc.c \
- swap_constants.h realpath.c
+ swap_constants.h realpath.c fsprobe.c sundries.c
losetup_SOURCES = lomount.c loop.h lomount.h
losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
}
return 1;
}
+
+const char *
+fsprobe_get_devname_for_mounting(const char *spec)
+{
+ char *name, *value;
+
+ if (!spec)
+ return NULL;
+
+ if (parse_spec(spec, &name, &value) != 0)
+ return NULL; /* parse error */
+
+ if (name) {
+ const char *nspec = NULL;
+
+ if (!strcmp(name,"LABEL"))
+ nspec = fsprobe_get_devname_by_label(value);
+ else if (!strcmp(name,"UUID"))
+ nspec = fsprobe_get_devname_by_uuid(value);
+
+ if (nspec && verbose > 1)
+ printf(_("mount: going to mount %s by %s\n"), spec, name);
+
+ free((void *) name);
+ return nspec;
+ }
+
+ /* no LABEL, no UUID, .. probably a path */
+ if (verbose > 1)
+ printf(_("mount: no LABEL=, no UUID=, going to mount %s by path\n"), spec);
+
+ return canonicalize(spec);
+}
+
+/* like fsprobe_get_devname_for_mounting(), but without verbose messages */
+const char *
+fsprobe_get_devname(const char *spec)
+{
+ char *name, *value;
+
+ if (!spec)
+ return NULL;
+
+ if (parse_spec(spec, &name, &value) != 0)
+ return NULL; /* parse error */
+
+ if (name) {
+ const char *nspec = NULL;
+
+ if (!strcmp(name,"LABEL"))
+ nspec = fsprobe_get_devname_by_label(value);
+ else if (!strcmp(name,"UUID"))
+ nspec = fsprobe_get_devname_by_uuid(value);
+
+ free((void *) name);
+ return nspec;
+ }
+
+ return canonicalize(spec);
+}
+
return blkid_get_tag_value(blkid, "UUID", devname);
}
-const char *
-fsprobe_get_devname(const char *spec) {
- return blkid_get_devname(blkid, spec, 0);
-}
-
const char *
fsprobe_get_devname_by_uuid(const char *uuid) {
return blkid_get_devname(blkid, "UUID", uuid);
return blkid_get_devname(blkid, "LABEL", label);
}
-/* Also when no UUID= or LABEL= occur? No verbose? No warnings? */
-const char *
-fsprobe_get_devname_for_mounting(const char *spec) {
- return blkid_get_devname(blkid, spec, 0);
-}
-
int
fsprobe_known_fstype(const char *fstype)
{
return xstrdup(path);
}
+
+
+/*
+ * Parses NAME=value, returns -1 on parse error, 0 success. The success is also
+ * when the 'spec' doesn't contain name=value pair (because the spec could be
+ * a devname too). In particular case the pointer 'name' is set to NULL.
+
+ * The result is a new allocated string (the 'name' pointer).
+ */
+int
+parse_spec(const char *spec, char **name, char **value)
+{
+ char *vl, *tk, *cp;
+
+ *name = NULL;
+ *value = NULL;
+
+ if (!(cp = strchr(spec, '=')))
+ return 0; /* no name= */
+
+ tk = xstrdup(spec);
+ vl = tk + (cp - spec);
+ *vl++ = '\0';
+
+ if (*vl == '"' || *vl == '\'') {
+ if (!(cp = strrchr(vl+1, *vl))) {
+ free(tk);
+ return -1; /* parse error */
+ }
+ vl++;
+ *cp = '\0';
+ }
+
+ *name = tk;
+ *value = vl;
+ return 0;
+}
+
char *xstrconcat3 (char *, const char *, const char *);
char *xstrconcat4 (char *, const char *, const char *, const char *);
+int parse_spec(const char *spec, char **name, char **value);
+
void die (int errcode, const char *fmt, ...);
/* exit status - bits below are ORed */
int all = 0;
int verbose = 0;
int priority = -1; /* non-prioritized swap by default */
+int mount_quiet = 0;
/* If true, don't complain if the device/file doesn't exist */
int ifexists = 0;