diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 05:10:34 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 05:10:34 +0000 |
commit | 8e8408c65078c4f4c171e5cc2b567d6705bed024 (patch) | |
tree | 1605641dff9d3858f2b1595d8885bb0fe9496f34 /lib/ext2fs/getsize.c | |
parent | 037a031cb6f2d5e4575a3028e3c7135c59ee805a (diff) | |
parent | 63687023fc2e8871a718cb4e18458eece2e3460c (diff) | |
download | e2fsprogs-8e8408c65078c4f4c171e5cc2b567d6705bed024.tar.gz |
Snap for 10453563 from 63687023fc2e8871a718cb4e18458eece2e3460c to mainline-uwb-releaseaml_uwb_341710010aml_uwb_341513070aml_uwb_341511050aml_uwb_341310300aml_uwb_341310030aml_uwb_341111010aml_uwb_341011000android14-mainline-uwb-release
Change-Id: Ib8f5c32e208ea07a1c7814b337878a6d47c59923
Diffstat (limited to 'lib/ext2fs/getsize.c')
-rw-r--r-- | lib/ext2fs/getsize.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index be067755..a0286344 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -74,7 +74,8 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, blk64_t *retblocks) { - HANDLE dev; + int fd; + HANDLE h; PARTITION_INFORMATION pi; DISK_GEOMETRY gi; DWORD retbytes; @@ -84,20 +85,18 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, DWORD filesize; #endif /* HAVE_GET_FILE_SIZE_EX */ - dev = CreateFile(file, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE , - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if (dev == INVALID_HANDLE_VALUE) - return EBADF; - if (DeviceIoControl(dev, IOCTL_DISK_GET_PARTITION_INFO, + fd = ext2fs_open_file(file, O_RDONLY, 0); + if (fd < 0) + return errno; + h = (HANDLE)_get_osfhandle(fd); + if (DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO, &pi, sizeof(PARTITION_INFORMATION), &pi, sizeof(PARTITION_INFORMATION), &retbytes, NULL)) { *retblocks = pi.PartitionLength.QuadPart / blocksize; - } else if (DeviceIoControl(dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, + } else if (DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_GEOMETRY, &gi, sizeof(DISK_GEOMETRY), &gi, sizeof(DISK_GEOMETRY), &retbytes, NULL)) { @@ -108,19 +107,19 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, gi.Cylinders.QuadPart / blocksize; #ifdef HAVE_GET_FILE_SIZE_EX - } else if (GetFileSizeEx(dev, &filesize)) { + } else if (GetFileSizeEx(h, &filesize)) { *retblocks = filesize.QuadPart / blocksize; } #else } else { - filesize = GetFileSize(dev, NULL); + filesize = GetFileSize(h, NULL); if (INVALID_FILE_SIZE != filesize) { *retblocks = filesize / blocksize; } } #endif /* HAVE_GET_FILE_SIZE_EX */ - CloseHandle(dev); + close(fd); return 0; } @@ -295,7 +294,7 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, #ifdef DEBUG int main(int argc, char **argv) { - blk_t blocks; + blk64_t blocks; int retval; if (argc < 2) { @@ -303,13 +302,14 @@ int main(int argc, char **argv) exit(1); } - retval = ext2fs_get_device_size(argv[1], 1024, &blocks); + retval = ext2fs_get_device_size2(argv[1], 1024, &blocks); if (retval) { com_err(argv[0], retval, "while calling ext2fs_get_device_size"); exit(1); } - printf("Device %s has %u 1k blocks.\n", argv[1], blocks); + printf("Device %s has %llu 1k blocks.\n", argv[1], + (unsigned long long) locks); exit(0); } #endif |