-#ifdef HAVE_LIBBLKID
-#include <blkid/blkid.h>
-extern blkid_cache blkid;
-#endif
-
-extern void mount_blkid_get_cache(void);
-extern void mount_blkid_put_cache(void);
-extern const char *mount_get_devname_by_uuid(const char *uuid);
-extern const char *mount_get_devname_by_label(const char *label);
-extern const char *mount_get_volume_label_by_spec(const char *spec);
-extern const char *mount_get_devname(const char *spec);
-extern const char *mount_get_devname_for_mounting(const char *spec);
-extern int fsprobe_known_fstype(const char *fstype);
+#ifndef MOUNT_FSPROBE_H
+#define MOUNT_FSPROBE_H
+/*
+ * This is the generic interface for filesystem guessing libraries.
+ * Implementations are provided by
+ *
+ * fsprobe_blkid.c for libblkid from e2fsprogs
+ * fsprobe_volumeid.c for libvolume_id from udev
+ *
+ * Copyright (C) 2007 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2007 Matthias Koenig <mkoenig@suse.de>
+ * Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+ */
+
+extern void fsprobe_init(void);
+extern void fsprobe_exit(void);
+
+extern const char *fsprobe_get_devname_by_uuid(const char *uuid);
+extern const char *fsprobe_get_devname_by_label(const char *label);
+
+extern const char *fsprobe_get_label_by_devname(const char *devname);
+extern const char *fsprobe_get_uuid_by_devname(const char *devname);
extern const char *fsprobe_get_fstype_by_devname(const char *devname);
+extern const char *fsprobe_get_devname(const char *spec);
+extern const char *fsprobe_get_devname_for_mounting(const char *spec);
+
+extern int fsprobe_known_fstype(const char *fstype);
+
struct mountargs {
const char *spec;
const char *node;
struct mountargs *args,
const char **types);
+#endif /* MOUNT_FSPROBE_H */
#include <stdio.h>
+#include <blkid/blkid.h>
#include "fsprobe.h"
-#ifdef HAVE_LIBBLKID
-
-blkid_cache blkid;
+static blkid_cache blkid;
void
-mount_blkid_get_cache(void) {
+fsprobe_init(void) {
blkid_get_cache(&blkid, NULL);
}
void
-mount_blkid_put_cache(void) {
+fsprobe_exit(void) {
blkid_put_cache(blkid);
}
const char *
-mount_get_volume_label_by_spec(const char *spec) {
- return blkid_get_tag_value(blkid, "LABEL", spec);
+fsprobe_get_label_by_devname(const char *devname) {
+ return blkid_get_tag_value(blkid, "LABEL", devname);
+}
+
+const char *
+fsprobe_get_uuid_by_devname(const char *devname) {
+ return blkid_get_tag_value(blkid, "UUID", devname);
}
const char *
-mount_get_devname(const char *spec) {
+fsprobe_get_devname(const char *spec) {
return blkid_get_devname(blkid, spec, 0);
}
const char *
-mount_get_devname_by_uuid(const char *uuid) {
+fsprobe_get_devname_by_uuid(const char *uuid) {
return blkid_get_devname(blkid, "UUID", uuid);
}
const char *
-mount_get_devname_by_label(const char *label) {
+fsprobe_get_devname_by_label(const char *label) {
return blkid_get_devname(blkid, "LABEL", label);
}
/* Also when no UUID= or LABEL= occur? No verbose? No warnings? */
const char *
-mount_get_devname_for_mounting(const char *spec) {
+fsprobe_get_devname_for_mounting(const char *spec) {
return blkid_get_devname(blkid, spec, 0);
}
return blkid_get_tag_value(blkid, "TYPE", devname);
}
-#endif
const char *devlabel;
int ret;
- devlabel = mount_get_volume_label_by_spec(device);
+ devlabel = fsprobe_get_label_by_devname(device);
ret = !strcmp(label, devlabel);
/* free(devlabel); */
return ret;
const char *devuuid;
int ret;
- devuuid = mount_get_devname_by_uuid(device);
+ devuuid = fsprobe_get_uuid_by_devname(device);
ret = !strcmp(uuid, devuuid);
/* free(devuuid); */
return ret;
int mount_quiet;
char *progname;
-const char *mount_get_volume_label_by_spec(const char *spec) { return NULL; }
-const char *mount_get_devname_by_uuid(const char *uuid) { return NULL; }
+const char *fsprobe_get_label_by_devname(const char *spec) { return NULL; }
+const char *fsprobe_get_uuid_by_devname(const char *spec) { return NULL; }
struct my_mntent *my_getmntent (mntFILE *mfp) { return NULL; }
mntFILE *my_setmntent (const char *file, char *mode) { return NULL; }
void my_endmntent (mntFILE *mfp) { }
return 0;
}
+static void
+my_free(const void *s) {
+ if (s)
+ free((void *) s);
+}
/* Report on a single mount. */
static void
if (me->mnt_opts != NULL)
printf (" (%s)", me->mnt_opts);
if (list_with_volumelabel) {
- const char *label;
- label = mount_get_volume_label_by_spec(me->mnt_fsname);
- if (label) {
- printf (" [%s]", label);
- /* free(label); */
+ const char *devname = fsprobe_get_devname(me->mnt_fsname);
+
+ if (devname) {
+ const char *label;
+
+ label = fsprobe_get_label_by_devname(devname);
+ my_free(devname);
+
+ if (label) {
+ printf (" [%s]", label);
+ my_free(label);
+ }
}
}
printf ("\n");
exit (0);
}
-static void
-my_free(const void *s) {
- if (s)
- free((void *) s);
-}
-
/* reallocates its first arg */
static char *
append_opt(char *s, const char *opt, const char *val)
opts = append_opt(opts, cmdlineopts, NULL);
/* Handle possible LABEL= and UUID= forms of spec */
- nspec = mount_get_devname_for_mounting(spec);
+ nspec = fsprobe_get_devname_for_mounting(spec);
if (nspec)
spec = nspec;
int ret = 0;
/* Handle possible UUID= and LABEL= in spec */
- spec0 = mount_get_devname(spec0);
+ spec0 = fsprobe_get_devname(spec0);
if (!spec0)
return ret;
if (fd > 2)
close(fd);
- mount_blkid_get_cache();
+ fsprobe_init();
#ifdef DO_PS_FIDDLING
initproctitle(argc, argv);
if (specseen) {
if (uuid)
- spec = mount_get_devname_by_uuid(uuid);
+ spec = fsprobe_get_devname_by_uuid(uuid);
else
- spec = mount_get_devname_by_label(volumelabel);
+ spec = fsprobe_get_devname_by_label(volumelabel);
if (!spec)
die (EX_USAGE, _("mount: no such partition found"));
if (result == EX_SOMEOK)
result = 0;
- mount_blkid_put_cache();
+ fsprobe_exit();
exit (result);
}
if (verbose)
printf(_("%s on %s\n"), progname, orig_special);
- special = mount_get_devname(orig_special);
+ special = fsprobe_get_devname(orig_special);
if (!special) {
fprintf(stderr, _("%s: cannot find the device for %s\n"),
progname, orig_special);
static int
swapon_by_label(const char *label, int prio) {
- const char *special = mount_get_devname_by_label(label);
+ const char *special = fsprobe_get_devname_by_label(label);
return special ? do_swapon(special, prio) : cannot_find(label);
}
static int
swapon_by_uuid(const char *uuid, int prio) {
- const char *special = mount_get_devname_by_uuid(uuid);
+ const char *special = fsprobe_get_devname_by_uuid(uuid);
return special ? do_swapon(special, prio) : cannot_find(uuid);
}
if (verbose)
printf(_("%s on %s\n"), progname, orig_special);
- special = mount_get_devname(orig_special);
+ special = fsprobe_get_devname(orig_special);
if (!special)
return cannot_find(orig_special);
static int
swapoff_by_label(const char *label, int quiet) {
- const char *special = mount_get_devname_by_label(label);
+ const char *special = fsprobe_get_devname_by_label(label);
return special ? do_swapoff(special, quiet) : cannot_find(label);
}
static int
swapoff_by_uuid(const char *uuid, int quiet) {
- const char *special = mount_get_devname_by_uuid(uuid);
+ const char *special = fsprobe_get_devname_by_uuid(uuid);
return special ? do_swapoff(special, quiet) : cannot_find(uuid);
}
if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
continue;
- special = mount_get_devname(orig_special);
+ special = fsprobe_get_devname(orig_special);
if (!special)
continue;