[PATCH 25/26] commands: parted: prepare use of non-512-byte sectors
Ahmad Fatoum
a.fatoum at barebox.org
Fri Jun 26 01:42:36 PDT 2026
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 at 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
More information about the barebox
mailing list