From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 25/26] commands: parted: prepare use of non-512-byte sectors
Date: Fri, 26 Jun 2026 10:42:36 +0200 [thread overview]
Message-ID: <20260626084608.1388806-26-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260626084608.1388806-1-a.fatoum@barebox.org>
Switching parted to create non-512-byte sectors needs a bit more effort
than just switching out all hardcoded SECTOR_SIZE/SHIFT.
Nevertheless, pick these low hanging fruit and defer the rest to some
unknown point in the future.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/createnv.c | 11 ++++++-----
commands/parted.c | 14 +++++++-------
common/partitions/efi.c | 6 +++---
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/commands/createnv.c b/commands/createnv.c
index 0c74637a114c..6083ab7c2c8f 100644
--- a/commands/createnv.c
+++ b/commands/createnv.c
@@ -69,15 +69,16 @@ static int do_createnv(int argc, char *argv[])
goto err;
}
- buf = xzalloc(2 * SECTOR_SIZE);
+ buf = xzalloc(2 * BLOCKSIZE(blk));
- ret = cdev_read(cdev, buf, 2 * SECTOR_SIZE, 0, 0);
+ ret = cdev_read(cdev, buf, 2 * BLOCKSIZE(blk), 0, 0);
if (ret < 0) {
printf("Cannot read from %s: %pe\n", cdev->name, ERR_PTR(ret));
goto err;
}
- filetype = file_detect_partition_table(buf, 2 * SECTOR_SIZE, SECTOR_SIZE);
+ filetype = file_detect_partition_table(buf, 2 * BLOCKSIZE(blk),
+ BLOCKSIZE(blk));
switch (filetype) {
case filetype_gpt:
@@ -108,7 +109,7 @@ static int do_createnv(int argc, char *argv[])
}
}
- size >>= SECTOR_SHIFT;
+ size = blockdevice_round_nblocks(blk, size);
ret = partition_find_free_space(pdesc, size, &start);
if (ret) {
@@ -123,7 +124,7 @@ static int do_createnv(int argc, char *argv[])
}
printf("Will create a barebox environment partition of size %llu bytes on %s\n",
- size << SECTOR_SHIFT, cdev->name);
+ size * BLOCKSIZE(blk), cdev->name);
if (!force) {
char c;
diff --git a/commands/parted.c b/commands/parted.c
index dd79def62a3e..3f531faaef3f 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -109,15 +109,15 @@ static int do_print(struct block_device *blk, int argc, char *argv[])
}
printf("Disk /dev/%s: %s\n", blk->cdev.name,
- size_human_readable(blk->num_blocks << SECTOR_SHIFT));
+ size_human_readable(blockdevice_size(blk)));
printf("Partition Table: %s\n", pdesc->parser->name);
printf("Number Start End Size Name\n");
list_for_each_entry(part, &pdesc->partitions, list) {
- uint64_t start = part->first_sec << SECTOR_SHIFT;
- uint64_t size = part->size << SECTOR_SHIFT;
- uint64_t end = start + size - SECTOR_SIZE;
+ uint64_t start = part->first_sec << blk->blockbits;
+ uint64_t size = part->size << blk->blockbits;
+ uint64_t end = start + size - BLOCKSIZE(blk);
printf(" %3d %10llu%-3s %10llu%-3s %10llu%-3s %-36s\n",
part->num,
@@ -162,7 +162,7 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
start = ALIGN(start, SZ_1M);
/* convert to LBA */
- start >>= SECTOR_SHIFT;
+ start = blockdevice_round_nblocks(blk, start);
if (!strcmp(argv[4], "max")) {
/* gpt requires 34 blocks at the end */
@@ -182,7 +182,7 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
end *= mult;
/* convert to LBA */
- end >>= SECTOR_SHIFT;
+ end >>= blk->blockbits;
/*
* When unit is >= KB then subtract one sector for user
@@ -235,7 +235,7 @@ static int do_mkpart_size(struct block_device *blk, int argc, char *argv[])
size = ALIGN(size, PARTITION_ALIGN_SIZE);
/* convert to LBA */
- size >>= SECTOR_SHIFT;
+ size = blockdevice_round_nblocks(blk, size);
pdesc = pdesc_get(blk);
if (!pdesc)
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 33d9a1df9e83..18a8c4d56632 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -689,7 +689,7 @@ static __maybe_unused struct partition_desc *efi_partition_create_table(struct b
partition_desc_init(&epd->pd, blk);
- epd->gpt = xzalloc(SECTOR_SIZE);
+ epd->gpt = xzalloc(BLOCKSIZE(blk));
gpt = epd->gpt;
gpt->signature = cpu_to_le64(GPT_HEADER_SIGNATURE);
@@ -851,12 +851,12 @@ static int __efi_partition_write(struct efi_partition_desc *epd, bool primary)
uint64_t my_lba, partition_entry_lba;
int ret;
- gpt = xmemdup(epd->gpt, SECTOR_SIZE);
+ gpt = xmemdup(epd->gpt, BLOCKSIZE(blk));
count = le32_to_cpu(gpt->num_partition_entries) *
le32_to_cpu(gpt->sizeof_partition_entry);
- size = count / GPT_BLOCK_SIZE;
+ size = blockdevice_round_nblocks(blk, count);
if (primary) {
my_lba = 1;
--
2.47.3
next prev parent reply other threads:[~2026-06-26 8:51 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 8:42 [PATCH 00/26] block: add support for non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 01/26] nvme: use barebox-appropriate 64-bit type for timeouts Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 02/26] nvme: fix buffer advancement when chunking due to max_hw_sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 03/26] nvme: allow flush opcode Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 04/26] nvme: honor namespace block size for I/O Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 05/26] bootscan: fix detection of GPT Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 06/26] block: clarify that writebuffer_io_len returns sector counts Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 07/26] block: fix wrong type for discard_start/size byte ranges Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 08/26] block: fix discard zeroing too little memory Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 09/26] block: use logical block size for reparse checks Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 10/26] block: require lower bound of sector size to be 512 bytes Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 11/26] filetype: don't hardcode sector size in file_detect_partition_table Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 12/26] block: define helpers for non-512-byte sector support Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 13/26] bootscan: use block size for partition table probe Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 14/26] ramdisk: validate exported sector size Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 15/26] efi: block: fix sector size mismatch in block device registration and ops Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 16/26] efi: loader: disk: report block device size in Block I/O Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 17/26] efi: loader: file: report cdev block size in file info Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 18/26] partitions: use byte offset for first partition policy Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 19/26] partitions: dos: allocate correctly sized buffer for dos_partition_desc Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 20/26] partition: support non-512 byte sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 21/26] fs: fat: fix garbage read when writing with bigger block size Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 22/26] fs: fat: support larger block device sectors Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 23/26] usb-storage: preserve READ CAPACITY sector size Ahmad Fatoum
2026-06-26 8:42 ` [PATCH 24/26] fuzz: add 4K-sector partition ramdisk target Ahmad Fatoum
2026-06-26 8:42 ` Ahmad Fatoum [this message]
2026-06-26 8:42 ` [PATCH 26/26] commands: parted: exit if block size if not 512 Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260626084608.1388806-26-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox