From: Karel Zak Date: Wed, 7 Nov 2007 23:54:58 +0000 (+0100) Subject: mount: use blkdev_get_size() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=461311047bf28ea838ab63e5a5e5b2003af2f377;p=util-linux mount: use blkdev_get_size() Signed-off-by: Karel Zak --- diff --git a/mount/Makefile.am b/mount/Makefile.am index 45674faf..4ba8f56f 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -8,12 +8,13 @@ man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8 utils_common = sundries.c xmalloc.c realpath.c fsprobe.c -headers_common = fstab.h linux_fs.h mount_mntent.h mount_constants.h \ +headers_common = fstab.h mount_mntent.h mount_constants.h \ mount_paths.h lomount.h fsprobe.h realpath.h xmalloc.h \ getusername.h loop.h sundries.h mount_common = fstab.c mount_mntent.c getusername.c lomount.c \ - $(utils_common) $(headers_common) ../lib/env.c + $(utils_common) $(headers_common) ../lib/env.c ../lib/linux_version.c \ + ../lib/blkdev.c mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c mount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS) diff --git a/mount/fsprobe.c b/mount/fsprobe.c index b874f9d7..0be73ac3 100644 --- a/mount/fsprobe.c +++ b/mount/fsprobe.c @@ -6,7 +6,6 @@ #include #include #include "mount_paths.h" -#include "linux_fs.h" #include "fsprobe.h" #include "sundries.h" /* for xstrdup */ #include "nls.h" diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c index 6b47392b..efdacc7d 100644 --- a/mount/fsprobe_volumeid.c +++ b/mount/fsprobe_volumeid.c @@ -8,6 +8,8 @@ #include #include +#include "blkdev.h" + #include "fsprobe.h" #include "realpath.h" #include "mount_paths.h" @@ -39,8 +41,7 @@ static char return NULL; } - /* TODO: use blkdev_get_size() */ - if (ioctl(fd, BLKGETSIZE64, &size) != 0) + if (blkdev_get_size(fd, &size) != 0) size = 0; if (volume_id_probe_all(id, 0, size) == 0) { diff --git a/mount/linux_fs.h b/mount/linux_fs.h deleted file mode 100644 index e47da2f5..00000000 --- a/mount/linux_fs.h +++ /dev/null @@ -1,15 +0,0 @@ -/* Including became more and more painful. - Below a very abbreviated version of some declarations, - only designed to be able to check a magic number - in case no filesystem type was given. */ - -#ifndef BLKGETSIZE -#ifndef _IO -/* pre-1.3.45 */ -#define BLKGETSIZE 0x1260 /* return device size */ -#else -/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */ -#define BLKGETSIZE _IO(0x12,96) -#endif -#endif - diff --git a/mount/mount.c b/mount/mount.c index 154f0da5..7a6ae004 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -37,11 +37,11 @@ #include "fstab.h" #include "lomount.h" #include "loop.h" -#include "linux_fs.h" /* for BLKGETSIZE */ #include "getusername.h" #include "mount_paths.h" #include "env.h" #include "nls.h" +#include "blkdev.h" #include "realpath.h" #define DO_PS_FIDDLING @@ -1219,8 +1219,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, break; case EINVAL: { int fd; - unsigned long size; - int warned=0; + unsigned long long size = 0; if (flags & MS_REMOUNT) { error (_("mount: %s not mounted already, or bad option"), node); @@ -1230,32 +1229,21 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, spec); if (stat(spec, &statbuf) == 0 && S_ISBLK(statbuf.st_mode) - && (fd = open(spec, O_RDONLY | O_NONBLOCK)) >= 0) { - if (ioctl(fd, BLKGETSIZE, &size) == 0) { - if (size == 0 && !loop) { - warned++; + && (fd = open(spec, O_RDONLY | O_NONBLOCK)) >= 0) { + + if (blkdev_get_size(fd, &size) == 0) { + if (size == 0 && !loop) error(_( " (could this be the IDE device where you in fact use\n" " ide-scsi so that sr0 or sda or so is needed?)")); - } - if (size && size <= 2) { - warned++; + + if (size && size <= 2) error(_( " (aren't you trying to mount an extended partition,\n" " instead of some logical partition inside?)")); - } - close(fd); - } -#if 0 - /* 0xf for SCSI, 0x3f for IDE. One might check /proc/partitions - to see whether this thing really is partitioned. - Do not suggest partitions for /dev/fd0. */ - if (!warned && (statbuf.st_rdev & 0xf) == 0) { - warned++; - error (" (could this be the whole disk device\n" - " where you need a partition?)"); + + close(fd); } -#endif } error(_( " In some cases useful info is found in syslog - try\n"