Merge "Add vdc volume getStorageSize" into main am: f05039392c
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2706217 Change-Id: I82ad84f8b63fb5f9204a35e1940cb9a77d45bc23 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
0923cc69d7
6 changed files with 86 additions and 0 deletions
|
@ -946,5 +946,10 @@ binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSl
|
|||
return translateBool(destroy_dsu_metadata_key(dsuSlot));
|
||||
}
|
||||
|
||||
binder::Status VoldNativeService::getStorageSize(int64_t* storageSize) {
|
||||
ENFORCE_SYSTEM_OR_ROOT;
|
||||
return translate(GetStorageSize(storageSize));
|
||||
}
|
||||
|
||||
} // namespace vold
|
||||
} // namespace android
|
||||
|
|
|
@ -162,6 +162,8 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
|
|||
binder::Status bindMount(const std::string& sourceDir, const std::string& targetDir) override;
|
||||
|
||||
binder::Status destroyDsuMetadataKey(const std::string& dsuSlot) override;
|
||||
|
||||
binder::Status getStorageSize(int64_t* storageSize) override;
|
||||
};
|
||||
|
||||
} // namespace vold
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <linux/kdev_t.h>
|
||||
|
||||
#include <ApexProperties.sysprop.h>
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include <android-base/properties.h>
|
||||
|
@ -53,6 +54,7 @@
|
|||
#include <private/android_filesystem_config.h>
|
||||
|
||||
#include <fscrypt/fscrypt.h>
|
||||
#include <libdm/dm.h>
|
||||
|
||||
#include "AppFuseUtil.h"
|
||||
#include "FsCrypt.h"
|
||||
|
@ -1196,3 +1198,68 @@ int VolumeManager::unmountAppFuse(uid_t uid, int mountId) {
|
|||
int VolumeManager::openAppFuseFile(uid_t uid, int mountId, int fileId, int flags) {
|
||||
return android::vold::OpenAppFuseFile(uid, mountId, fileId, flags);
|
||||
}
|
||||
|
||||
android::status_t android::vold::GetStorageSize(int64_t* storageSize) {
|
||||
// Start with the /data mount point from fs_mgr
|
||||
auto entry = android::fs_mgr::GetEntryForMountPoint(&fstab_default, DATA_MNT_POINT);
|
||||
if (entry == nullptr) {
|
||||
LOG(ERROR) << "No mount point entry for " << DATA_MNT_POINT;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
// Follow any symbolic links
|
||||
std::string blkDevice = entry->blk_device;
|
||||
std::string dataDevice;
|
||||
if (!android::base::Realpath(blkDevice, &dataDevice)) {
|
||||
dataDevice = blkDevice;
|
||||
}
|
||||
|
||||
// Handle mapped volumes.
|
||||
auto& dm = android::dm::DeviceMapper::Instance();
|
||||
for (;;) {
|
||||
auto parent = dm.GetParentBlockDeviceByPath(dataDevice);
|
||||
if (!parent.has_value()) break;
|
||||
dataDevice = *parent;
|
||||
}
|
||||
|
||||
// Get the potential /sys/block entry
|
||||
std::size_t leaf = dataDevice.rfind('/');
|
||||
if (leaf == std::string::npos) {
|
||||
LOG(ERROR) << "data device " << dataDevice << " is not a path";
|
||||
return EINVAL;
|
||||
}
|
||||
if (dataDevice.substr(0, leaf) != "/dev/block") {
|
||||
LOG(ERROR) << "data device " << dataDevice << " is not a block device";
|
||||
return EINVAL;
|
||||
}
|
||||
std::string sysfs = std::string() + "/sys/block/" + dataDevice.substr(leaf + 1);
|
||||
|
||||
// Look for a directory in /sys/block containing size where the name is a shortened
|
||||
// version of the name we now have
|
||||
// Typically we start with something like /sys/block/sda2, and we want /sys/block/sda
|
||||
// Note that this directory only contains actual disks, not partitions, so this is
|
||||
// not going to find anything other than the disks
|
||||
std::string size;
|
||||
std::string sizeFile;
|
||||
for (std::string sysfsDir = sysfs;; sysfsDir = sysfsDir.substr(0, sysfsDir.size() - 1)) {
|
||||
if (sysfsDir.back() == '/') {
|
||||
LOG(ERROR) << "Could not find valid block device from " << sysfs;
|
||||
return EINVAL;
|
||||
}
|
||||
sizeFile = sysfsDir + "/size";
|
||||
if (android::base::ReadFileToString(sizeFile, &size, true)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Read the size file and be done
|
||||
std::stringstream ssSize(size);
|
||||
ssSize >> *storageSize;
|
||||
if (ssSize.fail()) {
|
||||
LOG(ERROR) << sizeFile << " cannot be read as an integer";
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
*storageSize *= 512;
|
||||
return OK;
|
||||
}
|
|
@ -242,4 +242,10 @@ class VolumeManager {
|
|||
bool mSecureKeyguardShowing;
|
||||
};
|
||||
|
||||
namespace android {
|
||||
namespace vold {
|
||||
android::status_t GetStorageSize(int64_t* storageSize);
|
||||
}
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -136,6 +136,8 @@ interface IVold {
|
|||
|
||||
void destroyDsuMetadataKey(@utf8InCpp String dsuSlot);
|
||||
|
||||
long getStorageSize();
|
||||
|
||||
const int FSTRIM_FLAG_DEEP_TRIM = 1;
|
||||
|
||||
const int MOUNT_FLAG_PRIMARY = 1;
|
||||
|
|
4
vdc.cpp
4
vdc.cpp
|
@ -122,6 +122,10 @@ int main(int argc, char** argv) {
|
|||
checkStatus(args, vold->shutdown());
|
||||
} else if (args[0] == "volume" && args[1] == "reset") {
|
||||
checkStatus(args, vold->reset());
|
||||
} else if (args[0] == "volume" && args[1] == "getStorageSize") {
|
||||
int64_t size;
|
||||
checkStatus(args, vold->getStorageSize(&size));
|
||||
LOG(INFO) << size;
|
||||
} else if (args[0] == "cryptfs" && args[1] == "bindkeys") {
|
||||
bindkeys(args, vold);
|
||||
} else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 5) {
|
||||
|
|
Loading…
Reference in a new issue