From patchwork Wed Mar 4 03:12:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Light Hsieh X-Patchwork-Id: 11419243 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53B01921 for ; Wed, 4 Mar 2020 03:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2718C214D8 for ; Wed, 4 Mar 2020 03:12:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="mzDV54eH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387432AbgCDDM3 (ORCPT ); Tue, 3 Mar 2020 22:12:29 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:38104 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2387609AbgCDDM2 (ORCPT ); Tue, 3 Mar 2020 22:12:28 -0500 X-UUID: 826440239e364b029ea484cf06901dcf-20200304 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=7FGKC2CL96iktvyoBP2vbwLVT6EXR3CbHjrpB2EcLgw=; b=mzDV54eHbuWv4VhGtBiswDYgZSb8SEZVa6dtiWBj3/ddQrO+9b06Dm0Qe+3Y6d6Hto4hHPV9vDTm/Pnol/wpCpFqO39KiA/pvFNc9nhr8CKBl2st8ikQSSBoA5AbTE53zvR+mzGuJqk9QiKCma7db6IWmx2ZB+5wpJ3QazydLA8=; X-UUID: 826440239e364b029ea484cf06901dcf-20200304 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1444323461; Wed, 04 Mar 2020 11:12:20 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 4 Mar 2020 11:11:18 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 4 Mar 2020 11:09:47 +0800 From: To: CC: , , , , , , Light Hsieh Subject: [RESEND PATCH v1 3/3] block: set partition read/write policy according to write-protection status Date: Wed, 4 Mar 2020 11:12:17 +0800 Message-ID: <1583291537-15053-4-git-send-email-light.hsieh@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1583291537-15053-1-git-send-email-light.hsieh@mediatek.com> References: <1583291537-15053-1-git-send-email-light.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Light Hsieh For storage device with write-protection support, e.g. eMMC, register check_disk_range_wp() in struct block_device_operations for checking write-protection status. When creating block device for a partition, set read/write policy according to result of check_disk_range_wp() operation (if registered). Without this patch, ro attribute is not set for created block device of write-protected partition. User perform asynchronous buffered write to such partition won't get immediate error and therefore he won't be awared that write is not actually performed. With this patch, ro attribute is set for created block device of write-protected partition. User perform asynchronous buffered write to such partition will get immediate error and therefore he will be awared. Signed-off-by: Light Hsieh --- block/partition-generic.c | 10 ++++++++++ drivers/mmc/core/block.c | 1 + include/linux/blkdev.h | 1 + 3 files changed, 12 insertions(+) diff --git a/block/partition-generic.c b/block/partition-generic.c index 564fae7..69088e8 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -394,6 +394,16 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, goto out_free_info; pdev->devt = devt; + if (!p->policy) { + if (disk->fops->check_disk_range_wp) { + err = disk->fops->check_disk_range_wp(disk, start, len); + if (err > 0) + p->policy = 1; + else if (err != 0) + goto out_free_info; + } + } + /* delay uevent until 'holders' subdir is created */ dev_set_uevent_suppress(pdev, 1); err = device_add(pdev); diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index ee85abf..af81311 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1047,6 +1047,7 @@ static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, #ifdef CONFIG_COMPAT .compat_ioctl = mmc_blk_compat_ioctl, #endif + .check_disk_range_wp = mmc_blk_check_disk_range_wp, }; static int mmc_blk_part_switch_pre(struct mmc_card *card, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 053ea4b..7814290 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1707,6 +1707,7 @@ struct block_device_operations { void (*swap_slot_free_notify) (struct block_device *, unsigned long); int (*report_zones)(struct gendisk *, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); + int (*check_disk_range_wp)(struct gendisk *d, sector_t s, sector_t l); struct module *owner; const struct pr_ops *pr_ops; };