Integrate with fastboot HAL to get partition type
Bug: 79480454
Bug: 78793464
Test: fastboot getvar partition-type:userdata
Change-Id: Ib096ee8061568b8503f3a3f2dbb7e19a932162c4
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index 9f3fa75..9ac2dda 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -31,6 +31,9 @@
using ::android::hardware::boot::V1_0::BoolResult;
using ::android::hardware::boot::V1_0::Slot;
+using ::android::hardware::fastboot::V1_0::FileSystemType;
+using ::android::hardware::fastboot::V1_0::Result;
+using ::android::hardware::fastboot::V1_0::Status;
constexpr int kMaxDownloadSizeDefault = 0x20000000;
constexpr char kFastbootProtocolVersion[] = "0.4";
@@ -195,6 +198,47 @@
return true;
}
+bool GetPartitionType(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
+ if (args.size() < 1) {
+ *message = "Missing argument";
+ return false;
+ }
+ std::string partition_name = args[0];
+ auto fastboot_hal = device->fastboot_hal();
+ if (!fastboot_hal) {
+ *message = "Fastboot HAL not found";
+ return false;
+ }
+
+ FileSystemType type;
+ Result ret;
+ auto ret_val =
+ fastboot_hal->getPartitionType(args[0], [&](FileSystemType fs_type, Result result) {
+ type = fs_type;
+ ret = result;
+ });
+ if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) {
+ *message = "Unable to retrieve partition type";
+ } else {
+ switch (type) {
+ case FileSystemType::RAW:
+ *message = "raw";
+ return true;
+ case FileSystemType::EXT4:
+ *message = "ext4";
+ return true;
+ case FileSystemType::F2FS:
+ *message = "f2fs";
+ return true;
+ default:
+ *message = "Unknown file system type";
+ }
+ }
+
+ return false;
+}
+
bool GetPartitionIsLogical(FastbootDevice* device, const std::vector<std::string>& args,
std::string* message) {
if (args.size() < 1) {