[PATCH 1/2] partitions: UUID was missing from partitions by name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux