diff options
Diffstat (limited to 'fastboot')
-rw-r--r-- | fastboot/engine.cpp | 18 | ||||
-rw-r--r-- | fastboot/fastboot.cpp | 17 | ||||
-rw-r--r-- | fastboot/fastboot.h | 1 | ||||
-rw-r--r-- | fastboot/fs.cpp | 4 | ||||
-rw-r--r-- | fastboot/fs.h | 3 |
5 files changed, 15 insertions, 28 deletions
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp index 63e89714a..44796d7d9 100644 --- a/fastboot/engine.cpp +++ b/fastboot/engine.cpp @@ -88,24 +88,6 @@ bool fb_getvar(usb_handle* usb, const std::string& key, std::string* value) { 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. -bool fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) { - if (type_override) { - return fs_get_generator(type_override) != nullptr; - } - std::string partition_type; - if (!fb_getvar(usb, std::string("partition-type:") + partition, &partition_type)) { - return false; - } - return fs_get_generator(partition_type.c_str()) != nullptr; -} - static int cb_default(Action* a, int status, const char* resp) { if (status) { fprintf(stderr,"FAILED (%s)\n", resp); diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 6b845a013..5745fb0a4 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -614,8 +614,12 @@ static int64_t get_sparse_limit(usb_handle* usb, int64_t size) { // Until we get lazy inode table init working in make_ext4fs, we need to // erase partitions of type ext4 before flashing a filesystem so no stale // inodes are left lying around. Otherwise, e2fsck gets very upset. -static bool needs_erase(usb_handle* usb, const char* part) { - return !fb_format_supported(usb, part, nullptr); +static bool needs_erase(usb_handle* usb, const char* partition) { + std::string partition_type; + if (!fb_getvar(usb, std::string("partition-type:") + partition, &partition_type)) { + return false; + } + return partition_type == "ext4"; } static int load_buf_fd(usb_handle* usb, int fd, struct fastboot_buffer* buf) { @@ -889,7 +893,7 @@ static void fb_perform_format(usb_handle* usb, partition_size = size_override; } - gen = fs_get_generator(partition_type.c_str()); + gen = fs_get_generator(partition_type); if (!gen) { if (skip_if_not_supported) { fprintf(stderr, "Erase successful, but not automatically formatting.\n"); @@ -1059,8 +1063,11 @@ int main(int argc, char **argv) } else if(!strcmp(*argv, "erase")) { require(2); - if (!fb_format_supported(usb, argv[1], nullptr)) { - fprintf(stderr, "******** Did you mean to fastboot format this partition?\n"); + std::string partition_type; + if (fb_getvar(usb, std::string("partition-type:") + argv[1], &partition_type) && + fs_get_generator(partition_type) != nullptr) { + fprintf(stderr, "******** Did you mean to fastboot format this %s partition?\n", + partition_type.c_str()); } fb_queue_erase(argv[1]); diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index a66c21198..9e33531a4 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -50,7 +50,6 @@ char *fb_get_error(void); /* engine.c - high level command queue engine */ bool fb_getvar(usb_handle* usb, const std::string& key, std::string* value); -bool fb_format_supported(usb_handle* usb, const char* partition, const char* type_override); void fb_queue_flash(const char *ptn, void *data, uint32_t sz); void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, uint32_t sz); void fb_queue_erase(const char *ptn); diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp index c58a505b7..90d84742b 100644 --- a/fastboot/fs.cpp +++ b/fastboot/fs.cpp @@ -39,9 +39,9 @@ static const struct fs_generator { #endif }; -const struct fs_generator* fs_get_generator(const char* fs_type) { +const struct fs_generator* fs_get_generator(const std::string& fs_type) { for (size_t i = 0; i < sizeof(generators) / sizeof(*generators); i++) { - if (strcmp(generators[i].fs_type, fs_type) == 0) { + if (fs_type == generators[i].fs_type) { return generators + i; } } diff --git a/fastboot/fs.h b/fastboot/fs.h index 8444081eb..289488b2d 100644 --- a/fastboot/fs.h +++ b/fastboot/fs.h @@ -5,8 +5,7 @@ struct fs_generator; -const struct fs_generator* fs_get_generator(const char *fs_type); +const struct fs_generator* fs_get_generator(const std::string& fs_type); int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize); #endif - |