diff options
author | Christian Marangi <ansuelsmth@gmail.com> | 2024-10-03 00:11:41 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-10-22 08:14:56 -0600 |
commit | ba40f4c590f4c91119f3802ed501499709f583a9 (patch) | |
tree | c5f02222e92959a4e2fa7c433f3be0f16ebc6417 | |
parent | e3569ecae44daa6d88ac1bb0c6b976c298eff966 (diff) | |
download | lwn-ba40f4c590f4c91119f3802ed501499709f583a9.tar.gz lwn-ba40f4c590f4c91119f3802ed501499709f583a9.zip |
block: add support for defining read-only partitions
Add support for defining read-only partitions and complete support for
it in the cmdline partition parser as the additional "ro" after a
partition is scanned but never actually applied.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20241002221306.4403-2-ansuelsmth@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | block/blk.h | 1 | ||||
-rw-r--r-- | block/partitions/cmdline.c | 3 | ||||
-rw-r--r-- | block/partitions/core.c | 3 |
3 files changed, 7 insertions, 0 deletions
diff --git a/block/blk.h b/block/blk.h index ea926d685e92..8fddaf6eae49 100644 --- a/block/blk.h +++ b/block/blk.h @@ -547,6 +547,7 @@ void blk_free_ext_minor(unsigned int minor); #define ADDPART_FLAG_NONE 0 #define ADDPART_FLAG_RAID 1 #define ADDPART_FLAG_WHOLEDISK 2 +#define ADDPART_FLAG_READONLY 4 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, sector_t length); int bdev_del_partition(struct gendisk *disk, int partno); diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c index 152c85df92b2..da3e719d8e51 100644 --- a/block/partitions/cmdline.c +++ b/block/partitions/cmdline.c @@ -237,6 +237,9 @@ static int add_part(int slot, struct cmdline_subpart *subpart, put_partition(state, slot, subpart->from >> 9, subpart->size >> 9); + if (subpart->flags & PF_RDONLY) + state->parts[slot].flags |= ADDPART_FLAG_READONLY; + info = &state->parts[slot].info; strscpy(info->volname, subpart->name, sizeof(info->volname)); diff --git a/block/partitions/core.c b/block/partitions/core.c index 5bd7a603092e..629ed08b9ab9 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -373,6 +373,9 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, goto out_del; } + if (flags & ADDPART_FLAG_READONLY) + bdev_set_flag(bdev, BD_READ_ONLY); + /* everything is up and running, commence */ err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL); if (err) |