summaryrefslogtreecommitdiff
path: root/lib/libmtd_legacy.c
diff options
context:
space:
mode:
authorXiaolei Li <xiaolei.li@mediatek.com>2018-04-10 15:36:55 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2018-04-10 15:38:56 +0200
commita10353584f93334b5687c598a15260c0fc5b8d3e (patch)
treecb2916f76ba8c9cbe131b7cf632027891f94d964 /lib/libmtd_legacy.c
parent044ed4c0dd788f980a3a1a6fc6bf855a239f12e5 (diff)
libmtd: Add support to access OOB available size
This patch exposes OOB available size to user. Then user can use OOB free area according to OOB available size. Steps to get OOB available size: First, access /sys/class/mtd/mtdX/oobavail. If not exist, then try to get ecc layout by ioctl "ECCGETLAYOUT". If none of them work, set OOB available size to 0. Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/libmtd_legacy.c')
-rw-r--r--lib/libmtd_legacy.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index 46f51fd..e1ab48e 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -215,6 +215,46 @@ int legacy_mtd_get_info(struct mtd_info *info)
return 0;
}
+int legacy_get_mtd_oobavail(const char *node)
+{
+ struct stat st;
+ struct nand_ecclayout_user usrlay;
+ int fd, ret;
+
+ if (stat(node, &st))
+ return sys_errmsg("cannot open \"%s\"", node);
+
+ if (!S_ISCHR(st.st_mode)) {
+ errno = EINVAL;
+ return errmsg("\"%s\" is not a character device", node);
+ }
+
+ fd = open(node, O_RDONLY);
+ if (fd == -1)
+ return sys_errmsg("cannot open \"%s\"", node);
+
+ ret = ioctl(fd, ECCGETLAYOUT, &usrlay);
+ if (ret < 0) {
+ sys_errmsg("ECCGETLAYOUT ioctl request failed");
+ goto out_close;
+ }
+
+ ret = usrlay.oobavail;
+
+out_close:
+ close(fd);
+
+ return ret;
+}
+
+int legacy_get_mtd_oobavail1(int mtd_num)
+{
+ char node[sizeof(MTD_DEV_PATT) + 20];
+
+ sprintf(node, MTD_DEV_PATT, mtd_num);
+ return legacy_get_mtd_oobavail(node);
+}
+
/**
* legacy_get_dev_info - legacy version of 'mtd_get_dev_info()'.
* @node: name of the MTD device node
@@ -335,6 +375,9 @@ int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd)
close(fd);
+ ret = legacy_get_mtd_oobavail(node);
+ mtd->oobavail = ret > 0 ? ret : 0;
+
/*
* Unfortunately, the device name is not available via ioctl, and
* we have to parse /proc/mtd to get it.