public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Paolo Galtieri <pgaltieri@mvista.com>
To: linux-mtd@lists.infradead.org
Subject: patch to create sysfs char device nodes
Date: Thu, 09 Jun 2005 14:16:27 -0000	[thread overview]
Message-ID: <1118327333.2401.42.camel@playin.mvista.com> (raw)

[-- 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");
 }
 

             reply	other threads:[~2005-06-09 14:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-09 14:16 Paolo Galtieri [this message]
2005-07-04 16:14 ` patch to create sysfs char device nodes Coywolf Qi Hunt
2005-07-04 16:25   ` Thomas Gleixner
2005-07-04 17:15     ` Coywolf Qi Hunt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1118327333.2401.42.camel@playin.mvista.com \
    --to=pgaltieri@mvista.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox