UBI: add mtd_num sysfs attribute

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 8 02:59:03 EST 2008


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=b6b76ba466bbd47397efad0fdaeaa5ebf7d462c7
Commit:     b6b76ba466bbd47397efad0fdaeaa5ebf7d462c7
Parent:     d1f3dd6cc00f5bf744118fb2820ecdf09a1f4b73
Author:     Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
AuthorDate: Wed Dec 26 13:46:46 2007 +0200
Committer:  Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
CommitDate: Wed Dec 26 19:15:17 2007 +0200

    UBI: add mtd_num sysfs attribute
    
    Expose number or the underlying MTD device in sysfs.
    
    Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
---
 drivers/mtd/ubi/build.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 0ed8105..5098e6d 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -122,6 +122,8 @@ static struct device_attribute dev_min_io_size =
 	__ATTR(min_io_size, S_IRUGO, dev_attribute_show, NULL);
 static struct device_attribute dev_bgt_enabled =
 	__ATTR(bgt_enabled, S_IRUGO, dev_attribute_show, NULL);
+static struct device_attribute dev_mtd_num =
+	__ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL);
 
 /**
  * ubi_get_device - get UBI device.
@@ -257,8 +259,10 @@ static ssize_t dev_attribute_show(struct device *dev,
 		ret = sprintf(buf, "%d\n", ubi->min_io_size);
 	else if (attr == &dev_bgt_enabled)
 		ret = sprintf(buf, "%d\n", ubi->thread_enabled);
+	else if (attr == &dev_mtd_num)
+		ret = sprintf(buf, "%d\n", ubi->mtd->index);
 	else
-		BUG();
+		ret = -EINVAL;
 
 	ubi_put_device(ubi);
 	return ret;
@@ -314,6 +318,9 @@ static int ubi_sysfs_init(struct ubi_device *ubi)
 	if (err)
 		return err;
 	err = device_create_file(&ubi->dev, &dev_bgt_enabled);
+	if (err)
+		return err;
+	err = device_create_file(&ubi->dev, &dev_mtd_num);
 	return err;
 }
 
@@ -323,6 +330,7 @@ static int ubi_sysfs_init(struct ubi_device *ubi)
  */
 static void ubi_sysfs_close(struct ubi_device *ubi)
 {
+	device_remove_file(&ubi->dev, &dev_mtd_num);
 	device_remove_file(&ubi->dev, &dev_bgt_enabled);
 	device_remove_file(&ubi->dev, &dev_min_io_size);
 	device_remove_file(&ubi->dev, &dev_max_vol_count);



More information about the linux-mtd-cvs mailing list