Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: David Woodhouse
Date: Friday, August 29, 2008 - 5:19 am

On Wed, 2008-08-27 at 17:25 +0200, Jörn Engel wrote:

That's not _necessarily_ true, although it should certainly be done with
care. Attributes in sysfs can be optional (in a way that they can't
really be optional if they're part of a binary ioctl payload), and
userspace can cope with them being absent. The sub-page size attribute
is something which wouldn't always be present, and we could happily just
drop it and forget about it in future if we really wanted to.


It's hardly a fast path. And we don't have to worry about the fact that
it's non-atomic -- these things aren't exactly _changing_ over time.


You whine too much, Jörn. It doesn't take very long, as a proof of
concept, to add some attributes to the existing class support in
mtdchar.c ...

--- drivers/mtd/mtdchar.c~	2008-07-13 22:51:29.000000000 +0100
+++ drivers/mtd/mtdchar.c	2008-08-29 13:15:08.000000000 +0100
@@ -22,12 +22,32 @@
 
 static struct class *mtd_class;
 
+static ssize_t mtd_show_size(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+	return sprintf(buf, "0x%x\n", mtd->size);
+}
+static ssize_t mtd_show_erasesize(struct device *dev, struct device_attribute *attr,
+				  char *buf)
+{
+	struct mtd_info *mtd = dev_get_drvdata(dev);
+	return sprintf(buf, "0x%x\n", mtd->erasesize);
+}
+
+static DEVICE_ATTR(size, S_IRUGO, mtd_show_size, NULL);
+static DEVICE_ATTR(erasesize, S_IRUGO, mtd_show_erasesize, NULL);
+
 static void mtd_notify_add(struct mtd_info* mtd)
 {
+	struct device *dev;
 	if (!mtd)
 		return;
 
-	device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index);
+	dev = device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index);
+	dev_set_drvdata(dev, mtd);
+	device_create_file(dev, &dev_attr_size);
+	device_create_file(dev, &dev_attr_erasesize);
 
 	device_create(mtd_class, NULL,
 		      MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), "mtd%dro", mtd->index);


Ok, so it shouldn't be only for mtdchar -- it should be generic, so we
should shift some of that into the mtd core code. And we should let
people hook up the 'parent' correctly, and there are a few other things
we should do to tidy it up. But it isn't exactly hard.

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@intel.com                              Intel Corporation



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Bruce Leonard, (Thu Aug 21, 7:00 pm)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Tue Aug 26, 10:56 pm)
RE: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Tue Aug 26, 11:03 pm)
RE: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, David Woodhouse, (Tue Aug 26, 11:35 pm)
RE: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Tue Aug 26, 11:38 pm)
RE: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Ricard Wanderlof, (Tue Aug 26, 11:49 pm)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Wed Aug 27, 12:08 am)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Bruce Leonard, (Wed Aug 27, 12:10 am)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, David Woodhouse, (Wed Aug 27, 2:01 am)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Wed Aug 27, 7:47 am)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, Artem Bityutskiy, (Thu Aug 28, 10:48 pm)
Re: [PATCH 2/2][MTD] Add support for > 2GiB MTD devices, David Woodhouse, (Fri Aug 29, 5:19 am)