[PATCH 10/26] block: require lower bound of sector size to be 512 bytes

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


Various places around barebox implicitly assume 512 byte sectors. We are
going to generalize that to be able to support larger block sizes as
newer storage media can have 4k sectors.

As sector sizes below 512 bytes seem only relevant for historic floppy
disks and the like, define MIN_SECTOR_SHIFT/SIZE to that sector size and
refuse registering a block device that has a smaller sector size, so we do
not need to replicate that check in the users of blockdevice_register().

The new MIN_SECTOR_SHIFT/SIZE macros are added to make it easier in
future to differentiate between valid sanity checks like what's added
here and hardcoded sector assumptions that should be fixed.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 common/block.c  | 2 +-
 include/disks.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/common/block.c b/common/block.c
index 20ec3665d900..9d3865626555 100644
--- a/common/block.c
+++ b/common/block.c
@@ -471,7 +471,7 @@ int blockdevice_register(struct block_device *blk)
 	dev_dbg(blk->dev, "rdbufsize: %d blockbits: %d blkmask: 0x%08x\n",
 		blk->rdbufsize, blk->blockbits, blk->blkmask);
 
-	if (!blk->rdbufsize) {
+	if (!blk->rdbufsize || blk->blockbits < MIN_SECTOR_SHIFT) {
 		pr_warn("block size of %u not supported\n", BLOCKSIZE(blk));
 		return -ENOSYS;
 	}
diff --git a/include/disks.h b/include/disks.h
index a3673d1e276f..93f8bb2b7c26 100644
--- a/include/disks.h
+++ b/include/disks.h
@@ -8,6 +8,13 @@
 
 struct block_device;
 
+/** Minimum size of one sector in bytes */
+#define MIN_SECTOR_SIZE 512
+
+/** Minimum size of one sector in bit shift */
+#define MIN_SECTOR_SHIFT 9
+
+
 /** Size of one sector in bytes */
 #define SECTOR_SIZE 512
 
-- 
2.47.3




More information about the barebox mailing list