From patchwork Thu Nov 17 00:44:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 21357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp143176wrr; Wed, 16 Nov 2022 16:47:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf5BFKbmbkkfGGW6xiq0BN/b+8E+4qW94JGNvfpmsXt7eed698hVw2g8b/6FGF2PX+rDpsTJ X-Received: by 2002:aa7:8c50:0:b0:538:17f5:64e8 with SMTP id e16-20020aa78c50000000b0053817f564e8mr653038pfd.11.1668646070432; Wed, 16 Nov 2022 16:47:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668646070; cv=none; d=google.com; s=arc-20160816; b=DPZYT3YaSyiCKlcDkL0AopzVDJ0y4AEeZf/NU6qI10wmyw6MGkNp+kzs7WbgsYy6pF A+31Da2iSLzwpDpg9MxDThaRAUxkpxINg/bHFaAbiBDu40fW5laS2CU8+/qNQlEmNHnI A7ErhvlImeCdXpQSzQQBI01h8Tvs7gjG2OZFq9fTnacx8rAeQknlaKA7cKfKtYKgTUxO GS9G8VXZxobArSLSU712VXa2mzjwumEYGaQh+tj43wEuwAmM8rMaC7aWLs15qMFJYf6K 823Owae29SMU3pmje7mqg2XWRHGl/tST5FWUhli+OtY5OlcnFmFJecslhV1oQnXZUrHF mvPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=xA3V1TkReex71UuclY9reVPqQ9gZrUu/6oG40IQNr9g=; b=d2nqpdJhhkgb/Pc9GBqEB760m+6aEcW55xaDmHW2f6gKYW8YekJSiX/JuFq9O46LL8 wlsBfzphhubj5yR/m772Jhis7dvrjXNsAGCWewJ19+k8ifBTDx4s+dQLQP8772vbYkGB FzRTVxyd2S0pOnrJPZDPp1IFIaFG2q1oo3ioeh2buQrqhJ35MCeImUcX7dpvxhCR7Tgp H/ZHuq0nzG3zzt6qJmYzgXFwBZuTTvOkdcMYfmUVVMJ/RWQpGb8acfbF2vXM7Ch7CBkP oXHi91OJ53yRQymT8AZRCtcZpISAaJl+8qJTEUyyd268HtsCVGGWYmTzVXEIdIG3QFrp frMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu1-20020a17090b1b0100b00202fd098892si3635348pjb.190.2022.11.16.16.47.36; Wed, 16 Nov 2022 16:47:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238529AbiKQApy (ORCPT + 99 others); Wed, 16 Nov 2022 19:45:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238401AbiKQAp1 (ORCPT ); Wed, 16 Nov 2022 19:45:27 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F906CA3B; Wed, 16 Nov 2022 16:44:54 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1ovT1K-0002WL-6H; Thu, 17 Nov 2022 01:44:46 +0100 Date: Thu, 17 Nov 2022 00:44:40 +0000 From: Daniel Golle To: Christoph Hellwig , Jens Axboe , "Martin K. Petersen" , Chaitanya Kulkarni , Wolfram Sang , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/4] blkdev: add function to add named read-only partitions Message-ID: <2015e6097f7166915d829740ff33aab506948a0a.1668644705.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749702222262759809?= X-GMAIL-MSGID: =?utf-8?q?1749702222262759809?= 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 --- 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);