From patchwork Mon Apr 2 08:20:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10319475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE83360532 for ; Mon, 2 Apr 2018 08:20:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE79928A00 for ; Mon, 2 Apr 2018 08:20:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D041928C02; Mon, 2 Apr 2018 08:20:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3337728A00 for ; Mon, 2 Apr 2018 08:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/+K5RH+xrCPF4GRzPXxN7/hueSl3Syfnf1MPgCEA5DY=; b=mUsEnZ3GMa6PD/ SD9uQzx9rjCRsy04X+iF/xk/QG+qa4t5EpGhKPqvRY83UI9fcBZdmGdvt8/maGhBmhjLKJ4EBroHJ y+yb0YZQ4PdV3v7nS49nnQr5AFSCuusOPkA3aplAm9qrqCRLLinf2DeUfMwQdyNL/b2Ki5XOayfYV ED0s8kEWG0xMOctqo86VzJgi8bR2+IU87xZLOvzH6ZUfYf2cbUZ7cgh8BGe+rOyLbK0EWGJZoPC9R 2lpL3M+tLsipb8gCVBmEZD14+8WSBBzNGBNaorPF/vrqW85MHTlx4ONZxlRLZJilMyhDk5ekosTzL yz9m4nBYFELaLX7gc1hQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f2uhv-00040P-RB; Mon, 02 Apr 2018 08:20:51 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f2uhd-0003mo-Ik; Mon, 02 Apr 2018 08:20:35 +0000 X-UUID: 92027ea557ad4611aab9a1652fcbcccf-20180402 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 432858587; Mon, 02 Apr 2018 16:20:15 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 2 Apr 2018 16:20:13 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Mon, 2 Apr 2018 16:20:13 +0800 From: Xiaolei Li To: , Subject: [PATCH] mtd: Add sysfs attribute for mtd OOB available size Date: Mon, 2 Apr 2018 16:20:10 +0800 Message-ID: <1522657210-56833-2-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1522657210-56833-1-git-send-email-xiaolei.li@mediatek.com> References: <1522657210-56833-1-git-send-email-xiaolei.li@mediatek.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.5.0.5042-8.2.9001-23758.005 X-TM-AS-Result: No-8.683000-8.000000-10 X-TMASE-MatchedRID: MdSdJxe5grj1nyrqs74iHjTR2TFg0xG3FuNF4lJG6xss/uUAk6xP7GlF 7OhYLlctJKxrZGiKDPjr5CQRYN7wnK6EIEWX9vresK+WWVTsOXVA2uBGtrFNAUYvSDWdWaRhU8j ll7wo+otRUHsj/YINIBnlPjt/L4AXGAdnzrnkM48URSScn+QSXt0H8LFZNFG73Yq8RVaZivVygd Yw8EJB6WX39sgiVJj9QnE12cWlg07DGzi+iBC6cQSv8TR3PQKZ X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.683000-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23758.005 X-TMASE-POSTMAN: 2-d; X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180402_012033_747888_30F00B0C X-CRM114-Status: UNSURE ( 8.20 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, xiaolei.li@mediatek.com, linux-mtd@lists.infradead.org, srv_heupstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Expose mtd OOB available size by sysfs file. Then users can get available OOB size by accessing /sys/class/mtd/mtdX/oobavail. Signed-off-by: Xiaolei Li --- Documentation/ABI/testing/sysfs-class-mtd | 8 ++++++++ drivers/mtd/mtdcore.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd index f34e5923..3bc7c0a 100644 --- a/Documentation/ABI/testing/sysfs-class-mtd +++ b/Documentation/ABI/testing/sysfs-class-mtd @@ -232,3 +232,11 @@ Description: of the parent (another partition or a flash device) in bytes. This attribute is absent on flash devices, so it can be used to distinguish them from partitions. + +What: /sys/class/mtd/mtdX/oobavail +Date: April 2018 +KernelVersion: 4.16 +Contact: linux-mtd@lists.infradead.org +Description: + Number of bytes available for a client to place data into + the out of band area. diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 807d17d..99d9352 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -210,6 +210,15 @@ static ssize_t mtd_oobsize_show(struct device *dev, } static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL); +static ssize_t mtd_oobavail_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mtd_info *mtd = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobavail); +} +static DEVICE_ATTR(oobavail, S_IRUGO, mtd_oobavail_show, NULL); + static ssize_t mtd_numeraseregions_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -327,6 +336,7 @@ static ssize_t mtd_bbtblocks_show(struct device *dev, &dev_attr_writesize.attr, &dev_attr_subpagesize.attr, &dev_attr_oobsize.attr, + &dev_attr_oobavail.attr, &dev_attr_numeraseregions.attr, &dev_attr_name.attr, &dev_attr_ecc_strength.attr,