Add 64-bit getsize interface.
Added interface capable of opening 64-bit block device.
Signed-off-by: Jose R. Santos <jrs@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/debian/e2fslibs.symbols b/debian/e2fslibs.symbols
index 3bea44e..8f6aab9 100644
--- a/debian/e2fslibs.symbols
+++ b/debian/e2fslibs.symbols
@@ -161,6 +161,7 @@
ext2fs_get_data_io@Base 1.37
ext2fs_get_device_sectsize@Base 1.37
ext2fs_get_device_size@Base 1.37
+ ext2fs_get_device_size2@Base 1.41.4
ext2fs_get_free_blocks@Base 1.37
ext2fs_get_generic_bitmap_end@Base 1.41.0
ext2fs_get_generic_bitmap_range@Base 1.41.0
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index e02a55f..d5026bc 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -928,6 +928,8 @@
/* getsize.c */
extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks);
+extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
+ blk64_t *retblocks);
/* getsectsize.c */
errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index b45e285..79fba59 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -138,8 +138,8 @@
/*
* Returns the number of blocks in a partition
*/
-errcode_t ext2fs_get_device_size(const char *file, int blocksize,
- blk_t *retblocks)
+errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
+ blk64_t *retblocks)
{
int fd, rc = 0;
int valid_blkgetsize64 = 1;
@@ -169,11 +169,6 @@
#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
- if ((sizeof(*retblocks) < sizeof(unsigned long long))
- && ((size64 / (blocksize / 512)) > 0xFFFFFFFF)) {
- rc = EFBIG;
- goto out;
- }
*retblocks = size64 / (blocksize / 512);
goto out;
}
@@ -188,11 +183,6 @@
#endif
if (valid_blkgetsize64 &&
ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
- if ((sizeof(*retblocks) < sizeof(unsigned long long)) &&
- ((size64 / blocksize) > 0xFFFFFFFF)) {
- rc = EFBIG;
- goto out;
- }
*retblocks = size64 / blocksize;
goto out;
}
@@ -253,11 +243,6 @@
if (fstat(fd, &st) == 0)
#endif
if (S_ISREG(st.st_mode)) {
- if ((sizeof(*retblocks) < sizeof(unsigned long long)) &&
- ((st.st_size / blocksize) > 0xFFFFFFFF)) {
- rc = EFBIG;
- goto out;
- }
*retblocks = st.st_size / blocksize;
goto out;
}
@@ -282,17 +267,26 @@
}
valid_offset (fd, 0);
size64 = low + 1;
- if ((sizeof(*retblocks) < sizeof(unsigned long long))
- && ((size64 / blocksize) > 0xFFFFFFFF)) {
- rc = EFBIG;
- goto out;
- }
*retblocks = size64 / blocksize;
out:
close(fd);
return rc;
}
+errcode_t ext2fs_get_device_size(const char *file, int blocksize,
+ blk_t *retblocks)
+{
+ errcode_t retval;
+ blk64_t blocks;
+ retval = ext2fs_get_device_size2(file, blocksize, &blocks);
+
+ if (!retval && blocks < (1ULL << 32)) {
+ *retblocks = (blk_t) blocks;
+ return retval;
+ }
+ return EFBIG;
+}
+
#endif /* WIN32 */
#ifdef DEBUG