]> www.infradead.org Git - users/hch/misc.git/commitdiff
block: add support for defining read-only partitions
authorChristian Marangi <ansuelsmth@gmail.com>
Wed, 2 Oct 2024 22:11:41 +0000 (00:11 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 22 Oct 2024 14:14:56 +0000 (08:14 -0600)
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>
block/blk.h
block/partitions/cmdline.c
block/partitions/core.c

index ea926d685e92e7bc34ad61e1568f2dce8ac53b73..8fddaf6eae49da23921ad0851a4ade2341b9ff31 100644 (file)
@@ -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);
index 152c85df92b20e0c090988aafd70588c379f775f..da3e719d8e51e212bb946a07c1273970619d5bb2 100644 (file)
@@ -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));
index 5bd7a603092ea9c0ea9087cb1cf7d6e0aa1a1e27..629ed08b9ab9cab90d3c9b4f0d2b4f299786074a 100644 (file)
@@ -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)