From: Karel Zak Date: Wed, 9 May 2007 23:47:28 +0000 (+0200) Subject: mount: fsprobe: remove mount_guess_fstype.{c,h} X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9053b8a10dbce2ec441df906c5cc4dbb4e048e46;p=util-linux mount: fsprobe: remove mount_guess_fstype.{c,h} Signed-off-by: Kay Sievers Signed-off-by: Karel Zak --- diff --git a/mount/Makefile.am b/mount/Makefile.am index 07ba0a83..ae67ed63 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -7,15 +7,13 @@ sbin_PROGRAMS = losetup swapon man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8 MNTHDRS = fstab.h linux_fs.h mount_mntent.h mount_constants.h my_dev_t.h \ - mount_paths.h lomount.h fsprobe.h \ - mount_guess_fstype.h realpath.h xmalloc.h \ + mount_paths.h lomount.h fsprobe.h realpath.h xmalloc.h \ getusername.h loop.h sundries.h mount_common = fstab.c sundries.c xmalloc.c realpath.c mount_mntent.c \ - getusername.c lomount.c $(MNTHDRS) ../lib/env.c + fsprobe.c getusername.c lomount.c $(MNTHDRS) ../lib/env.c -mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c \ - mount_guess_fstype.c +mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c mount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS) mount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS) diff --git a/mount/mount_guess_fstype.c b/mount/fsprobe.c similarity index 60% rename from mount/mount_guess_fstype.c rename to mount/fsprobe.c index 01c3fc72..4b578026 100644 --- a/mount/mount_guess_fstype.c +++ b/mount/fsprobe.c @@ -1,35 +1,3 @@ -/* - * Thu Jul 14 07:32:40 1994: faith@cs.unc.edu added changes from Adam - * J. Richter (adam@adam.yggdrasil.com) so that /proc/filesystems is used - * if no -t option is given. I modified his patches so that, if - * /proc/filesystems is not available, the behavior of mount is the same as - * it was previously. - * - * Wed Feb 8 09:23:18 1995: Mike Grupenhoff added - * a probe of the superblock for the type before /proc/filesystems is - * checked. - * - * Fri Apr 5 01:13:33 1996: quinlan@bucknell.edu, fixed up iso9660 autodetect - * - * Wed Nov 11 11:33:55 1998: K.Garloff@ping.de, try /etc/filesystems before - * /proc/filesystems - * [This was mainly in order to specify vfat before fat; these days we often - * detect *fat and then assume vfat, so perhaps /etc/filesystems isnt - * so useful anymore.] - * - * 1999-02-22 Arkadiusz Mi¶kiewicz - * added Native Language Support - * - * 2000-12-01 Sepp Wijnands - * added probes for cramfs, hfs, hpfs and adfs. - * - * 2001-10-26 Tim Launchbury - * added sysv magic. - * - * aeb - many changes. - * - */ - #include #include #include @@ -37,28 +5,13 @@ #include #include #include +#include "mount_paths.h" #include "linux_fs.h" #include "fsprobe.h" -#include "mount_guess_fstype.h" #include "sundries.h" /* for xstrdup */ #include "nls.h" -#define ETC_FILESYSTEMS "/etc/filesystems" -#define PROC_FILESYSTEMS "/proc/filesystems" - -char * -do_guess_fstype(const char *device) -{ - return blkid_get_tag_value(blkid, "TYPE", device); -} - -static int -known_fstype(const char *fstype) -{ - return blkid_known_fstype(fstype); -} - - +/* list of already tested filesystems by fsprobe_procfsloop_mount() */ static struct tried { struct tried *next; char *type; @@ -68,7 +21,7 @@ static int was_tested(const char *fstype) { struct tried *t; - if (known_fstype(fstype)) + if (fsprobe_known_fstype(fstype)) return 1; for (t = tried; t; t = t->next) { if (!strcmp(t->type, fstype)) @@ -100,23 +53,6 @@ free_tested(void) { tried = NULL; } -char * -guess_fstype(const char *spec) { - char *type = do_guess_fstype(spec); - if (verbose) { - printf (_("mount: you didn't specify a filesystem type for %s\n"), - spec); - if (!type) - printf (_(" I will try all types mentioned in %s or %s\n"), - ETC_FILESYSTEMS, PROC_FILESYSTEMS); - else if (!strcmp(type, "swap")) - printf (_(" and it looks like this is swapspace\n")); - else - printf (_(" I will try type %s\n"), type); - } - return type; -} - static char * procfsnext(FILE *procfs) { char line[100]; @@ -134,7 +70,8 @@ procfsnext(FILE *procfs) { the kernel knows about, so /etc/filesystems is irrelevant. Return: 1: yes, 0: no, -1: cannot open procfs */ int -is_in_procfs(const char *type) { +fsprobe_known_fstype_in_procfs(const char *type) +{ FILE *procfs; char *fsname; int ret = -1; @@ -159,8 +96,10 @@ is_in_procfs(const char *type) { /* when 0 or -1 is returned, *types contains the type used */ /* when 1 is returned, *types is NULL */ int -procfsloop(int (*mount_fn)(struct mountargs *), struct mountargs *args, - const char **types) { +fsprobe_procfsloop_mount( int (*mount_fn)(struct mountargs *), + struct mountargs *args, + const char **types) +{ char *files[2] = { ETC_FILESYSTEMS, PROC_FILESYSTEMS }; FILE *procfs; char *fsname; @@ -208,7 +147,7 @@ procfsloop(int (*mount_fn)(struct mountargs *), struct mountargs *args, ret = 0; break; } else if (errno != EINVAL && - is_in_procfs(fsname) == 1) { + fsprobe_known_fstype_in_procfs(fsname) == 1) { *types = "guess"; ret = -1; errsv = errno; diff --git a/mount/fsprobe.h b/mount/fsprobe.h index c96ff8cb..cc429e15 100644 --- a/mount/fsprobe.h +++ b/mount/fsprobe.h @@ -10,3 +10,20 @@ 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); +extern const char *fsprobe_get_fstype_by_devname(const char *devname); + +struct mountargs { + const char *spec; + const char *node; + const char *type; + int flags; + void *data; +}; + +extern int fsprobe_known_fstype_in_procfs(const char *type); + +extern int fsprobe_procfsloop_mount(int (*mount_fn)(struct mountargs *), + struct mountargs *args, + const char **types); + diff --git a/mount/fsprobe_blkid.c b/mount/fsprobe_blkid.c index 9ff4e31c..7f8c3624 100644 --- a/mount/fsprobe_blkid.c +++ b/mount/fsprobe_blkid.c @@ -41,4 +41,15 @@ mount_get_devname_for_mounting(const char *spec) { return blkid_get_devname(blkid, spec, 0); } +int +fsprobe_known_fstype(const char *fstype) +{ + return blkid_known_fstype(fstype); +} + +const char * +fsprobe_get_fstype_by_devname(const char *devname) { + return blkid_get_tag_value(blkid, "TYPE", devname); +} + #endif diff --git a/mount/mount.c b/mount/mount.c index 5ab9062f..a443c358 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -38,7 +38,6 @@ #include "lomount.h" #include "loop.h" #include "linux_fs.h" /* for BLKGETSIZE */ -#include "mount_guess_fstype.h" #include "getusername.h" #include "mount_paths.h" #include "env.h" @@ -655,6 +654,26 @@ check_special_mountprog(const char *spec, const char *node, const char *type, in return 0; } + +static const char * +guess_fstype_by_devname(const char *devname) +{ + const char *type = fsprobe_get_fstype_by_devname(devname); + + if (verbose) { + printf (_("mount: you didn't specify a filesystem type for %s\n"), devname); + + if (!type) + printf (_(" I will try all types mentioned in %s or %s\n"), + ETC_FILESYSTEMS, PROC_FILESYSTEMS); + else if (!strcmp(type, "swap")) + printf (_(" and it looks like this is swapspace\n")); + else + printf (_(" I will try type %s\n"), type); + } + return type; +} + /* * guess_fstype_and_mount() * Mount a single file system. Guess the type when unknown. @@ -674,7 +693,7 @@ guess_fstype_and_mount(const char *spec, const char *node, const char **types, *types = "none"; /* random, but not "bind" */ if (!*types && !(flags & MS_REMOUNT)) { - *types = guess_fstype(spec); + *types = guess_fstype_by_devname(spec); if (*types) { if (!strcmp(*types, "swap")) { error(_("%s looks like swapspace - not mounted"), spec); @@ -710,7 +729,7 @@ guess_fstype_and_mount(const char *spec, const char *node, const char **types, return do_mount_syscall (&args); } - return procfsloop(do_mount_syscall, &args, types); + return fsprobe_procfsloop_mount(do_mount_syscall, &args, types); } /* @@ -1146,8 +1165,10 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, case EIO: error (_("mount: %s: can't read superblock"), spec); break; case ENODEV: - { int pfs; - if ((pfs = is_in_procfs(types)) == 1 || !strcmp(types, "guess")) + { + int pfs = fsprobe_known_fstype_in_procfs(types); + + if (pfs == 1 || !strcmp(types, "guess")) error(_("mount: %s: unknown device"), spec); else if (pfs == 0) { char *lowtype, *p; @@ -1164,11 +1185,13 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, u++; } } - if (u && is_in_procfs(lowtype) == 1) + if (u && fsprobe_known_fstype_in_procfs(lowtype) == 1) error (_("mount: probably you meant %s"), lowtype); - else if (!strncmp(lowtype, "iso", 3) && is_in_procfs("iso9660") == 1) + else if (!strncmp(lowtype, "iso", 3) && + fsprobe_known_fstype_in_procfs("iso9660") == 1) error (_("mount: maybe you meant 'iso9660'?")); - else if (!strncmp(lowtype, "fat", 3) && is_in_procfs("vfat") == 1) + else if (!strncmp(lowtype, "fat", 3) && + fsprobe_known_fstype_in_procfs("vfat") == 1) error (_("mount: maybe you meant 'vfat'?")); free(lowtype); } else @@ -1740,8 +1763,8 @@ main(int argc, char *argv[]) { use only for testing purposes - the guessing is not reliable at all */ { - char *fstype; - fstype = do_guess_fstype(optarg); + const char *fstype; + fstype = fsprobe_get_fstype_by_devname(optarg); printf("%s\n", fstype ? fstype : "unknown"); exit(fstype ? 0 : EX_FAIL); } diff --git a/mount/mount_guess_fstype.h b/mount/mount_guess_fstype.h deleted file mode 100644 index 63cb678c..00000000 --- a/mount/mount_guess_fstype.h +++ /dev/null @@ -1,16 +0,0 @@ -struct mountargs { - const char *spec; - const char *node; - const char *type; - int flags; - void *data; -}; - -extern int verbose; - -char *guess_fstype(const char *device); -char *do_guess_fstype(const char *device); -int procfsloop(int (*mount_fn)(struct mountargs *), struct mountargs *args, - const char **type); -int is_in_procfs(const char *fstype); - diff --git a/mount/mount_paths.h b/mount/mount_paths.h index fe84e1d7..9093b10e 100644 --- a/mount/mount_paths.h +++ b/mount/mount_paths.h @@ -12,4 +12,7 @@ #endif #define LOCK_TIMEOUT 10 +#define ETC_FILESYSTEMS "/etc/filesystems" +#define PROC_FILESYSTEMS "/proc/filesystems" + #endif /* MOUNT_PATHS_H */