fastboot: handle small flash block sizes correctly
Erase block sizes smaller than the ext4 block size may be valid, but
can incorrectly result in a stripe width smaller than the stride
size. Instead of reporting these sizes as invalid, add a check to
enforce that raid_stripe_width >= raid_stride.
Bug: 68770797
Test: Hack fb_getvar to report small erase block size, run fastboot
-w and confirm it does not print a warning or set stripe_width smaller
than stride.
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I689ce4bdd5b38bd0952bb6de54785cca39176010
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index c3b1bfb..222d64f 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1365,9 +1365,8 @@
fprintf(stderr, "Couldn't parse %s '%s'.\n", name.c_str(), sizeString.c_str());
return 0;
}
- if (size < 4096 || (size & (size - 1)) != 0) {
- fprintf(stderr, "Invalid %s %u: must be a power of 2 and at least 4096.\n",
- name.c_str(), size);
+ if ((size & (size - 1)) != 0) {
+ fprintf(stderr, "Invalid %s %u: must be a power of 2.\n", name.c_str(), size);
return 0;
}
return size;
diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp
index 709f061..e78e97f 100644
--- a/fastboot/fs.cpp
+++ b/fastboot/fs.cpp
@@ -120,6 +120,8 @@
int raid_stripe_width = eraseBlkSize / block_size;
// stride should be the max of 8kb and logical block size
if (logicalBlkSize != 0 && logicalBlkSize < 8192) raid_stride = 8192 / block_size;
+ // stripe width should be >= stride
+ if (raid_stripe_width < raid_stride) raid_stripe_width = raid_stride;
ext_attr += StringPrintf(",stride=%d,stripe-width=%d", raid_stride, raid_stripe_width);
}
mke2fs_args.push_back("-E");