mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] partitions: UUID was missing from partitions by name
@ 2015-12-09 21:55 Trent Piepho
  2015-12-09 22:04 ` [PATCH 2/2] partitions/efi: Add partuuid to partition description Trent Piepho
  2015-12-10  8:00 ` [PATCH 1/2] partitions: UUID was missing from partitions by name Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Trent Piepho @ 2015-12-09 21:55 UTC (permalink / raw)
  To: barebox

The partition code registers one or two cdevs for each partition.  The
2nd one is used if the partition has a name.  The block of code for
each cdev is duplicated twice, and the 2nd copy is missing the bit
that copies the partition uuid and the dos partition type to the cdev.

Refactor the register cdev out to a new function that is called twice.
This way each cdev is done correctly.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 common/partitions.c | 70 +++++++++++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/common/partitions.c b/common/partitions.c
index 4f50bfe..9e54355 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -36,57 +36,63 @@
 static LIST_HEAD(partition_parser_list);
 
 /**
- * Register one partition on the given block device
+ * Register a cdev for given partition.  One partition
+ * can have multiple (1-2) cdev's associated with it.
  * @param blk Block device to register to
  * @param part Partition description
- * @param no Partition number
- * @return 0 on success
+ * @param partition_name Name for cdev (NULL is checked for)
+ * @param start Offset of partition start (bytes)
+ * @param size Partition size (bytes)
  */
-static int register_one_partition(struct block_device *blk,
-					struct partition *part, int no)
+static int register_partition_cdev(struct block_device *blk,
+				   const struct partition *part,
+				   const char *partition_name,
+				   uint64_t start, uint64_t size)
 {
-	char *partition_name;
-	int ret;
-	uint64_t start = part->first_sec * SECTOR_SIZE;
-	uint64_t size = part->size * SECTOR_SIZE;
 	struct cdev *cdev;
 
-	partition_name = asprintf("%s.%d", blk->cdev.name, no);
 	if (!partition_name)
 		return -ENOMEM;
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
 				partition_name, blk->cdev.name);
 	cdev = devfs_add_partition(blk->cdev.name,
-				start, size, 0, partition_name);
-	if (IS_ERR(cdev)) {
-		ret = PTR_ERR(cdev);
-		goto out;
-	}
+				   start, size, 0, partition_name);
+	if (IS_ERR(cdev))
+		return PTR_ERR(cdev);
 
 	cdev->dos_partition_type = part->dos_partition_type;
 	strcpy(cdev->partuuid, part->partuuid);
 
-	free(partition_name);
-
-	if (!part->name[0])
-		return 0;
+	return 0;
+}
 
-	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
-	if (!partition_name)
-		return -ENOMEM;
+/**
+ * Register one partition on the given block device
+ * @param blk Block device to register to
+ * @param part Partition description
+ * @param no Partition number
+ * @return 0 on success
+ */
+static int register_one_partition(struct block_device *blk,
+					struct partition *part, int no)
+{
+	char *partition_name;
+	int ret;
+	uint64_t start = part->first_sec * SECTOR_SIZE;
+	uint64_t size = part->size * SECTOR_SIZE;
 
-	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
-				partition_name, blk->cdev.name);
-	cdev = devfs_add_partition(blk->cdev.name,
-				start, size, 0, partition_name);
+	/* Make device with partition number */
+	partition_name = asprintf("%s.%d", blk->cdev.name, no);
+	ret = register_partition_cdev(blk, part, partition_name, start, size);
+	free(partition_name);
 
-	if (IS_ERR(cdev))
-		dev_warn(blk->dev, "Registering partition %s on drive %s failed\n",
-				partition_name, blk->cdev.name);
+	/* If that worked, try to register with the part name too */
+	if (!ret && part->name[0]) {
+		partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+		ret = register_partition_cdev(blk, part, partition_name, start, size);
+		free(partition_name);
+	}
 
-	ret = 0;
-out:
-	free(partition_name);
 	return ret;
 }
 
-- 
1.8.3.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] partitions/efi: Add partuuid to partition description
  2015-12-09 21:55 [PATCH 1/2] partitions: UUID was missing from partitions by name Trent Piepho
@ 2015-12-09 22:04 ` Trent Piepho
  2015-12-09 23:38   ` [PATCH 2/2 v2] " Trent Piepho
  2015-12-10  8:00 ` [PATCH 1/2] partitions: UUID was missing from partitions by name Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Trent Piepho @ 2015-12-09 22:04 UTC (permalink / raw)
  To: barebox

In commit bc31d85c6e23d724664e76bcfc3b2eda778012a3 the partition UUID
was added to the partition struct and thence to the cdev(s) for the
partition.  But just for DOS partitions.  Do this for GPT aka EFI
partitions too.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 common/partitions/Kconfig | 1 +
 common/partitions/efi.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/partitions/Kconfig b/common/partitions/Kconfig
index 90238ad..be9405a 100644
--- a/common/partitions/Kconfig
+++ b/common/partitions/Kconfig
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS
 config PARTITION_DISK_EFI
 	depends on PARTITION_DISK
 	select CRC32
+	select PRINTF_UUID
 	bool "EFI: GPT partition support"
 	help
 	  Add support to handle partitions in GUID Partition Table style.
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 61abf00..061f7b4 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk,
 		pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
 		pentry->size++;
 		part_set_efi_name(&ptes[i], pentry->name);
+		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pU", &ptes[i].unique_partition_guid);
 		pd->used_entries++;
 	}
 
-- 
1.8.3.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2 v2] partitions/efi: Add partuuid to partition description
  2015-12-09 22:04 ` [PATCH 2/2] partitions/efi: Add partuuid to partition description Trent Piepho
@ 2015-12-09 23:38   ` Trent Piepho
  0 siblings, 0 replies; 4+ messages in thread
From: Trent Piepho @ 2015-12-09 23:38 UTC (permalink / raw)
  To: barebox

In commit bc31d85c6e23d724664e76bcfc3b2eda778012a3 the partition UUID
was added to the partition struct and thence to the cdev(s) for the
partition.  But just for DOS partitions.  Do this for GPT aka EFI
partitions too.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
Changes from v1:
  Turns out the default is to print the UUID in big-endian format
  but the kernel and everyone else uses little-endian for GPT UUIDs.

 common/partitions/Kconfig | 1 +
 common/partitions/efi.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/partitions/Kconfig b/common/partitions/Kconfig
index 90238ad..be9405a 100644
--- a/common/partitions/Kconfig
+++ b/common/partitions/Kconfig
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS
 config PARTITION_DISK_EFI
 	depends on PARTITION_DISK
 	select CRC32
+	select PRINTF_UUID
 	bool "EFI: GPT partition support"
 	help
 	  Add support to handle partitions in GUID Partition Table style.
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 61abf00..a9945dd 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk,
 		pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
 		pentry->size++;
 		part_set_efi_name(&ptes[i], pentry->name);
+		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
 		pd->used_entries++;
 	}
 
-- 
1.8.3.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] partitions: UUID was missing from partitions by name
  2015-12-09 21:55 [PATCH 1/2] partitions: UUID was missing from partitions by name Trent Piepho
  2015-12-09 22:04 ` [PATCH 2/2] partitions/efi: Add partuuid to partition description Trent Piepho
@ 2015-12-10  8:00 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-12-10  8:00 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Wed, Dec 09, 2015 at 09:55:29PM +0000, Trent Piepho wrote:
> The partition code registers one or two cdevs for each partition.  The
> 2nd one is used if the partition has a name.  The block of code for
> each cdev is duplicated twice, and the 2nd copy is missing the bit
> that copies the partition uuid and the dos partition type to the cdev.
> 
> Refactor the register cdev out to a new function that is called twice.
> This way each cdev is done correctly.

Nice. Besides of fixing a bug this makes intention of the code is much
clearer. Thanks, applied.

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-10  8:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-09 21:55 [PATCH 1/2] partitions: UUID was missing from partitions by name Trent Piepho
2015-12-09 22:04 ` [PATCH 2/2] partitions/efi: Add partuuid to partition description Trent Piepho
2015-12-09 23:38   ` [PATCH 2/2 v2] " Trent Piepho
2015-12-10  8:00 ` [PATCH 1/2] partitions: UUID was missing from partitions by name Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox