public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* patch to create sysfs char device nodes
@ 2005-06-09 14:16 Paolo Galtieri
  2005-07-04 16:14 ` Coywolf Qi Hunt
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Galtieri @ 2005-06-09 14:16 UTC (permalink / raw)
  To: linux-mtd

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

Hi,
  with DEVFS going away I discovered that no character device nodes are
created if a flash device is present which contains filesystems. The
mtd-utils package requires the existence of character device nodes for
performing erase, lock and unlock functions.  The problem is that the
flash device driver has not been modified to use sysfs instead of devfs.

I have attached a patch to mtdchar.c which uses the sysfs interface to
create the appropriate nodes.  Please let me know if you have comments.

The changes are for linux-2.6.12-rc5

Thanks
Paolo

[-- Attachment #2: MTDCnew --]
[-- Type: text/plain, Size: 2085 bytes --]

--- drivers/mtd/OLDmtdchar.c	2005-06-06 16:10:39.000000000 -0700
+++ drivers/mtd/mtdchar.c	2005-06-06 16:18:39.000000000 -0700
@@ -15,27 +15,29 @@
 #include <linux/fs.h>
 #include <asm/uaccess.h>
 
-#ifdef CONFIG_DEVFS_FS
-#include <linux/devfs_fs_kernel.h>
+#include <linux/device.h>
+
+static struct class_simple *mtd_class;
 
 static void mtd_notify_add(struct mtd_info* mtd)
 {
 	if (!mtd)
 		return;
 
-	devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
-		      S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index);
-		
-	devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
-		      S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index);
+	class_simple_device_add(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
+		NULL, "mtd%d", mtd->index);
+
+	class_simple_device_add(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
+		NULL, "mtd%dro", mtd->index);
+
 }
 
 static void mtd_notify_remove(struct mtd_info* mtd)
 {
 	if (!mtd)
 		return;
-	devfs_remove("mtd/%d", mtd->index);
-	devfs_remove("mtd/%dro", mtd->index);
+	class_simple_device_remove(MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
+	class_simple_device_remove(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
 }
 
 static struct mtd_notifier notifier = {
@@ -45,19 +47,13 @@
 
 static inline void mtdchar_devfs_init(void)
 {
-	devfs_mk_dir("mtd");
 	register_mtd_user(&notifier);
 }
 
 static inline void mtdchar_devfs_exit(void)
 {
 	unregister_mtd_user(&notifier);
-	devfs_remove("mtd");
 }
-#else /* !DEVFS */
-#define mtdchar_devfs_init() do { } while(0)
-#define mtdchar_devfs_exit() do { } while(0)
-#endif
 
 static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
 {
@@ -543,6 +539,14 @@
 		return -EAGAIN;
 	}
 
+	mtd_class = class_simple_create(THIS_MODULE, "mtd");
+
+	if (IS_ERR(mtd_class)) {
+		printk(KERN_ERR "Error creating mtd class.\n");
+		unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
+		return 1;
+	}
+
 	mtdchar_devfs_init();
 	return 0;
 }
@@ -550,6 +554,7 @@
 static void __exit cleanup_mtdchar(void)
 {
 	mtdchar_devfs_exit();
+	class_simple_destroy(mtd_class);
 	unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-04 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-09 14:16 patch to create sysfs char device nodes Paolo Galtieri
2005-07-04 16:14 ` Coywolf Qi Hunt
2005-07-04 16:25   ` Thomas Gleixner
2005-07-04 17:15     ` Coywolf Qi Hunt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox