Merge "Clarify and fix the intent of the partition-type checking code."
This commit is contained in:
commit
d0f45aa24c
|
@ -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);
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue