amend sysfs mtd sysfs interface
cover amend sysfs mtd sysfs interface
Hi, this patch series improves MTD sysfs interface. It adds a couple of new useful files which I'm going to use in UBI utilites. It also removes the 'flags' file because I believe it is a bad idea to expose it to userspace via sysfs, just bad API.
David, if you are fine with these, please, make it go upstream now, because we have just added sysfs and it is not too late to amend it.
Thanks.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)
PATCH 1/3 MTD: add sysfs file which tells if bad blocks are allowed
Add a per-mtd device 'bb_allowed' sysfs file which contains 0 if bad blocks are not allowed, and 1 if they are allowed.
This is useful for userspace.
--- drivers/mtd/mtdcore.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/mtd/mtdcore.c +11 -0
@@ -174,6 +174,16 @@ static ssize_t mtd_name_show(struct device *dev, } static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL); +static ssize_t mtd_bb_allowed_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct mtd_info *mtd =dev_to_mtd (dev); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , !!mtd->block_markbad); + +} +static DEVICE_ATTR(bb_allowed, S_IRUGO, mtd_bb_allowed_show, NULL); +static struct attribute *mtd_attrs[] = { &dev_attr_type.attr, &dev_attr_flags.attr,
@@ -184,6 +194,7 @@ static struct attribute *mtd_attrs[] = { &dev_attr_oobsize.attr, &dev_attr_numeraseregions.attr, &dev_attr_name.attr, + &dev_attr_bb_allowed.attr, NULL, };
Signature · 6 lines
1.6.0.6 -- Best regards, Artem Bityutskiy (Битюцкий Артём)
PATCH 2/3 MTD: add sysfs file which shows if the device is writable
In reply to Artem BityutskiyAdd "writable" per-mtd device file which contains 1 if the MTD device is writable and 0 if it is not.
--- drivers/mtd/mtdcore.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/mtd/mtdcore.c +11 -0
@@ -184,6 +184,16 @@ static ssize_t mtd_bb_allowed_show(struct device *dev, } static DEVICE_ATTR(bb_allowed, S_IRUGO, mtd_bb_allowed_show, NULL); +static ssize_t mtd_writable_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct mtd_info *mtd =dev_to_mtd (dev); + +return snprintf (buf,PAGE_SIZE ,"%d\n" , !!(mtd->flags &MTD_WRITEABLE )); + +} +static DEVICE_ATTR(writable, S_IRUGO, mtd_writable_show, NULL); +static struct attribute *mtd_attrs[] = { &dev_attr_type.attr, &dev_attr_flags.attr,
@@ -195,6 +205,7 @@ static struct attribute *mtd_attrs[] = { &dev_attr_numeraseregions.attr, &dev_attr_name.attr, &dev_attr_bb_allowed.attr, + &dev_attr_writable.attr, NULL, };
Signature · 5 lines
1.6.0.6 -- Best regards, Artem Bityutskiy (Битюцкий Артём)
PATCH 3/3 MTD: remove the 'flags' sysfs file
In reply to Artem BityutskiyIt is bad idea to export the MTD flags via sysfs. It is much cleaner to create a per-flag sysfs file which contains 0 or
1. It is difficult for users to parse '0x400'. We have ioctls which return the flags, no need to add this to sysfs.
--- drivers/mtd/mtdcore.c | 11 ----------- 1 files changed, 0 insertions(+), 11 deletions(-)
drivers/mtd/mtdcore.c +0 -11
@@ -91,16 +91,6 @@ static ssize_t mtd_type_show(struct device *dev, } static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL); -static ssize_t mtd_flags_show (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct mtd_info *mtd =dev_to_mtd (dev); - -return snprintf (buf,PAGE_SIZE ,"0x%lx\n" , (unsigned long )mtd->flags); - -} -static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL); -static ssize_t mtd_size_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -196,7 +186,6 @@ static DEVICE_ATTR(writable, S_IRUGO, mtd_writable_show, NULL);static struct attribute *mtd_attrs[] = { &dev_attr_type.attr, - &dev_attr_flags.attr, &dev_attr_size.attr, &dev_attr_erasesize.attr, &dev_attr_writesize.attr,
Signature · 5 lines
1.6.0.6 -- Best regards, Artem Bityutskiy (Битюцкий Артём)