All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 3/4] blkdev: add function to add named read-only partitions
Date: Thu, 17 Nov 2022 00:44:40 +0000	[thread overview]
Message-ID: <2015e6097f7166915d829740ff33aab506948a0a.1668644705.git.daniel@makrotopia.org> (raw)
In-Reply-To: <cover.1668644705.git.daniel@makrotopia.org>

Add function bdev_add_partition_ro() which can be used by drivers to
register named read-only partitions on a disk device.
Unlike the existing bdev_add_partition() function, there is also no
check for overlapping partitions.
This new function is going to be used by the uImage.FIT parser.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 block/partitions/core.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/blkdev.h  |  7 +++++++
 2 files changed, 41 insertions(+)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index 355646b0707d..060a6585a387 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -469,6 +469,40 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
 	return ret;
 }
 
+int bdev_add_partition_ro(struct gendisk *disk, int partno, sector_t start,
+			  sector_t length, const char *volname)
+{
+	struct block_device *part;
+	struct partition_meta_info *info;
+	int ret;
+
+	mutex_lock(&disk->open_mutex);
+	if (!disk_live(disk)) {
+		ret = -ENXIO;
+		goto out;
+	}
+
+	part = add_partition(disk, partno, start, length,
+			     ADDPART_FLAG_READONLY, NULL);
+	ret = PTR_ERR_OR_ZERO(part);
+	if (ret)
+		goto out;
+
+	if (volname) {
+		info = kzalloc(sizeof(struct partition_meta_info), GFP_KERNEL);
+		if (!info) {
+			ret = -ENOMEM;
+			goto out;
+		}
+		strscpy(info->volname, volname, sizeof(info->volname));
+		part->bd_meta_info = info;
+	}
+out:
+	mutex_unlock(&disk->open_mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(bdev_add_partition_ro);
+
 int bdev_del_partition(struct gendisk *disk, int partno)
 {
 	struct block_device *part = NULL;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b45cdcdccc6d..6e468a2fc4ec 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1504,6 +1504,8 @@ int sync_blockdev_nowait(struct block_device *bdev);
 void sync_bdevs(bool wait);
 void bdev_statx_dioalign(struct inode *inode, struct kstat *stat);
 void printk_all_partitions(void);
+int bdev_add_partition_ro(struct gendisk *disk, int partno, sector_t start,
+			  sector_t length, const char *volname);
 #else
 static inline dev_t devt_from_partuuid(const char *uuid_str, int *root_wait)
 {
@@ -1537,6 +1539,11 @@ static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)
 static inline void printk_all_partitions(void)
 {
 }
+static inline int bdev_add_partition_ro(struct gendisk *disk, int partno, sector_t start,
+			  sector_t length, const char *volname)
+{
+	return 0;
+}
 #endif /* CONFIG_BLOCK */
 
 int fsync_bdev(struct block_device *bdev);
-- 
2.38.1


  parent reply	other threads:[~2022-11-17  0:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17  0:42 [RFC PATCH 0/4] block: uImage.FIT filesystem image mapper Daniel Golle
2022-11-17  0:42 ` [RFC PATCH 1/4] init: move block device helpers from init/do_mounts.c Daniel Golle
2022-11-17  5:55   ` Christoph Hellwig
2022-11-19 16:03     ` Daniel Golle
2022-11-22 12:37       ` Christoph Hellwig
2022-12-09 17:00         ` Daniel Golle
2022-12-12  9:03           ` Christoph Hellwig
2022-12-12 11:02             ` Daniel Golle
2022-12-13  6:48               ` Christoph Hellwig
2022-12-13 12:45                 ` Daniel Golle
2022-12-14 16:43                   ` Christoph Hellwig
2022-12-14 20:01                     ` Daniel Golle
2022-12-15  8:09                       ` Christoph Hellwig
2023-03-30 14:43         ` Daniel Golle
2022-11-17  0:43 ` [RFC PATCH 2/4] block: add new flag to add partitions read-only Daniel Golle
2022-11-17  0:44 ` Daniel Golle [this message]
2022-11-17  5:56   ` [RFC PATCH 3/4] blkdev: add function to add named read-only partitions Christoph Hellwig
2022-11-17 17:12     ` Daniel Golle
2022-11-17  0:45 ` [RFC PATCH 4/4] block: add uImage.FIT block partition driver Daniel Golle
2022-11-17  5:58   ` Christoph Hellwig

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=2015e6097f7166915d829740ff33aab506948a0a.1668644705.git.daniel@makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.