lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250719-mtd-ooblayout-sysfs-v1-1-e0d68d872e17@gmail.com>
Date: Sat, 19 Jul 2025 14:06:48 +0200
From: Gabor Juhos <j4g8y7@...il.com>
To: Miquel Raynal <miquel.raynal@...tlin.com>, 
 Richard Weinberger <richard@....at>, Vignesh Raghavendra <vigneshr@...com>
Cc: linux-kernel@...r.kernel.org, linux-mtd@...ts.infradead.org, 
 Gabor Juhos <j4g8y7@...il.com>
Subject: [PATCH] mtd: expose ooblayout information via sysfs

Add two new sysfs device attributes which allows to determine the OOB
layout used by a given MTD device. This can be useful to verify the
current layout during driver development without adding extra debug
code. The exposed information also makes it easier to analyze NAND
dumps without the need of cravling out the layout from the driver code.

The content of the new sysfs files is similar to this:

    # cat /sys/class/mtd/mtd0/ooblayout_ecc
    0      0   49
    1     65   63
    # cat /sys/class/mtd/mtd0/ooblayout_free
    0     49   16

Also update the ABI documentation about the new attributes.

Signed-off-by: Gabor Juhos <j4g8y7@...il.com>
---
 Documentation/ABI/testing/sysfs-class-mtd | 14 +++++++++++
 drivers/mtd/mtdcore.c                     | 40 +++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd
index f77fa4f6d46571175b156113a1afeeb9f5f51c0f..fd3000b9cc7aee4ea9069d1869f310fefa24f97a 100644
--- a/Documentation/ABI/testing/sysfs-class-mtd
+++ b/Documentation/ABI/testing/sysfs-class-mtd
@@ -240,3 +240,17 @@ Contact:	linux-mtd@...ts.infradead.org
 Description:
 		Number of bytes available for a client to place data into
 		the out of band area.
+
+What:		/sys/class/mtd/mtdX/ooblayout_ecc
+What:		/sys/class/mtd/mtdX/ooblayout_free
+Date:		July 2025
+KernelVersion:	6.17
+Contact:	linux-mtd@...ts.infradead.org
+Description:
+		Newline separated list of the regions in the out of band area.
+
+		Each line contains three decimal numbers separated by spaces.
+		The first number indicates the index of the region. The second
+		number describes the starting offset within the out of band
+		area. The last number specifies the amount of bytes available
+		in the region.
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 429d8c16baf045e6a030e309ce0fb1cbec669098..552d12f749e43b7d9abb07e0235a3ef2d2a98546 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -254,6 +254,44 @@ static ssize_t mtd_oobavail_show(struct device *dev,
 }
 MTD_DEVICE_ATTR_RO(oobavail);
 
+static ssize_t mtd_ooblayout_show(struct device *dev,
+				  struct device_attribute *attr, char *buf,
+				  int (*iter)(struct mtd_info *, int section,
+					      struct mtd_oob_region *region))
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+	ssize_t size = 0;
+	int section;
+
+	for (section = 0;; section++) {
+		struct mtd_oob_region region;
+		int err;
+
+		err = iter(mtd, section, &region);
+		if (err)
+			break;
+
+		size += sysfs_emit_at(buf, size, "%-3d %4u %4u\n", section,
+				      region.offset, region.length);
+	}
+
+	return size;
+}
+
+static ssize_t mtd_ooblayout_ecc_show(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	return mtd_ooblayout_show(dev, attr, buf, mtd_ooblayout_ecc);
+}
+MTD_DEVICE_ATTR_RO(ooblayout_ecc);
+
+static ssize_t mtd_ooblayout_free_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
+{
+	return mtd_ooblayout_show(dev, attr, buf, mtd_ooblayout_free);
+}
+MTD_DEVICE_ATTR_RO(ooblayout_free);
+
 static ssize_t mtd_numeraseregions_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
@@ -366,6 +404,8 @@ static struct attribute *mtd_attrs[] = {
 	&dev_attr_subpagesize.attr,
 	&dev_attr_oobsize.attr,
 	&dev_attr_oobavail.attr,
+	&dev_attr_ooblayout_ecc.attr,
+	&dev_attr_ooblayout_free.attr,
 	&dev_attr_numeraseregions.attr,
 	&dev_attr_name.attr,
 	&dev_attr_ecc_strength.attr,

---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250719-mtd-ooblayout-sysfs-77af651b3738

Best regards,
-- 
Gabor Juhos <j4g8y7@...il.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ