Signed-off-by: Karel Zak <kzak@xxxxxxxxxx> --- mount/fsprobe.h | 41 ++++++++++++++++++++++++++++------------- mount/fsprobe_blkid.c | 27 +++++++++++++++------------ mount/fstab.c | 8 ++++---- mount/mount.c | 40 +++++++++++++++++++++++----------------- mount/swapon.c | 14 +++++++------- 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/mount/fsprobe.h b/mount/fsprobe.h index cc429e1..e59440e 100644 --- a/mount/fsprobe.h +++ b/mount/fsprobe.h @@ -1,18 +1,32 @@ -#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@xxxxxxxx> + * Copyright (C) 2007 Matthias Koenig <mkoenig@xxxxxxx> + * Copyright (C) 2007 Karel Zak <kzak@xxxxxxxxxx> + */ + +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; @@ -27,3 +41,4 @@ extern int fsprobe_procfsloop_mount(int (*mount_fn)(struct mountargs *), struct mountargs *args, const char **types); +#endif /* MOUNT_FSPROBE_H */ diff --git a/mount/fsprobe_blkid.c b/mount/fsprobe_blkid.c index 7f8c362..d25b973 100644 --- a/mount/fsprobe_blkid.c +++ b/mount/fsprobe_blkid.c @@ -1,43 +1,47 @@ #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); } @@ -52,4 +56,3 @@ fsprobe_get_fstype_by_devname(const char *devname) { return blkid_get_tag_value(blkid, "TYPE", devname); } -#endif diff --git a/mount/fstab.c b/mount/fstab.c index 5267f62..c47f20d 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -292,7 +292,7 @@ has_label(const char *device, const char *label) { 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; @@ -303,7 +303,7 @@ has_uuid(const char *device, const char *uuid){ 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; @@ -745,8 +745,8 @@ int verbose; 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) { } diff --git a/mount/mount.c b/mount/mount.c index be9e409..12964ca 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -233,6 +233,11 @@ parse_string_opt(char *s) { return 0; } +static void +my_free(const void *s) { + if (s) + free((void *) s); +} /* Report on a single mount. */ static void @@ -245,11 +250,18 @@ print_one (const struct my_mntent *me) { 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"); @@ -268,12 +280,6 @@ print_all (char *types) { 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) @@ -1330,7 +1336,7 @@ mount_one (const char *spec, const char *node, const char *types, 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; @@ -1387,7 +1393,7 @@ mounted (const char *spec0, const char *node0) { int ret = 0; /* Handle possible UUID= and LABEL= in spec */ - spec0 = mount_get_devname(spec0); + spec0 = fsprobe_get_devname(spec0); if (!spec0) return ret; @@ -1669,7 +1675,7 @@ main(int argc, char *argv[]) { if (fd > 2) close(fd); - mount_blkid_get_cache(); + fsprobe_init(); #ifdef DO_PS_FIDDLING initproctitle(argc, argv); @@ -1842,9 +1848,9 @@ main(int argc, char *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")); @@ -1922,7 +1928,7 @@ main(int argc, char *argv[]) { if (result == EX_SOMEOK) result = 0; - mount_blkid_put_cache(); + fsprobe_exit(); exit (result); } diff --git a/mount/swapon.c b/mount/swapon.c index cb055b3..025a6b5 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -180,7 +180,7 @@ do_swapon(const char *orig_special, int prio) { 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); @@ -255,13 +255,13 @@ cannot_find(const char *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); } @@ -272,7 +272,7 @@ do_swapoff(const char *orig_special, int quiet) { 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); @@ -293,13 +293,13 @@ do_swapoff(const char *orig_special, int quiet) { 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); } @@ -328,7 +328,7 @@ swapon_all(void) { if (!streq(fstab->mnt_type, MNTTYPE_SWAP)) continue; - special = mount_get_devname(orig_special); + special = fsprobe_get_devname(orig_special); if (!special) continue; -- 1.5.0.6 - To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html