summaryrefslogtreecommitdiff
path: root/fastboot/engine.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-10-30 11:49:47 -0700
committerElliott Hughes <enh@google.com>2015-10-30 14:15:22 -0700
commit2fd45a9cea9d31375a44ba36b065c2f8a2999993 (patch)
treee78af401417273d7744ca674ae5ec1a5300ea9cb /fastboot/engine.cpp
parentbb51fbc4d4b311ae315e4d7dd174167ebeadc2a8 (diff)
fastboot shouldn't erase non-existent cache partitions.
Check that the cache partition exists before trying to erase it. Also clean up some of the C string handling and int booleans. Bug: http://b/25375777 Change-Id: I1880e542b729f2026ab3a2943d4bee9d659b1eeb
Diffstat (limited to 'fastboot/engine.cpp')
-rw-r--r--fastboot/engine.cpp57
1 files changed, 23 insertions, 34 deletions
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index a0e990a85..63e89714a 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -75,41 +75,35 @@ static Action *action_last = 0;
-int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...)
-{
- char cmd[CMD_SIZE] = "getvar:";
- int getvar_len = strlen(cmd);
- va_list args;
-
- response[FB_RESPONSE_SZ] = '\0';
- va_start(args, fmt);
- vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args);
- va_end(args);
- cmd[CMD_SIZE - 1] = '\0';
- return fb_command_response(usb, cmd, response);
+bool fb_getvar(usb_handle* usb, const std::string& key, std::string* value) {
+ std::string cmd = "getvar:";
+ cmd += key;
+
+ char buf[FB_RESPONSE_SZ + 1];
+ memset(buf, 0, sizeof(buf));
+ if (fb_command_response(usb, cmd.c_str(), buf)) {
+ return false;
+ }
+ *value = buf;
+ return true;
}
-/* Return true if this partition is supported by the fastboot format command.
- * It is also used to determine if we should first erase a partition before
- * flashing it with an ext4 filesystem. See needs_erase()
- *
- * Not all devices report the filesystem type, so don't report any errors,
- * just return false.
- */
-int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override)
-{
- char fs_type[FB_RESPONSE_SZ + 1] = {0,};
- int status;
-
+// Return true if this partition is supported by the fastboot format command.
+// It is also used to determine if we should first erase a partition before
+// flashing it with an ext4 filesystem. See needs_erase()
+//
+// Not all devices report the filesystem type, so don't report any errors,
+// just return false.
+bool fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) {
if (type_override) {
- return !!fs_get_generator(type_override);
+ return fs_get_generator(type_override) != nullptr;
}
- status = fb_getvar(usb, fs_type, "partition-type:%s", partition);
- if (status) {
- return 0;
+ std::string partition_type;
+ if (!fb_getvar(usb, std::string("partition-type:") + partition, &partition_type)) {
+ return false;
}
- return !!fs_get_generator(fs_type);
+ return fs_get_generator(partition_type.c_str()) != nullptr;
}
static int cb_default(Action* a, int status, const char* resp) {
@@ -394,8 +388,3 @@ int fb_execute_queue(usb_handle *usb)
fprintf(stderr,"finished. total time: %.3fs\n", (now() - start));
return status;
}
-
-int fb_queue_is_empty(void)
-{
- return (action_list == nullptr);
-}