diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-09-02 10:55:24 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2013-09-09 09:52:32 +0200 |
commit | 96f54b8bc892bc6feee6b9a3878b23e8dcbb2004 (patch) | |
tree | 7c2e2a41edf3255ce0c0b474052a7316b8f42654 /utils/mount.c | |
parent | c3a70032aa37e72adea05f03f5f8555e0991b560 (diff) |
mount: handle -t auto
Use libblkid to detect the filesystem type if "auto" is given as
type. Remove the translator localization from main, this is also done
in do_mount and any errors are propagated properly. This way "auto" is
handled correctly if given on the command line or used as filesystem
type in the fstab.
* configure.ac: Add check for libblkid.
* config.make.in: Make libblkid specific values available.
* utils/Makefile: Use libblkid specific values.
* utils/mount.c (DEFAULT_FSTYPE): Use "auto" as default type.
(do_mount): Detect type using libblkid.
(main): Drop translator localization.
Diffstat (limited to 'utils/mount.c')
-rw-r--r-- | utils/mount.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/utils/mount.c b/utils/mount.c index 77b2138e..04519da2 100644 --- a/utils/mount.c +++ b/utils/mount.c @@ -28,11 +28,14 @@ #include <hurd/fsys.h> #include <hurd/fshelp.h> #include <hurd/paths.h> +#ifdef HAVE_BLKID +#include <blkid/blkid.h> +#endif #include "match-options.h" #define SEARCH_FMTS _HURD "%sfs\0" _HURD "%s" -#define DEFAULT_FSTYPE "ext2" +#define DEFAULT_FSTYPE "auto" static char *fstype = DEFAULT_FSTYPE; static char *device, *mountpoint; @@ -338,6 +341,29 @@ do_mount (struct fs *fs, int remount) return EBUSY; } + if (strcmp (fs->mntent.mnt_type, "auto") == 0) + { +#if HAVE_BLKID + char *type = + blkid_get_tag_value (NULL, "TYPE", fs->mntent.mnt_fsname); + if (! type) + { + error (0, 0, "failed to detect file system type"); + return EFTYPE; + } + else + { + fs->mntent.mnt_type = strdup (type); + if (! fs->mntent.mnt_type) + error (3, ENOMEM, "failed to allocate memory"); + } +#else + fs->mntent.mnt_type = strdup ("ext2"); + if (! fs->mntent.mnt_type) + error (3, ENOMEM, "failed to allocate memory"); +#endif + } + err = fs_type (fs, &type); if (err) { @@ -579,13 +605,6 @@ main (int argc, char **argv) mnt_opts: 0, mnt_freq: 0, mnt_passno: 0 }; - struct fstype *fst; - - err = fstypes_get (fstab->types, fstype, &fst); - if (err) - error (106, err, "cannot initialize type %s", fstype); - if (fst->program == 0) - error (2, 0, "filesystem type %s not recognized", fstype); err = fstab_add_mntent (fstab, &m, &fs); if (err) |