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
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index a0e990a..63e8971 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -75,41 +75,35 @@
-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;
+bool fb_getvar(usb_handle* usb, const std::string& key, std::string* value) {
+ std::string cmd = "getvar:";
+ cmd += key;
- 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);
+ 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 @@
fprintf(stderr,"finished. total time: %.3fs\n", (now() - start));
return status;
}
-
-int fb_queue_is_empty(void)
-{
- return (action_list == nullptr);
-}