From: Karel Zak Date: Thu, 10 May 2007 09:21:35 +0000 (+0200) Subject: mount: fsprobe: rename the rest of API routines to fsprobe_* X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=950f648f8a773359bbec7f30820c9b3159e66e1c;p=util-linux mount: fsprobe: rename the rest of API routines to fsprobe_* Signed-off-by: Karel Zak --- diff --git a/mount/fsprobe.h b/mount/fsprobe.h index cc429e15..e59440e0 100644 --- a/mount/fsprobe.h +++ b/mount/fsprobe.h @@ -1,18 +1,32 @@ -#ifdef HAVE_LIBBLKID -#include -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 + * Copyright (C) 2007 Matthias Koenig + * Copyright (C) 2007 Karel Zak + */ + +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 7f8c3624..d25b9731 100644 --- a/mount/fsprobe_blkid.c +++ b/mount/fsprobe_blkid.c @@ -1,43 +1,47 @@ #include +#include #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 5267f620..c47f20d2 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 a443c358..02aeb967 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -232,6 +232,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 @@ -244,11 +249,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"); @@ -267,12 +279,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) @@ -1329,7 +1335,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; @@ -1386,7 +1392,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; @@ -1668,7 +1674,7 @@ main(int argc, char *argv[]) { if (fd > 2) close(fd); - mount_blkid_get_cache(); + fsprobe_init(); #ifdef DO_PS_FIDDLING initproctitle(argc, argv); @@ -1841,9 +1847,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")); @@ -1921,7 +1927,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 64fe3503..8c3c1bdf 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -179,7 +179,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); @@ -254,13 +254,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); } @@ -271,7 +271,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); @@ -292,13 +292,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); } @@ -327,7 +327,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;