summaryrefslogtreecommitdiff
path: root/fastboot/device/variables.cpp
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-08-09 19:47:17 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-08-09 19:47:17 +0000
commit3cf9f9b83826c4b920d83dc4647af678be3b159c (patch)
treeb8bd07c40126dc8e4519c687bc17d21fc16136ba /fastboot/device/variables.cpp
parent424ffa2df93b92f0c0e31cc62983e83d696ddd89 (diff)
parent88ef0b1f256be1958a9c6c8989165400f1181340 (diff)
Merge changes Id2a61d35,Ibe802c36
* changes: fastbootd: Add support for flashing logical partitions. fastbootd: Enable erase and flash commands for physical partitions.
Diffstat (limited to 'fastboot/device/variables.cpp')
-rw-r--r--fastboot/device/variables.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index 33f7f74bd..b51b98535 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -16,6 +16,8 @@
#include "variables.h"
+#include <inttypes.h>
+
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
@@ -24,6 +26,7 @@
#include <ext4_utils/ext4_utils.h>
#include "fastboot_device.h"
+#include "flashing.h"
#include "utility.h"
using ::android::hardware::boot::V1_0::BoolResult;
@@ -125,3 +128,23 @@ bool GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args) {
std::string result = (args[0] == "userdata" ? "no" : "yes");
return device->WriteOkay(result);
}
+
+bool GetPartitionSize(FastbootDevice* device, const std::vector<std::string>& args) {
+ if (args.size() < 1) {
+ return device->WriteFail("Missing argument");
+ }
+ // Zero-length partitions cannot be created through device-mapper, so we
+ // special case them here.
+ bool is_zero_length;
+ if (LogicalPartitionExists(args[0], device->GetCurrentSlot(), &is_zero_length) &&
+ is_zero_length) {
+ return device->WriteOkay("0");
+ }
+ // Otherwise, open the partition as normal.
+ PartitionHandle handle;
+ if (!OpenPartition(device, args[0], &handle)) {
+ return device->WriteFail("Could not open partition");
+ }
+ uint64_t size = get_block_device_size(handle.fd());
+ return device->WriteOkay(android::base::StringPrintf("%" PRIX64, size));
+}