Skip to content

Commit

Permalink
mount: use blkid to determine fstype
Browse files Browse the repository at this point in the history
* Add a function to volume_id that returns an fstype for a
  given device.

* During mount, if the fstype is auto, or blkid disagrees
  with the given fstype, trust blkid's determination of the
  filesystem type and run with it.

Change-Id: I357cbb5d255a30a27152a06de5328b2ef14553f9
  • Loading branch information
invisiblek authored and Flinny committed Apr 12, 2015
1 parent af50a56 commit 352389a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/volume_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

char *get_fstype_from_devname(const char *device);
char *get_devname_from_label(const char *spec);
char *get_devname_from_uuid(const char *spec);
void display_uuid_cache(int scan_devices);
Expand Down
11 changes: 8 additions & 3 deletions util-linux/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,16 +1776,21 @@ static int singlemount(struct mntent *mp, int ignore_busy)
int rc = -1;
unsigned long vfsflags;
char *loopFile = NULL, *filteropts = NULL;
char *detected_fstype = NULL;
llist_t *fl = NULL;
struct stat st;

errno = 0;

vfsflags = parse_mount_options(mp->mnt_opts, &filteropts);

// Treat fstype "auto" as unspecified
if (mp->mnt_type && strcmp(mp->mnt_type, "auto") == 0)
mp->mnt_type = NULL;
detected_fstype = get_fstype_from_devname(mp->mnt_fsname);

// If fstype is auto or disagrees with blkid, trust blkid's
// determination of the filesystem type
if ((mp->mnt_type && !strcmp(mp->mnt_type, "auto")) ||
(detected_fstype && strcmp(detected_fstype, mp->mnt_type)))
mp->mnt_type = detected_fstype;

// Might this be a virtual filesystem?
if (ENABLE_FEATURE_MOUNT_HELPERS && strchr(mp->mnt_fsname, '#')) {
Expand Down
20 changes: 20 additions & 0 deletions util-linux/volume_id/get_devname.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,26 @@ int add_to_uuid_cache(const char *device)
return 0;
}

char *get_fstype_from_devname(const char *device)
{
#if ENABLE_FEATURE_BLKID_TYPE
struct uuidCache_s *uc;
struct stat *statbuf;

if (stat(device, statbuf) < 0)
return NULL;

if (!S_ISBLK(statbuf->st_mode) && !S_ISREG(statbuf->st_mode))
return NULL;

add_to_uuid_cache(device);
uc = uuidcache_init(0);

return uc->type;
#else
return NULL;
#endif
}

/* Used by mount and findfs */

Expand Down

0 comments on commit 352389a

Please sign in to comment.