mkswap: BLKGETSIZE cleanup

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2007-11-07 13:26:27 +01:00
parent 3738a48e08
commit 54e377b386
2 changed files with 7 additions and 15 deletions

View File

@ -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 fsck_minix_SOURCES = fsck.minix.c bitops.h minix.h
mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h
mkfs_bfs_SOURCES = mkfs.bfs.c 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 usrbinexec_PROGRAMS = fdformat isosize

View File

@ -50,19 +50,12 @@
#include "swapheader.h" #include "swapheader.h"
#include "xstrncpy.h" #include "xstrncpy.h"
#include "nls.h" #include "nls.h"
#include "blkdev.h"
#ifdef HAVE_LIBUUID #ifdef HAVE_LIBUUID
#include <uuid/uuid.h> #include <uuid/uuid.h>
#endif #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 * program_name = "mkswap";
static char * device_name = NULL; static char * device_name = NULL;
static int DEV = -1; static int DEV = -1;
@ -428,19 +421,18 @@ find_size (int fd) {
static unsigned long static unsigned long
get_size(const char *file) { get_size(const char *file) {
int fd; int fd;
unsigned long size; unsigned long long size;
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror(file); perror(file);
exit(1); exit(1);
} }
if (ioctl(fd, BLKGETSIZE, &size) >= 0) { if (blkdev_get_size(fd, &size) == 0)
int sectors_per_page = pagesize/512; size /= pagesize;
size /= sectors_per_page; else
} else {
size = find_size(fd) / pagesize; size = find_size(fd) / pagesize;
}
close(fd); close(fd);
return size; return size;
} }