Add GetBlockDevSize, GetBlockDevSectors helpers
Helpers to get a block device size in bytes or 512 byte sectors,
using BLKGETSIZE64 and returning value of uint64_t type.
This also removes get_blkdev_size().
Test: build, manual, mount exFAT volume
Bug: 80202067
Change-Id: Ib07e8ac6ef7ff49de0ed570d1fa202e8b558b80c
diff --git a/model/Disk.cpp b/model/Disk.cpp
index 13cb1c7..2b6773d 100644
--- a/model/Disk.cpp
+++ b/model/Disk.cpp
@@ -243,12 +243,8 @@
mSize = -1;
mLabel.clear();
- int fd = open(mDevPath.c_str(), O_RDONLY | O_CLOEXEC);
- if (fd != -1) {
- if (ioctl(fd, BLKGETSIZE64, &mSize)) {
- mSize = -1;
- }
- close(fd);
+ if (GetBlockDevSize(mDevPath, &mSize) != OK) {
+ mSize = -1;
}
unsigned int majorId = major(mDevice);