diff options
author | Samuel Thibault | 2008-07-24 01:15:07 +0200 |
---|---|---|
committer | Karel Zak | 2008-07-24 01:15:07 +0200 |
commit | 098fa6b1201bd66bc8fcb54b103ff241e3136dca (patch) | |
tree | 09904b63e53f7e7bbc083cd111833200aeae7c92 /disk-utils/mkswap.c | |
parent | fdisk: non-linux support (BLK* and HDIO_*) (diff) | |
download | kernel-qcow2-util-linux-098fa6b1201bd66bc8fcb54b103ff241e3136dca.tar.gz kernel-qcow2-util-linux-098fa6b1201bd66bc8fcb54b103ff241e3136dca.tar.xz kernel-qcow2-util-linux-098fa6b1201bd66bc8fcb54b103ff241e3136dca.zip |
disk-utils: clean up code, use blkdev_* functions
[kzak@redhat.com: split the original patch to small patches]
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 31 |
1 files changed, 1 insertions, 30 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 8bf358ed3..0bac74aba 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -388,35 +388,6 @@ check_blocks(void) { printf(_("%lu bad pages\n"), badpages); } -static long -valid_offset (int fd, off_t offset) { - char ch; - - if (lseek (fd, offset, 0) < 0) - return 0; - if (read (fd, &ch, 1) < 1) - return 0; - return 1; -} - -static off_t -find_size (int fd) { - off_t high, low; - - low = 0; - for (high = 1; high > 0 && valid_offset (fd, high); high *= 2) - low = high; - while (low < high - 1) { - const off_t mid = (low + high) / 2; - - if (valid_offset (fd, mid)) - low = mid; - else - high = mid; - } - return (low + 1); -} - /* return size in pages, to avoid integer overflow */ static unsigned long get_size(const char *file) { @@ -431,7 +402,7 @@ get_size(const char *file) { if (blkdev_get_size(fd, &size) == 0) size /= pagesize; else - size = find_size(fd) / pagesize; + size = blkdev_find_size(fd) / pagesize; close(fd); return size; |