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);
diff --git a/model/ObbVolume.cpp b/model/ObbVolume.cpp
index ec3d267..21479c4 100644
--- a/model/ObbVolume.cpp
+++ b/model/ObbVolume.cpp
@@ -23,7 +23,6 @@
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
-#include <android-base/unique_fd.h>
#include <cutils/fs.h>
#include <private/android_filesystem_config.h>
@@ -36,7 +35,6 @@
#include <sys/wait.h>
using android::base::StringPrintf;
-using android::base::unique_fd;
namespace android {
namespace vold {
@@ -59,19 +57,10 @@
}
if (!mSourceKey.empty()) {
- unsigned long nr_sec = 0;
- {
- unique_fd loop_fd(open(mLoopPath.c_str(), O_RDWR | O_CLOEXEC));
- if (loop_fd.get() == -1) {
- PLOG(ERROR) << getId() << " failed to open loop";
- return -1;
- }
-
- get_blkdev_size(loop_fd.get(), &nr_sec);
- if (nr_sec == 0) {
- PLOG(ERROR) << getId() << " failed to get loop size";
- return -1;
- }
+ uint64_t nr_sec = 0;
+ if (GetBlockDev512Sectors(mLoopPath, &nr_sec) != OK) {
+ PLOG(ERROR) << getId() << " failed to get loop size";
+ return -1;
}
char tmp[PATH_MAX];