From: Karel Zak Date: Wed, 7 Nov 2007 12:26:27 +0000 (+0100) Subject: mkswap: BLKGETSIZE cleanup X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54e377b38698f285e0c4aeef124912030cdb85fe;p=util-linux mkswap: BLKGETSIZE cleanup Signed-off-by: Karel Zak --- diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am index 4b8f55c4..7042aeed 100644 --- a/disk-utils/Makefile.am +++ b/disk-utils/Makefile.am @@ -7,7 +7,7 @@ sbin_PROGRAMS = mkfs mkswap blockdev fsck.minix mkfs.minix mkfs.bfs fsck_minix_SOURCES = fsck.minix.c bitops.h minix.h mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h mkfs_bfs_SOURCES = mkfs.bfs.c -mkswap_SOURCES = mkswap.c swapheader.h ../lib/linux_version.c +mkswap_SOURCES = mkswap.c swapheader.h ../lib/linux_version.c ../lib/blkdev.c usrbinexec_PROGRAMS = fdformat isosize diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index d61075b5..850236f9 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -50,19 +50,12 @@ #include "swapheader.h" #include "xstrncpy.h" #include "nls.h" +#include "blkdev.h" #ifdef HAVE_LIBUUID #include #endif -#ifndef _IO -/* pre-1.3.45 */ -#define BLKGETSIZE 0x1260 -#else -/* same on i386, m68k, arm; different on alpha, mips, sparc, ppc */ -#define BLKGETSIZE _IO(0x12,96) -#endif - static char * program_name = "mkswap"; static char * device_name = NULL; static int DEV = -1; @@ -428,19 +421,18 @@ find_size (int fd) { static unsigned long get_size(const char *file) { int fd; - unsigned long size; + unsigned long long size; fd = open(file, O_RDONLY); if (fd < 0) { perror(file); exit(1); } - if (ioctl(fd, BLKGETSIZE, &size) >= 0) { - int sectors_per_page = pagesize/512; - size /= sectors_per_page; - } else { + if (blkdev_get_size(fd, &size) == 0) + size /= pagesize; + else size = find_size(fd) / pagesize; - } + close(fd); return size; }