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 <[email protected]>
---
 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 via email to