[PATCH 13/26] bootscan: use block size for partition table probe

Ahmad Fatoum a.fatoum at barebox.org
Fri Jun 26 01:42:24 PDT 2026


With 4k byte sectors, LBA1, which would contain the GPT magic string
would start at offset 4096, which is well outside the 2048 bytes that
FILE_TYPE_SAFE_BUFSIZE expands to.

Fix this by always reading at least the first two LBAs with the block
size reported by the block device.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 common/bootscan.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/common/bootscan.c b/common/bootscan.c
index 5b70024a75aa..60eeb06b65c2 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -8,6 +8,7 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <linux/err.h>
+#include <linux/minmax.h>
 #include <mtd/ubi-user.h>
 #include <uapi/spec/dps.h>
 
@@ -86,6 +87,7 @@ int boot_scan_cdev(struct bootscanner *scanner,
 		   bool autodiscover)
 {
 	int ret, found = 0;
+	unsigned int blocksize;
 	size_t bufsize, readsize;
 	void *buf;
 	enum filetype type, filetype;
@@ -98,7 +100,8 @@ int boot_scan_cdev(struct bootscanner *scanner,
 		return 0;
 	}
 
-	bufsize = FILE_TYPE_SAFE_BUFSIZE;
+	blocksize = cdev_blocksize(cdev);
+	bufsize = max_t(size_t, FILE_TYPE_SAFE_BUFSIZE, 2 * blocksize);
 
 	buf = xzalloc(bufsize);
 
@@ -110,7 +113,7 @@ int boot_scan_cdev(struct bootscanner *scanner,
 
 	readsize = ret;
 
-	type = file_detect_partition_table(buf, readsize, SECTOR_SIZE);
+	type = file_detect_partition_table(buf, readsize, blocksize);
 	filetype = file_detect_type(buf, readsize);
 	free(buf);
 
-- 
2.47.3




More information about the barebox mailing list