fabf16a2e631359d0cbed0995c592211f15e2d89
[openwrt/staging/wigyori.git] /
1 From 03cb793b26834ddca170ba87057c8f883772dd45 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 3 Oct 2024 00:11:41 +0200
4 Subject: [PATCH 1/5] block: add support for defining read-only partitions
5
6 Add support for defining read-only partitions and complete support for
7 it in the cmdline partition parser as the additional "ro" after a
8 partition is scanned but never actually applied.
9
10 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 Reviewed-by: Christoph Hellwig <hch@lst.de>
12 Link: https://lore.kernel.org/r/20241002221306.4403-2-ansuelsmth@gmail.com
13 Signed-off-by: Jens Axboe <axboe@kernel.dk>
14 ---
15 block/blk.h | 1 +
16 block/partitions/cmdline.c | 3 +++
17 block/partitions/core.c | 3 +++
18 3 files changed, 7 insertions(+)
19
20 --- a/block/blk.h
21 +++ b/block/blk.h
22 @@ -424,6 +424,7 @@ void blk_free_ext_minor(unsigned int min
23 #define ADDPART_FLAG_NONE 0
24 #define ADDPART_FLAG_RAID 1
25 #define ADDPART_FLAG_WHOLEDISK 2
26 +#define ADDPART_FLAG_READONLY 4
27 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
28 sector_t length);
29 int bdev_del_partition(struct gendisk *disk, int partno);
30 --- a/block/partitions/cmdline.c
31 +++ b/block/partitions/cmdline.c
32 @@ -237,6 +237,9 @@ static int add_part(int slot, struct cmd
33 put_partition(state, slot, subpart->from >> 9,
34 subpart->size >> 9);
35
36 + if (subpart->flags & PF_RDONLY)
37 + state->parts[slot].flags |= ADDPART_FLAG_READONLY;
38 +
39 info = &state->parts[slot].info;
40
41 strscpy(info->volname, subpart->name, sizeof(info->volname));
42 --- a/block/partitions/core.c
43 +++ b/block/partitions/core.c
44 @@ -392,6 +392,9 @@ static struct block_device *add_partitio
45 goto out_del;
46 }
47
48 + if (flags & ADDPART_FLAG_READONLY)
49 + bdev->bd_read_only = true;
50 +
51 /* everything is up and running, commence */
52 err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
53 if (err)