From 343fa65e9fc67e55717d622ee1db6553dc2285b4 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 27 Jul 2001 22:15:06 -0400 Subject: [PATCH] getsize.c (ext2fs_get_device_size): Add support for the BLKGETSIZE64 ioctl. (Ioctl defined by unofficial patches from Ben LaHaise, but it's likely this interface won't change.) --- lib/ext2fs/ChangeLog | 5 +++++ lib/ext2fs/getsize.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 6ff0166..25c3a1b 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,10 @@ 2001-07-27 Theodore Tso + * getsize.c (ext2fs_get_device_size): Add support for the + BLKGETSIZE64 ioctl. (Ioctl defined by unofficial patches + from Ben LaHaise, but it's likely this interface won't + change.) + * mkjournal.c (ext2fs_add_journal_device): Use the correct block when writing the journal superblock, too. (Oops! Needed to make 1k filesystems with external journal to work.) diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index e8fadba..2558017 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -32,6 +32,9 @@ #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE) #define BLKGETSIZE _IO(0x12,96) /* return device size */ #endif +#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE64) +#define BLKGETSIZE64 _IO(0x12,109) /* return device size */ +#endif #include "ext2_fs.h" #include "ext2fs.h" @@ -54,6 +57,9 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, blk_t *retblocks) { int fd; +#ifdef BLKGETSIZE64 + unsigned long long size64; +#endif #ifdef BLKGETSIZE unsigned long size; #endif @@ -76,6 +82,17 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, if (fd < 0) return errno; +#ifdef BLKGETSIZE64 + if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) { + close(fd); + size64 = size64 / (blocksize / 512); + *retblocks = size64; + if (*retblocks != size64) { + return EFBIG; + } + return 0; + } +#endif #ifdef BLKGETSIZE if (ioctl(fd, BLKGETSIZE, &size) >= 0) { close(fd); -- 1.8.3.1