mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] cdev: maintain partition index in struct cdev
Date: Thu, 11 Dec 2025 21:42:32 +0100	[thread overview]
Message-ID: <20251211204233.2594385-1-a.fatoum@pengutronix.de> (raw)

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




                 reply	other threads:[~2025-12-11 20:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20251211204233.2594385-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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