mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@kymetacorp.com>
To: barebox <barebox@lists.infradead.org>
Subject: [PATCH 1/2] partitions: UUID was missing from partitions by name
Date: Wed, 9 Dec 2015 21:55:29 +0000	[thread overview]
Message-ID: <1449698135.26955.58.camel@rtred1test09.kymeta.local> (raw)

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

             reply	other threads:[~2015-12-09 21:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-09 21:55 Trent Piepho [this message]
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

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=1449698135.26955.58.camel@rtred1test09.kymeta.local \
    --to=tpiepho@kymetacorp.com \
    --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