summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-01-09 17:17:07 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-01-09 17:17:07 +0000
commitdddb1254523f85140195f5427cb19865bd135cef (patch)
tree716e5edbd6321ec8256b69aabf74942df145b664
parent3e8db96437d988c808582013ca0d02890399e098 (diff)
For systems using a dynamic device filesystem (pretty much everything
now), don't register the character device for transcoder support unless the 'zttranscode'module is loaded. This will result in zttranscode no longer being automatically loaded when there are no transcoders present but Asterisk's codec_zap is loaded to look for them. The zttranscode module will get loaded if any transcoder driver modules are loaded, so users with transcoders will not see any change in behavior. git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@3635 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rw-r--r--zaptel-base.c56
-rw-r--r--zaptel.h11
-rw-r--r--zttranscode.c16
3 files changed, 68 insertions, 15 deletions
diff --git a/zaptel-base.c b/zaptel-base.c
index 0ce3d24..3eb9973 100644
--- a/zaptel-base.c
+++ b/zaptel-base.c
@@ -143,6 +143,8 @@ EXPORT_SYMBOL(zt_hdlc_finish);
EXPORT_SYMBOL(zt_hdlc_getbuf);
EXPORT_SYMBOL(zt_hdlc_putbuf);
EXPORT_SYMBOL(zt_alarm_channel);
+EXPORT_SYMBOL(zt_register_chardev);
+EXPORT_SYMBOL(zt_unregister_chardev);
#ifdef CONFIG_PROC_FS
static struct proc_dir_entry *proc_entries[ZT_MAX_SPANS];
@@ -155,7 +157,6 @@ static devfs_handle_t channel;
static devfs_handle_t pseudo;
static devfs_handle_t ctl;
static devfs_handle_t timer;
-static devfs_handle_t transcode;
#endif
/* udev necessary data structures. Yeah! */
@@ -7284,6 +7285,36 @@ static void __exit watchdog_cleanup(void)
#endif
+int zt_register_chardev(struct zt_chardev *dev)
+{
+#ifdef CONFIG_ZAP_UDEV
+ char udevname[strlen(dev->name) + 3];
+
+ strcpy(udevname, "zap");
+ strcat(udevname, dev->name);
+ CLASS_DEV_CREATE(zap_class, MKDEV(ZT_MAJOR, dev->minor), NULL, udevname);
+#endif /* CONFIG_ZAP_UDEV */
+
+#ifdef CONFIG_DEVFS_FS
+ dev->devfs_handle = devfs_register(zaptel_devfs_dir, dev->name, DEVFS_FL_DEFAULT, ZT_MAJOR, dev->minor, mode, &zt_fops, NULL);
+#endif /* CONFIG_DEVFS_FS */
+
+ return 0;
+}
+
+int zt_unregister_chardev(struct zt_chardev *dev)
+{
+#ifdef CONFIG_ZAP_UDEV
+ class_device_destroy(zap_class, MKDEV(ZT_MAJOR, dev->minor));
+#endif /* CONFIG_ZAP_UDEV */
+
+#ifdef CONFIG_DEVFS_FS
+ devfs_unregister(dev->devfs_handle);
+#endif /* CONFIG_DEVFS_FS */
+
+ return 0;
+}
+
static int __init zt_init(void) {
int res = 0;
@@ -7293,7 +7324,6 @@ static int __init zt_init(void) {
#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");
@@ -7302,19 +7332,19 @@ static int __init zt_init(void) {
#ifdef CONFIG_DEVFS_FS
{
- umode_t mode = S_IFCHR|S_IRUGO|S_IWUGO;
- devfs_register_chrdev(ZT_MAJOR, "zaptel", &zt_fops);
- zaptel_devfs_dir = devfs_mk_dir(NULL, "zap", NULL);
- if (!zaptel_devfs_dir) return -EBUSY; /* This would be bad */
- timer = devfs_register(zaptel_devfs_dir, "timer", DEVFS_FL_DEFAULT, ZT_MAJOR, 253, mode, &zt_fops, NULL);
- channel = devfs_register(zaptel_devfs_dir, "channel", DEVFS_FL_DEFAULT, ZT_MAJOR, 254, mode, &zt_fops, NULL);
- pseudo = devfs_register(zaptel_devfs_dir, "pseudo", DEVFS_FL_DEFAULT, ZT_MAJOR, 255, mode, &zt_fops, NULL);
- transcode = devfs_register(zaptel_devfs_dir, "transcode", DEVFS_FL_DEFAULT, ZT_MAJOR, 250, mode, &zt_fops, NULL);
- ctl = devfs_register(zaptel_devfs_dir, "ctl", DEVFS_FL_DEFAULT, ZT_MAJOR, 0, mode, &zt_fops, NULL);
+ umode_t mode = S_IFCHR|S_IRUGO|S_IWUGO;
+
+ devfs_register_chrdev(ZT_MAJOR, "zaptel", &zt_fops);
+ if (!(zaptel_devfs_dir = devfs_mk_dir(NULL, "zap", NULL)))
+ return -EBUSY; /* This would be bad */
+ timer = devfs_register(zaptel_devfs_dir, "timer", DEVFS_FL_DEFAULT, ZT_MAJOR, 253, mode, &zt_fops, NULL);
+ channel = devfs_register(zaptel_devfs_dir, "channel", DEVFS_FL_DEFAULT, ZT_MAJOR, 254, mode, &zt_fops, NULL);
+ pseudo = devfs_register(zaptel_devfs_dir, "pseudo", DEVFS_FL_DEFAULT, ZT_MAJOR, 255, mode, &zt_fops, NULL);
+ ctl = devfs_register(zaptel_devfs_dir, "ctl", DEVFS_FL_DEFAULT, ZT_MAJOR, 0, mode, &zt_fops, NULL);
}
#else
if ((res = register_chrdev(ZT_MAJOR, "zaptel", &zt_fops))) {
- printk(KERN_ERR "Unable to register tor device on %d\n", ZT_MAJOR);
+ printk(KERN_ERR "Unable to register Zaptel character device handler on %d\n", ZT_MAJOR);
return res;
}
#endif /* CONFIG_DEVFS_FS */
@@ -7347,7 +7377,6 @@ static void __exit zt_cleanup(void) {
#ifdef CONFIG_DEVFS_FS
devfs_unregister(timer);
- devfs_unregister(transcode);
devfs_unregister(channel);
devfs_unregister(pseudo);
devfs_unregister(ctl);
@@ -7355,7 +7384,6 @@ static void __exit zt_cleanup(void) {
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 */
diff --git a/zaptel.h b/zaptel.h
index 02e8a4e..2cc6106 100644
--- a/zaptel.h
+++ b/zaptel.h
@@ -1198,6 +1198,17 @@ struct zt_tone_state {
int modulate;
};
+struct zt_chardev {
+ const char *name;
+ __u8 minor;
+#ifdef CONFIG_DEVFS_FS
+ static devfs_handle_t devfs_handle;
+#endif
+};
+
+int zt_register_chardev(struct zt_chardev *dev);
+int zt_unregister_chardev(struct zt_chardev *dev);
+
#ifdef CONFIG_ZAPATA_NET
struct zt_hdlc {
#ifdef LINUX26
diff --git a/zttranscode.c b/zttranscode.c
index cf99b8a..ca2cdd8 100644
--- a/zttranscode.c
+++ b/zttranscode.c
@@ -428,7 +428,7 @@ static unsigned int zt_tc_poll(struct file *file, struct poll_table_struct *wait
return ztc->tch->status & ZT_TC_FLAG_BUSY ? 0 : POLLPRI;
}
-struct file_operations __zt_transcode_fops = {
+static struct file_operations __zt_transcode_fops = {
owner: THIS_MODULE,
llseek: NULL,
open: zt_tc_open,
@@ -443,14 +443,25 @@ struct file_operations __zt_transcode_fops = {
fasync: NULL,
};
+static struct zt_chardev transcode_chardev = {
+ .name = "transcode",
+ .minor = 250,
+};
+
int zttranscode_init(void)
{
+ int res;
+
if (zt_transcode_fops) {
printk("Whoa, zt_transcode_fops already set?!\n");
return -EBUSY;
}
zt_transcode_fops = &__zt_transcode_fops;
+
+ if ((res = zt_register_chardev(&transcode_chardev)))
+ return res;
+
printk("Zaptel Transcoder support loaded\n");
return 0;
@@ -458,7 +469,10 @@ int zttranscode_init(void)
void zttranscode_cleanup(void)
{
+ zt_unregister_chardev(&transcode_chardev);
+
zt_transcode_fops = NULL;
+
printk("Zaptel Transcoder support unloaded\n");
}