From patchwork Mon Apr 9 03:10:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10330101 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 36F5E6022E for ; Mon, 9 Apr 2018 03:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 270B02898E for ; Mon, 9 Apr 2018 03:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1937828996; Mon, 9 Apr 2018 03:11:41 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, 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 E8FC62898E for ; Mon, 9 Apr 2018 03:11:39 +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=M6VGg773cLZM7i0hioym0LaFgNPFtKZjyat8c3lyPMY=; b=JtQQ5e7R3ebfvg vxETqWPqZYx+zLMSj9XKPWrYGD+9cvmBWS9HFqJJewUbB/QiJWFWdpVsku8zpI2ThVnf+a48tmlha kf/szSfJVB8IR5gtgEOe87+/mPNvOTCw1RhgyV3VAZBQugZ9pQrRAjQtgOw+RvtsIxptSKssWuxqi RQ+NQyXOUQ6AF2G7IoJqEMgKGqZAi4z9g6avhWhCIyBvZLIPxcyncSFBP3voNCAzNp0P1s5jJJ8Ez Qs8buGj2iWPMUjQY2RD0asWhd5dR9xluswIW9Ol6RS9q7a3rN+E6/sZQMn+2vOdxcU2NMnwo53w8h qFhwqh91KK+RLr4CmU9A==; 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 1f5NDV-0006Q6-Af; Mon, 09 Apr 2018 03:11:37 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5NDB-0005kJ-OT; Mon, 09 Apr 2018 03:11:19 +0000 X-UUID: 29861722134a422a81df3f5d7f776139-20180409 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1611400085; Mon, 09 Apr 2018 11:10:17 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 9 Apr 2018 11:10:17 +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, 9 Apr 2018 11:10:16 +0800 From: Xiaolei Li To: , Subject: [PATCH 1/2] libmtd: Add support to access OOB available size Date: Mon, 9 Apr 2018 11:10:09 +0800 Message-ID: <1523243410-65424-2-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523243410-65424-1-git-send-email-xiaolei.li@mediatek.com> References: <1523243410-65424-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-23772.004 X-TM-AS-Result: No-10.310100-8.000000-10 X-TMASE-MatchedRID: GA0hUCQRxNT1nyrqs74iHjTR2TFg0xG3sEf8CpnIYtkR34ro7k23nXbk pdDhAgYm09NQNrxIpFYa7rkdR+2D46v08M2153e5hrs6JAEL1u7lNvCpVWkX4+BvxYFhNwdMIw6 4a0XgvUTbcEjshLePR+YKfye+AbdNFxyzzffqvHmQOktEo73GFObVJDm0C8mjBsURHqz/t+09SO VV9xbHPuLzNWBegCW2wgn7iDBesS3CttcwYNipX/UrOTjR0Rj1X6P8psKTEvFZdVKufZg8Kya8k y3x5m9WUOoAcsYbzIU= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--10.310100-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23772.004 X-TMASE-POSTMAN: 2-d; X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180408_201118_058286_59A27F05 X-CRM114-Status: UNSURE ( 8.89 ) 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 Fetch OOB available size by accessing /sys/class/mtd/mtdX/oobavail. Signed-off-by: Xiaolei Li --- This patch depends on the reviewing patch "mtd: Add sysfs attribute for mtd OOB available size"[1]. [1] https://patchwork.kernel.org/patch/10319475/ --- include/libmtd.h | 2 ++ lib/libmtd.c | 7 +++++++ lib/libmtd_int.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/include/libmtd.h b/include/libmtd.h index db85fb4..cc24af8 100644 --- a/include/libmtd.h +++ b/include/libmtd.h @@ -66,6 +66,7 @@ struct mtd_info * @min_io_size: minimum input/output unit size * @subpage_size: sub-page size * @oob_size: OOB size (zero if the device does not have OOB area) + * @oobavail: free OOB size * @region_cnt: count of additional erase regions * @writable: zero if the device is read-only * @bb_allowed: non-zero if the MTD device may have bad eraseblocks @@ -84,6 +85,7 @@ struct mtd_dev_info int min_io_size; int subpage_size; int oob_size; + int oobavail; int region_cnt; unsigned int writable:1; unsigned int bb_allowed:1; diff --git a/lib/libmtd.c b/lib/libmtd.c index 86c89ae..76a9439 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -614,6 +614,10 @@ libmtd_t libmtd_open(void) if (!lib->mtd_oob_size) goto out_error; + lib->mtd_oobavail = mkpath(lib->mtd, MTD_OOBAVAIL); + if (!lib->mtd_oobavail) + goto out_error; + lib->mtd_region_cnt = mkpath(lib->mtd, MTD_REGION_CNT); if (!lib->mtd_region_cnt) goto out_error; @@ -637,6 +641,7 @@ void libmtd_close(libmtd_t desc) free(lib->mtd_flags); free(lib->mtd_region_cnt); free(lib->mtd_oob_size); + free(lib->mtd_oobavail); free(lib->mtd_subpage_size); free(lib->mtd_min_io_size); free(lib->mtd_size); @@ -769,6 +774,8 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd) return -1; if (dev_read_pos_int(lib->mtd_oob_size, mtd_num, &mtd->oob_size)) return -1; + if (dev_read_pos_int(lib->mtd_oobavail, mtd_num, &mtd->oobavail)) + return -1; if (dev_read_pos_int(lib->mtd_region_cnt, mtd_num, &mtd->region_cnt)) return -1; if (dev_read_hex_int(lib->mtd_flags, mtd_num, &ret)) diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h index 03b0863..3cab32b 100644 --- a/lib/libmtd_int.h +++ b/lib/libmtd_int.h @@ -44,6 +44,7 @@ extern "C" { #define MTD_MIN_IO_SIZE "writesize" #define MTD_SUBPAGE_SIZE "subpagesize" #define MTD_OOB_SIZE "oobsize" +#define MTD_OOBAVAIL "oobavail" #define MTD_REGION_CNT "numeraseregions" #define MTD_FLAGS "flags" @@ -63,6 +64,7 @@ extern "C" { * @mtd_min_io_size: minimum I/O unit size file pattern * @mtd_subpage_size: sub-page size file pattern * @mtd_oob_size: MTD device OOB size file pattern + * @mtd_oobavail: MTD device free OOB size file pattern * @mtd_region_cnt: count of additional erase regions file pattern * @mtd_flags: MTD device flags file pattern * @sysfs_supported: non-zero if sysfs is supported by MTD @@ -92,6 +94,7 @@ struct libmtd char *mtd_min_io_size; char *mtd_subpage_size; char *mtd_oob_size; + char *mtd_oobavail; char *mtd_region_cnt; char *mtd_flags; unsigned int sysfs_supported:1;