From: Xiaolei Li <xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: david.oberhollenzer-S6VGOU4v5edDinCvNWH78Q@public.gmane.org,
boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org
Cc: linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org
Subject: [PATCH 1/2] libmtd: Add support to access OOB available size
Date: Mon, 9 Apr 2018 11:10:09 +0800 [thread overview]
Message-ID: <1523243410-65424-2-git-send-email-xiaolei.li@mediatek.com> (raw)
In-Reply-To: <1523243410-65424-1-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Fetch OOB available size by accessing /sys/class/mtd/mtdX/oobavail.
Signed-off-by: Xiaolei Li <xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
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;
--
1.9.1
next prev parent reply other threads:[~2018-04-09 3:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-09 3:10 [PATCH 0/2] Fix Jffs2 type flash erase problem Xiaolei Li
[not found] ` <1523243410-65424-1-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-04-09 3:10 ` Xiaolei Li [this message]
[not found] ` <1523243410-65424-2-git-send-email-xiaolei.li-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-04-09 6:58 ` [PATCH 1/2] libmtd: Add support to access OOB available size David Oberhollenzer
[not found] ` <99d17022-0b07-a999-b6ac-05b51df7d18d-S6VGOU4v5edDinCvNWH78Q@public.gmane.org>
2018-04-09 7:25 ` xiaolei li
2018-04-09 7:35 ` Boris Brezillon
2018-04-09 8:33 ` xiaolei li
2018-04-09 8:37 ` Boris Brezillon
2018-04-09 8:45 ` xiaolei li
2018-04-09 8:53 ` David Oberhollenzer
[not found] ` <bec14308-33e1-d158-37d2-4f59047f0016-S6VGOU4v5edDinCvNWH78Q@public.gmane.org>
2018-04-09 9:01 ` xiaolei li
2018-04-09 3:10 ` [PATCH 2/2] misc-utils: flash_erase: Fix Jffs2 type flash erase problem Xiaolei Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1523243410-65424-2-git-send-email-xiaolei.li@mediatek.com \
--to=xiaolei.li-nus5lvnupcjwk0htik3j/w@public.gmane.org \
--cc=boris.brezillon-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
--cc=david.oberhollenzer-S6VGOU4v5edDinCvNWH78Q@public.gmane.org \
--cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox