* [PATCH] cdev: maintain partition index in struct cdev
@ 2025-12-11 20:42 Ahmad Fatoum
0 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 20:42 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use by the EFI loader, we will need to know a partition's number
within the disk, so have the devfs-core keep track of that.
If all cdevs are deleted because of reparenting, we also reset the
counting back to zero.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 6 +++++-
fs/fs.c | 8 ++++++--
include/driver.h | 3 +++
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 67ce67851769..3c6e146d78ff 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -599,8 +599,11 @@ int devfs_remove(struct cdev *cdev)
list_for_each_entry_safe(c, tmp, &cdev->partitions, partition_entry)
cdevfs_del_partition(c);
- if (cdev_is_partition(cdev))
+ if (cdev_is_partition(cdev)) {
list_del(&cdev->partition_entry);
+ if (list_empty(&cdev->master->partitions))
+ cdev->master->partition_table_index = 0;
+ }
return 0;
}
@@ -736,6 +739,7 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev,
new->size = size;
new->offset = cdev->offset + offset;
new->flags = inherited_flags;
+ new->partition_table_index = cdev->partition_table_index++;
new->dev = cdev->dev;
new->master = cdev;
diff --git a/fs/fs.c b/fs/fs.c
index 77f22d69ea49..55f9174f945d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -78,8 +78,12 @@ void cdev_print(const struct cdev *cdev)
printf("Origin: %s", dev_name(cdev->dev) ?: "None");
if (cdev->master)
printf("\tMaster: %s", cdev->master->name);
- if (cdev->partname)
- printf("\tPartition: %s", cdev->partname);
+ if (cdev->partname) {
+ printf("\tPartition:");
+ if (cdev->flags & DEVFS_PARTITION_FROM_TABLE)
+ printf(" #%d", cdev->partition_table_index);
+ printf(" \"%s\"", cdev->partname);
+ }
printf("\n");
}
printf("Ocount: %d\tFlags: 0x%02x", cdev->open, cdev->flags);
diff --git a/include/driver.h b/include/driver.h
index de5a63c379eb..6d13042f0757 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -431,6 +431,9 @@ struct cdev {
loff_t size;
unsigned int flags;
u16 typeflags; /* GPT type-specific attributes */
+ s8 partition_table_index; /* For GPT/MBR-formatted disks only: 0-based index of partition
+ * or number of index of next free child partition otherwise
+ */
int open;
struct mtd_info *mtd;
struct list_head aliases;
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cdev: maintain partition index in struct cdev
2025-12-18 9:30 ` Ahmad Fatoum
@ 2025-12-18 9:38 ` Sascha Hauer
0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2025-12-18 9:38 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Thu, Dec 18, 2025 at 10:30:59AM +0100, Ahmad Fatoum wrote:
>
>
> On 12/18/25 10:29 AM, Sascha Hauer wrote:
> > On Thu, Dec 18, 2025 at 10:19:45AM +0100, Ahmad Fatoum wrote:
> >> For use by the EFI loader, we will need to know a partition's number
> >> within the partition table on disk, so have the devfs-core keep track
> >> of that.
> >>
> >> Mere iteration over the cdev list doesn't work for thus purpose as there
> >> may be invalid PTEs, which cause e.g. the first on-disk partition to
> >> have a higher number.
> >>
> >> See 9dfffaf2ef47 ("partitions: efi: Continue partition enumeration on
> >> invalid pte") for more info. A real world example is the current
> >> debian-13-nocloud-arm64.raw image, which has two partitions:
> >> 0 and 14 (or 1 and 15 in barebox).
> >
> > Should have mentioned this in my last mail, but isn't this the other way
> > round?
>
> Yes, of course. Should I resend?
Nope, fixed.
Sascha
>
> >
> > Sascja
> >
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
> >> v2 -> v3:
> >> - fix comment to mention that index is 0-based (Sascha)j
> >> v1 -> v2:
> >> - record actual partition number from the table.
> >> I compared against EDK-II and Linux and both take the actual
> >> number, which may not be either the number in our cdev list
> >> or the location on disk.
> >> ---
> >> common/partitions.c | 1 +
> >> include/driver.h | 3 +++
> >> 2 files changed, 4 insertions(+)
> >>
> >> diff --git a/common/partitions.c b/common/partitions.c
> >> index 1a4e046c5f55..40f4c629e1ac 100644
> >> --- a/common/partitions.c
> >> +++ b/common/partitions.c
> >> @@ -52,6 +52,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
> >> goto out;
> >> }
> >>
> >> + cdev->partition_table_index = part->num;
> >> cdev->flags |= DEVFS_PARTITION_FROM_TABLE | part->flags;
> >> cdev->typeflags |= part->typeflags;
> >> cdev->typeuuid = part->typeuuid;
> >> diff --git a/include/driver.h b/include/driver.h
> >> index 14d1731fd976..77b9b876955a 100644
> >> --- a/include/driver.h
> >> +++ b/include/driver.h
> >> @@ -436,6 +436,9 @@ struct cdev {
> >> loff_t size;
> >> unsigned int flags;
> >> u16 typeflags; /* GPT type-specific attributes */
> >> + s8 partition_table_index; /* For GPT/MBR-formatted disks only:
> >> + * 0-based index of partition on disk
> >> + */
> >> int open;
> >> struct mtd_info *mtd;
> >> struct list_head aliases;
> >> --
> >> 2.47.3
> >>
> >>
> >>
> >
>
> --
> Pengutronix e.K. | |
> Steuerwalder Str. 21 | http://www.pengutronix.de/ |
> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cdev: maintain partition index in struct cdev
2025-12-18 9:19 Ahmad Fatoum
2025-12-18 9:29 ` Sascha Hauer
@ 2025-12-18 9:37 ` Sascha Hauer
1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2025-12-18 9:37 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Thu, 18 Dec 2025 10:19:45 +0100, Ahmad Fatoum wrote:
> For use by the EFI loader, we will need to know a partition's number
> within the partition table on disk, so have the devfs-core keep track
> of that.
>
> Mere iteration over the cdev list doesn't work for thus purpose as there
> may be invalid PTEs, which cause e.g. the first on-disk partition to
> have a higher number.
>
> [...]
Applied, thanks!
[1/1] cdev: maintain partition index in struct cdev
https://git.pengutronix.de/cgit/barebox/commit/?id=ebe242d1d9d2 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cdev: maintain partition index in struct cdev
2025-12-18 9:29 ` Sascha Hauer
@ 2025-12-18 9:30 ` Ahmad Fatoum
2025-12-18 9:38 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Ahmad Fatoum @ 2025-12-18 9:30 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 12/18/25 10:29 AM, Sascha Hauer wrote:
> On Thu, Dec 18, 2025 at 10:19:45AM +0100, Ahmad Fatoum wrote:
>> For use by the EFI loader, we will need to know a partition's number
>> within the partition table on disk, so have the devfs-core keep track
>> of that.
>>
>> Mere iteration over the cdev list doesn't work for thus purpose as there
>> may be invalid PTEs, which cause e.g. the first on-disk partition to
>> have a higher number.
>>
>> See 9dfffaf2ef47 ("partitions: efi: Continue partition enumeration on
>> invalid pte") for more info. A real world example is the current
>> debian-13-nocloud-arm64.raw image, which has two partitions:
>> 0 and 14 (or 1 and 15 in barebox).
>
> Should have mentioned this in my last mail, but isn't this the other way
> round?
Yes, of course. Should I resend?
>
> Sascja
>
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> v2 -> v3:
>> - fix comment to mention that index is 0-based (Sascha)j
>> v1 -> v2:
>> - record actual partition number from the table.
>> I compared against EDK-II and Linux and both take the actual
>> number, which may not be either the number in our cdev list
>> or the location on disk.
>> ---
>> common/partitions.c | 1 +
>> include/driver.h | 3 +++
>> 2 files changed, 4 insertions(+)
>>
>> diff --git a/common/partitions.c b/common/partitions.c
>> index 1a4e046c5f55..40f4c629e1ac 100644
>> --- a/common/partitions.c
>> +++ b/common/partitions.c
>> @@ -52,6 +52,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
>> goto out;
>> }
>>
>> + cdev->partition_table_index = part->num;
>> cdev->flags |= DEVFS_PARTITION_FROM_TABLE | part->flags;
>> cdev->typeflags |= part->typeflags;
>> cdev->typeuuid = part->typeuuid;
>> diff --git a/include/driver.h b/include/driver.h
>> index 14d1731fd976..77b9b876955a 100644
>> --- a/include/driver.h
>> +++ b/include/driver.h
>> @@ -436,6 +436,9 @@ struct cdev {
>> loff_t size;
>> unsigned int flags;
>> u16 typeflags; /* GPT type-specific attributes */
>> + s8 partition_table_index; /* For GPT/MBR-formatted disks only:
>> + * 0-based index of partition on disk
>> + */
>> int open;
>> struct mtd_info *mtd;
>> struct list_head aliases;
>> --
>> 2.47.3
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cdev: maintain partition index in struct cdev
2025-12-18 9:19 Ahmad Fatoum
@ 2025-12-18 9:29 ` Sascha Hauer
2025-12-18 9:30 ` Ahmad Fatoum
2025-12-18 9:37 ` Sascha Hauer
1 sibling, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2025-12-18 9:29 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Thu, Dec 18, 2025 at 10:19:45AM +0100, Ahmad Fatoum wrote:
> For use by the EFI loader, we will need to know a partition's number
> within the partition table on disk, so have the devfs-core keep track
> of that.
>
> Mere iteration over the cdev list doesn't work for thus purpose as there
> may be invalid PTEs, which cause e.g. the first on-disk partition to
> have a higher number.
>
> See 9dfffaf2ef47 ("partitions: efi: Continue partition enumeration on
> invalid pte") for more info. A real world example is the current
> debian-13-nocloud-arm64.raw image, which has two partitions:
> 0 and 14 (or 1 and 15 in barebox).
Should have mentioned this in my last mail, but isn't this the other way
round?
Sascja
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v2 -> v3:
> - fix comment to mention that index is 0-based (Sascha)j
> v1 -> v2:
> - record actual partition number from the table.
> I compared against EDK-II and Linux and both take the actual
> number, which may not be either the number in our cdev list
> or the location on disk.
> ---
> common/partitions.c | 1 +
> include/driver.h | 3 +++
> 2 files changed, 4 insertions(+)
>
> diff --git a/common/partitions.c b/common/partitions.c
> index 1a4e046c5f55..40f4c629e1ac 100644
> --- a/common/partitions.c
> +++ b/common/partitions.c
> @@ -52,6 +52,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
> goto out;
> }
>
> + cdev->partition_table_index = part->num;
> cdev->flags |= DEVFS_PARTITION_FROM_TABLE | part->flags;
> cdev->typeflags |= part->typeflags;
> cdev->typeuuid = part->typeuuid;
> diff --git a/include/driver.h b/include/driver.h
> index 14d1731fd976..77b9b876955a 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -436,6 +436,9 @@ struct cdev {
> loff_t size;
> unsigned int flags;
> u16 typeflags; /* GPT type-specific attributes */
> + s8 partition_table_index; /* For GPT/MBR-formatted disks only:
> + * 0-based index of partition on disk
> + */
> int open;
> struct mtd_info *mtd;
> struct list_head aliases;
> --
> 2.47.3
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] cdev: maintain partition index in struct cdev
@ 2025-12-18 9:19 Ahmad Fatoum
2025-12-18 9:29 ` Sascha Hauer
2025-12-18 9:37 ` Sascha Hauer
0 siblings, 2 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2025-12-18 9:19 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use by the EFI loader, we will need to know a partition's number
within the partition table on disk, so have the devfs-core keep track
of that.
Mere iteration over the cdev list doesn't work for thus purpose as there
may be invalid PTEs, which cause e.g. the first on-disk partition to
have a higher number.
See 9dfffaf2ef47 ("partitions: efi: Continue partition enumeration on
invalid pte") for more info. A real world example is the current
debian-13-nocloud-arm64.raw image, which has two partitions:
0 and 14 (or 1 and 15 in barebox).
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v2 -> v3:
- fix comment to mention that index is 0-based (Sascha)j
v1 -> v2:
- record actual partition number from the table.
I compared against EDK-II and Linux and both take the actual
number, which may not be either the number in our cdev list
or the location on disk.
---
common/partitions.c | 1 +
include/driver.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/common/partitions.c b/common/partitions.c
index 1a4e046c5f55..40f4c629e1ac 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -52,6 +52,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
goto out;
}
+ cdev->partition_table_index = part->num;
cdev->flags |= DEVFS_PARTITION_FROM_TABLE | part->flags;
cdev->typeflags |= part->typeflags;
cdev->typeuuid = part->typeuuid;
diff --git a/include/driver.h b/include/driver.h
index 14d1731fd976..77b9b876955a 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -436,6 +436,9 @@ struct cdev {
loff_t size;
unsigned int flags;
u16 typeflags; /* GPT type-specific attributes */
+ s8 partition_table_index; /* For GPT/MBR-formatted disks only:
+ * 0-based index of partition on disk
+ */
int open;
struct mtd_info *mtd;
struct list_head aliases;
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-18 9:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-11 20:42 [PATCH] cdev: maintain partition index in struct cdev Ahmad Fatoum
2025-12-18 9:19 Ahmad Fatoum
2025-12-18 9:29 ` Sascha Hauer
2025-12-18 9:30 ` Ahmad Fatoum
2025-12-18 9:38 ` Sascha Hauer
2025-12-18 9:37 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox