ChangeSet 1.1608.84.7, 2004/03/10 17:34:33-08:00, ogasawara@osdl.org [PATCH] Add sysfs simple class support for netlink Patch adds sysfs simple class support for netlink character device (Major 36). Feedback appreciated. Thanks, net/netlink/netlink_dev.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff -Nru a/net/netlink/netlink_dev.c b/net/netlink/netlink_dev.c --- a/net/netlink/netlink_dev.c Mon Mar 15 15:29:27 2004 +++ b/net/netlink/netlink_dev.c Mon Mar 15 15:29:27 2004 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ static long open_map; static struct socket *netlink_user[MAX_LINKS]; +static struct class_simple *netlink_class; /* * Device operations @@ -229,17 +231,26 @@ 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"); /* Someone tell me the official names for the uppercase ones */ for (i = 0; i < ARRAY_SIZE(entries); i++) { devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor), 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++) { devfs_mk_cdev(MKDEV(NETLINK_MAJOR, i + 16), 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; @@ -249,11 +260,16 @@ { 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); - 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); + class_simple_device_remove(MKDEV(NETLINK_MAJOR, i + 16)); + } devfs_remove("netlink"); + class_simple_destroy(netlink_class); unregister_chrdev(NETLINK_MAJOR, "netlink"); }