Index: zaptel-base.c =================================================================== --- zaptel-base.c (révision 12) +++ zaptel-base.c (copie de travail) @@ -160,30 +160,8 @@ static devfs_handle_t transcode; #endif -/* udev necessary data structures. Yeah! */ -#ifdef CONFIG_ZAP_UDEV +#include "zaptel-sysfs.h" -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) -#define CLASS_DEV_CREATE(class, devt, device, name) \ - class_device_create(class, NULL, devt, device, name) -#else -#define CLASS_DEV_CREATE(class, devt, device, name) \ - class_device_create(class, devt, device, name) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) -static struct class *zap_class = NULL; -#else -static struct class_simple *zap_class = NULL; -#define class_create class_simple_create -#define class_destroy class_simple_destroy -#define class_device_create class_simple_device_add -#define class_device_destroy(a, b) class_simple_device_remove(b) -#endif - -#endif /* CONFIG_ZAP_UDEV */ - - /* There is a table like this in the PPP driver, too */ static int deftaps = 64; @@ -4731,11 +4709,20 @@ #endif /* CONFIG_DEVFS_FS */ #ifdef CONFIG_ZAP_UDEV - for (x = 0; x < span->channels; x++) { - char chan_name[50]; - if (span->chans[x].channo < 250) { - sprintf(chan_name, "zap%d", span->chans[x].channo); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, span->chans[x].channo), NULL, chan_name); + /* for the time beeing we are obliged to do bad error handling + * so as to not break the whole zt_register mechanism + * FIXME: add proper locking + */ + if (zt_sysfs_span_register(span)) { + printk(KERN_ERR "Sysfs Registration of span %d failed\n", span->spanno); + } else { + + for (x = 0; x < span->channels; x++) { + if (zt_sysfs_channel_register(&span->chans[x])) { + printk(KERN_ERR "Sysfs Registration of channel %d from span %d failed\n", + span->chans[x].channo, span->spanno); + break; + } } } #endif /* CONFIG_ZAP_UDEV */ @@ -4788,10 +4775,13 @@ #endif /* CONFIG_DEVFS_FS */ #ifdef CONFIG_ZAP_UDEV + /* + * FIXME: add proper locking + */ for (x = 0; x < span->channels; x++) { - if (span->chans[x].channo < 250) - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, span->chans[x].channo)); + zt_sysfs_channel_unregister(&span->chans[x]); } + zt_sysfs_span_unregister(span); #endif /* CONFIG_ZAP_UDEV */ spans[span->spanno] = NULL; @@ -7141,12 +7131,12 @@ #endif #ifdef CONFIG_ZAP_UDEV /* udev support functions */ - zap_class = class_create(THIS_MODULE, "zaptel"); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 250), NULL, "zaptranscode"); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 253), NULL, "zaptimer"); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 254), NULL, "zapchannel"); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 255), NULL, "zappseudo"); - CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, 0), NULL, "zapctl"); + res = zt_sysfs_init(); + if (res) { + printk(KERN_ERR "Unable to init sysfs for zaptel\n"); + return res; + } + /* FIXME: Add proper error handling to this method */ #endif /* CONFIG_ZAP_UDEV */ #ifdef CONFIG_DEVFS_FS @@ -7235,12 +7225,7 @@ devfs_unregister_chrdev(ZT_MAJOR, "zaptel"); #else #ifdef CONFIG_ZAP_UDEV - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, 250)); /* transcode */ - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, 253)); /* timer */ - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, 254)); /* channel */ - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, 255)); /* pseudo */ - class_device_destroy(zap_class, MKDEV(ZT_MAJOR, 0)); /* ctl */ - class_destroy(zap_class); + zt_sysfs_destroy(); #endif /* CONFIG_ZAP_UDEV */ unregister_chrdev(ZT_MAJOR, "zaptel"); #endif