Skip to contentSkip to conversation

partitions: Align partition numbering with that of Linux kernel

PATCH In review Andrey Smirnov 2 participants 3 messages Feb 5, 2018 – Feb 16, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 partitions: Align partition numbering with that of Linux kernel

Change the way Barebox numbers DOS/EFI partitions, such that it would be consistent with how Linux kernel does it. With this change:

- Both types of partitions are numbered starting from 1, not 0

- Extended DOS partitions always start from 5, leaving first 4 to non-extended ones.

---
 common/partitions.c        | 7 +++----
 common/partitions/dos.c    | 2 ++
 common/partitions/efi.c    | 1 +
 common/partitions/parser.h | 1 +
 4 files changed, 7 insertions(+), 4 deletions(-)
common/partitions.c +3 -4
index 574b31fbb..53d55a49a 100644
@@ -42,8 +42,7 @@ static LIST_HEAD(partition_parser_list);
  * @param no Partition number
  * @return 0 on success
  */
-static int register_one_partition(struct block_device *blk,
-					struct partition *part, int no)
+static int register_one_partition(struct block_device *blk, struct partition *part)
 {
 	char *partition_name;
 	int ret;
@@ -51,7 +50,7 @@ static int register_one_partition(struct block_device *blk,
 	uint64_t size = part->size * SECTOR_SIZE;
 	struct cdev *cdev;
 
-	partition_name = basprintf("%s.%d", blk->cdev.name, no);
+	partition_name = basprintf("%s.%d", blk->cdev.name, part->number);
 	if (!partition_name)
 		return -ENOMEM;
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
@@ -150,7 +149,7 @@ int parse_partition_table(struct block_device *blk)
 
 	/* at least one partition description found */
 	for (i = 0; i < pdesc->used_entries; i++) {
-		rc = register_one_partition(blk, &pdesc->parts[i], i);
+		rc = register_one_partition(blk, &pdesc->parts[i]);
 		if (rc != 0)
 			dev_err(blk->dev,
 				"Failed to register partition %d on %s (%d)\n",
common/partitions/dos.c +2 -0
index 488c2936f..2ee9b2bd6 100644
@@ -170,6 +170,7 @@ static void dos_extended_partition(struct block_device *blk, struct partition_de
 			get_unaligned_le32(&table[0].partition_start);
 		pd->parts[n].size = get_unaligned_le32(&table[0].partition_size);
 		pd->parts[n].dos_partition_type = table[0].type;
+		pd->parts[n].number = partno;
 		if (signature)
 			sprintf(pd->parts[n].partuuid, "%08x-%02u",
 				signature, partno);
@@ -224,6 +225,7 @@ static void dos_partition(void *buf, struct block_device *blk,
 			pd->parts[n].first_sec = pentry.first_sec;
 			pd->parts[n].size = pentry.size;
 			pd->parts[n].dos_partition_type = pentry.dos_partition_type;
+			pd->parts[n].number = i + 1;
 			if (signature)
 				sprintf(pd->parts[n].partuuid, "%08x-%02d",
 						signature, i + 1);
common/partitions/efi.c +1 -0
index 88734f166..5dc9e1ad8 100644
@@ -456,6 +456,7 @@ static void efi_partition(void *buf, struct block_device *blk,
 		pentry = &pd->parts[pd->used_entries];
 		pentry->first_sec = le64_to_cpu(ptes[i].starting_lba);
 		pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
+		pentry->number = pd->used_entries + 1;
 		pentry->size++;
 		part_set_efi_name(&ptes[i], pentry->name);
 		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
common/partitions/parser.h +1 -0
index 8ad134a9a..713933794 100644
@@ -20,6 +20,7 @@ struct partition {
 	char partuuid[MAX_PARTUUID_STR];
 	uint64_t first_sec;
 	uint64_t size;
+	int number;
 };
 
 struct partition_desc {
Signature · 7 lines
2.14.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 8 lines · Andrey Smirnov

Change the way Barebox numbers DOS/EFI partitions, such that it would be consistent with how Linux kernel does it. With this change:

- Both types of partitions are numbered starting from 1, not 0

- Extended DOS partitions always start from 5, leaving first 4 to non-extended ones.

Sascha, any opinion on this patch?

Thanks,
Andrey Smirnov

Quoted 85 lines
---
 common/partitions.c        | 7 +++----
 common/partitions/dos.c    | 2 ++
 common/partitions/efi.c    | 1 +
 common/partitions/parser.h | 1 +
 4 files changed, 7 insertions(+), 4 deletions(-)
common/partitions.c +3 -4
index 574b31fbb..53d55a49a 100644
@@ -42,8 +42,7 @@ static LIST_HEAD(partition_parser_list);
  * @param no Partition number
  * @return 0 on success
  */
-static int register_one_partition(struct block_device *blk,
-                                       struct partition *part, int no)
+static int register_one_partition(struct block_device *blk, struct partition *part)
 {
        char *partition_name;
        int ret;
@@ -51,7 +50,7 @@ static int register_one_partition(struct block_device *blk,
        uint64_t size = part->size * SECTOR_SIZE;
        struct cdev *cdev;
 
-       partition_name = basprintf("%s.%d", blk->cdev.name, no);
+       partition_name = basprintf("%s.%d", blk->cdev.name, part->number);
        if (!partition_name)
                return -ENOMEM;
        dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
@@ -150,7 +149,7 @@ int parse_partition_table(struct block_device *blk)
 
        /* at least one partition description found */
        for (i = 0; i < pdesc->used_entries; i++) {
-               rc = register_one_partition(blk, &pdesc->parts[i], i);
+               rc = register_one_partition(blk, &pdesc->parts[i]);
                if (rc != 0)
                        dev_err(blk->dev,
                                "Failed to register partition %d on %s (%d)\n",
common/partitions/dos.c +2 -0
index 488c2936f..2ee9b2bd6 100644
@@ -170,6 +170,7 @@ static void dos_extended_partition(struct block_device *blk, struct partition_de
                        get_unaligned_le32(&table[0].partition_start);
                pd->parts[n].size = get_unaligned_le32(&table[0].partition_size);
                pd->parts[n].dos_partition_type = table[0].type;
+               pd->parts[n].number = partno;
                if (signature)
                        sprintf(pd->parts[n].partuuid, "%08x-%02u",
                                signature, partno);
@@ -224,6 +225,7 @@ static void dos_partition(void *buf, struct block_device *blk,
                        pd->parts[n].first_sec = pentry.first_sec;
                        pd->parts[n].size = pentry.size;
                        pd->parts[n].dos_partition_type = pentry.dos_partition_type;
+                       pd->parts[n].number = i + 1;
                        if (signature)
                                sprintf(pd->parts[n].partuuid, "%08x-%02d",
                                                signature, i + 1);
common/partitions/efi.c +1 -0
index 88734f166..5dc9e1ad8 100644
@@ -456,6 +456,7 @@ static void efi_partition(void *buf, struct block_device *blk,
                pentry = &pd->parts[pd->used_entries];
                pentry->first_sec = le64_to_cpu(ptes[i].starting_lba);
                pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
+               pentry->number = pd->used_entries + 1;
                pentry->size++;
                part_set_efi_name(&ptes[i], pentry->name);
                snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
common/partitions/parser.h +1 -1
index 8ad134a9a..713933794 100644
@@ -20,6 +20,7 @@ struct partition {
        char partuuid[MAX_PARTUUID_STR];
        uint64_t first_sec;
        uint64_t size;
+       int number;
 };
 
 struct partition_desc {
--
Quoted 2 lines

2.14.3

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
In reply to Andrey Smirnov

Hi Andrey,

Quoted 7 lines · Andrey Smirnov

Change the way Barebox numbers DOS/EFI partitions, such that it would be consistent with how Linux kernel does it. With this change:

- Both types of partitions are numbered starting from 1, not 0

- Extended DOS partitions always start from 5, leaving first 4 to non-extended ones.

I am not very happy with this change because it breaks boards expecting a certain numbering. See for example:

arch/arm/mach-omap/omap_generic.c:116:static char *envpath = "/mnt/mmc0.0/barebox.env"; arch/arm/boards/phytec-som-am335x/defaultenv-physom-am335x/boot/mmc:3:global.bootm.image=/mnt/mmc0.0/linuximage arch/arm/boards/embedsky-e9/defaultenv-e9/boot/mmc1:3:mount /dev/mmc1.0

There are more examples in-tree and for sure more out of tree.

We need very strong reasons to change this numbering.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox