Commit 4740d085 authored by Leann Ogasawara's avatar Leann Ogasawara Committed by Greg Kroah-Hartman

[PATCH] Add sysfs simple class support for netlink

Patch adds sysfs simple class support for netlink character device
(Major 36).  Feedback appreciated.  Thanks,
parent 20e358f2
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/device.h>
#include <asm/bitops.h> #include <asm/bitops.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
static long open_map; static long open_map;
static struct socket *netlink_user[MAX_LINKS]; static struct socket *netlink_user[MAX_LINKS];
static struct class_simple *netlink_class;
/* /*
* Device operations * Device operations
...@@ -229,17 +231,26 @@ static int __init init_netlink(void) ...@@ -229,17 +231,26 @@ static int __init init_netlink(void)
return -EIO; return -EIO;
} }
netlink_class = class_simple_create(THIS_MODULE, "netlink");
if (IS_ERR(netlink_class)) {
printk (KERN_ERR "Error creating netlink class.\n");
unregister_chrdev(NETLINK_MAJOR, "netlink");
return PTR_ERR(netlink_class);
}
devfs_mk_dir("netlink"); devfs_mk_dir("netlink");
/* Someone tell me the official names for the uppercase ones */ /* Someone tell me the official names for the uppercase ones */
for (i = 0; i < ARRAY_SIZE(entries); i++) { for (i = 0; i < ARRAY_SIZE(entries); i++) {
devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor), devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor),
S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name); S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name);
class_simple_device_add(netlink_class, MKDEV(NETLINK_MAJOR, entries[i].minor), NULL, "%s", entries[i].name);
} }
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
devfs_mk_cdev(MKDEV(NETLINK_MAJOR, i + 16), devfs_mk_cdev(MKDEV(NETLINK_MAJOR, i + 16),
S_IFCHR|S_IRUSR|S_IWUSR, "netlink/tap%d", i); S_IFCHR|S_IRUSR|S_IWUSR, "netlink/tap%d", i);
class_simple_device_add(netlink_class, MKDEV(NETLINK_MAJOR, i + 16), NULL, "tap%d", i);
} }
return 0; return 0;
...@@ -249,11 +260,16 @@ static void __exit cleanup_netlink(void) ...@@ -249,11 +260,16 @@ static void __exit cleanup_netlink(void)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(entries); i++) for (i = 0; i < ARRAY_SIZE(entries); i++) {
devfs_remove("netlink/%s", entries[i].name); devfs_remove("netlink/%s", entries[i].name);
for (i = 0; i < 16; i++) class_simple_device_remove(MKDEV(NETLINK_MAJOR, entries[i].minor));
}
for (i = 0; i < 16; i++) {
devfs_remove("netlink/tap%d", i); devfs_remove("netlink/tap%d", i);
class_simple_device_remove(MKDEV(NETLINK_MAJOR, i + 16));
}
devfs_remove("netlink"); devfs_remove("netlink");
class_simple_destroy(netlink_class);
unregister_chrdev(NETLINK_MAJOR, "netlink"); unregister_chrdev(NETLINK_MAJOR, "netlink");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment