patch-2.2.15 linux/drivers/isdn/divert/divert_procfs.c
Next file: linux/drivers/isdn/eicon/eicon.h
Previous file: linux/drivers/isdn/avmb1/t1pci.c
Back to the patch index
Back to the overall index
- Lines: 576
- Date:
Fri Apr 21 12:46:08 2000
- Orig file:
v2.2.14/drivers/isdn/divert/divert_procfs.c
- Orig date:
Wed Oct 20 01:12:36 1999
diff -u --new-file --recursive --exclude-from ../../exclude v2.2.14/drivers/isdn/divert/divert_procfs.c linux/drivers/isdn/divert/divert_procfs.c
@@ -1,10 +1,10 @@
-/*
- * $Id: divert_procfs.c,v 1.5 1999/09/14 20:31:01 werner Exp $
+/*
+ * $Id: divert_procfs.c,v 1.6 2000/02/14 19:23:03 werner Exp $
*
* Filesystem handling for the diversion supplementary services.
*
* Copyright 1998 by Werner Cornelius (werner@isdn4linux.de)
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
@@ -17,9 +17,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: divert_procfs.c,v $
+ * Revision 1.6 2000/02/14 19:23:03 werner
+ *
+ * Changed handling of proc filesystem tables to a more portable version
+ *
* Revision 1.5 1999/09/14 20:31:01 werner
*
* Removed obsoleted functions for proc fs and synced with new ones.
@@ -44,9 +48,9 @@
#include <linux/version.h>
#include <linux/poll.h>
#ifdef CONFIG_PROC_FS
- #include <linux/proc_fs.h>
+#include <linux/proc_fs.h>
#else
- #include <linux/fs.h>
+#include <linux/fs.h>
#endif
#include <linux/isdnif.h>
#include "isdn_divert.h"
@@ -54,220 +58,239 @@
/*********************************/
/* Variables for interface queue */
/*********************************/
-ulong if_used = 0; /* number of interface users */
-static struct divert_info *divert_info_head = NULL; /* head of queue */
-static struct divert_info *divert_info_tail = NULL; /* pointer to last entry */
-static struct wait_queue *rd_queue = 0; /* Queue IO */
+ulong if_used = 0; /* number of interface users */
+static struct divert_info *divert_info_head = NULL; /* head of queue */
+static struct divert_info *divert_info_tail = NULL; /* pointer to last entry */
+static struct wait_queue *rd_queue = 0; /* Queue IO */
/*********************************/
/* put an info buffer into queue */
/*********************************/
-void put_info_buffer(char *cp)
-{ struct divert_info *ib;
- int flags;
-
- if (if_used <= 0) return;
- if (!cp) return;
- if (!*cp) return;
- if (!(ib = (struct divert_info *) kmalloc(sizeof(struct divert_info)+strlen(cp), GFP_ATOMIC))) return; /* no memory */
- strcpy(ib->info_start,cp); /* set output string */
- ib->next = NULL;
- save_flags(flags);
- cli();
- ib->usage_cnt = if_used;
- if (!divert_info_head)
- divert_info_head = ib; /* new head */
- else
- divert_info_tail->next = ib; /* follows existing messages */
- divert_info_tail = ib; /* new tail */
- restore_flags(flags);
-
- /* delete old entrys */
- while (divert_info_head->next)
- { if ((divert_info_head->usage_cnt <= 0) &&
- (divert_info_head->next->usage_cnt <= 0))
- { ib = divert_info_head;
- divert_info_head = divert_info_head->next;
- kfree(ib);
- }
- else break;
- } /* divert_info_head->next */
- wake_up_interruptible(&(rd_queue));
-} /* put_info_buffer */
+void
+put_info_buffer(char *cp)
+{
+ struct divert_info *ib;
+ int flags;
+
+ if (if_used <= 0)
+ return;
+ if (!cp)
+ return;
+ if (!*cp)
+ return;
+ if (!(ib = (struct divert_info *) kmalloc(sizeof(struct divert_info) + strlen(cp), GFP_ATOMIC)))
+ return; /* no memory */
+ strcpy(ib->info_start, cp); /* set output string */
+ ib->next = NULL;
+ save_flags(flags);
+ cli();
+ ib->usage_cnt = if_used;
+ if (!divert_info_head)
+ divert_info_head = ib; /* new head */
+ else
+ divert_info_tail->next = ib; /* follows existing messages */
+ divert_info_tail = ib; /* new tail */
+ restore_flags(flags);
+
+ /* delete old entrys */
+ while (divert_info_head->next) {
+ if ((divert_info_head->usage_cnt <= 0) &&
+ (divert_info_head->next->usage_cnt <= 0)) {
+ ib = divert_info_head;
+ divert_info_head = divert_info_head->next;
+ kfree(ib);
+ } else
+ break;
+ } /* divert_info_head->next */
+ wake_up_interruptible(&(rd_queue));
+} /* put_info_buffer */
/**********************************/
/* deflection device read routine */
/**********************************/
-static ssize_t isdn_divert_read(struct file *file, char *buf, size_t count, loff_t *off)
-{ struct divert_info *inf;
- int len;
-
- if (!*((struct divert_info **)file->private_data))
- { if (file->f_flags & O_NONBLOCK)
- return -EAGAIN;
- interruptible_sleep_on(&(rd_queue));
- }
- if (!(inf = *((struct divert_info **)file->private_data))) return(0);
-
- inf->usage_cnt--; /* new usage count */
- (struct divert_info **)file->private_data = &inf->next; /* next structure */
- if ((len = strlen(inf->info_start)) <= count)
- { if (copy_to_user(buf, inf->info_start, len))
- return -EFAULT;
- file->f_pos += len;
- return(len);
- }
- return(0);
-} /* isdn_divert_read */
+static ssize_t
+isdn_divert_read(struct file *file, char *buf, size_t count, loff_t * off)
+{
+ struct divert_info *inf;
+ int len;
+
+ if (!*((struct divert_info **) file->private_data)) {
+ if (file->f_flags & O_NONBLOCK)
+ return -EAGAIN;
+ interruptible_sleep_on(&(rd_queue));
+ }
+ if (!(inf = *((struct divert_info **) file->private_data)))
+ return (0);
+
+ inf->usage_cnt--; /* new usage count */
+ (struct divert_info **) file->private_data = &inf->next; /* next structure */
+ if ((len = strlen(inf->info_start)) <= count) {
+ if (copy_to_user(buf, inf->info_start, len))
+ return -EFAULT;
+ file->f_pos += len;
+ return (len);
+ }
+ return (0);
+} /* isdn_divert_read */
/**********************************/
/* deflection device write routine */
/**********************************/
-static ssize_t isdn_divert_write(struct file *file, const char *buf, size_t count, loff_t *off)
+static ssize_t
+isdn_divert_write(struct file *file, const char *buf, size_t count, loff_t * off)
{
- return(-ENODEV);
-} /* isdn_divert_write */
+ return (-ENODEV);
+} /* isdn_divert_write */
/***************************************/
/* select routines for various kernels */
/***************************************/
-static unsigned int isdn_divert_poll(struct file *file, poll_table * wait)
-{ unsigned int mask = 0;
+static unsigned int
+isdn_divert_poll(struct file *file, poll_table * wait)
+{
+ unsigned int mask = 0;
- poll_wait(file, &(rd_queue), wait);
- /* mask = POLLOUT | POLLWRNORM; */
- if (*((struct divert_info **)file->private_data))
- { mask |= POLLIN | POLLRDNORM;
- }
- return mask;
-} /* isdn_divert_poll */
+ poll_wait(file, &(rd_queue), wait);
+ /* mask = POLLOUT | POLLWRNORM; */
+ if (*((struct divert_info **) file->private_data)) {
+ mask |= POLLIN | POLLRDNORM;
+ }
+ return mask;
+} /* isdn_divert_poll */
/****************/
/* Open routine */
/****************/
-static int isdn_divert_open(struct inode *ino, struct file *filep)
-{ int flags;
+static int
+isdn_divert_open(struct inode *ino, struct file *filep)
+{
+ int flags;
- MOD_INC_USE_COUNT;
- save_flags(flags);
- cli();
- if_used++;
- if (divert_info_head)
- (struct divert_info **)filep->private_data = &(divert_info_tail->next);
- else
- (struct divert_info **)filep->private_data = &divert_info_head;
- restore_flags(flags);
- /* start_divert(); */
- return(0);
-} /* isdn_divert_open */
+ MOD_INC_USE_COUNT;
+ save_flags(flags);
+ cli();
+ if_used++;
+ if (divert_info_head)
+ (struct divert_info **) filep->private_data = &(divert_info_tail->next);
+ else
+ (struct divert_info **) filep->private_data = &divert_info_head;
+ restore_flags(flags);
+ /* start_divert(); */
+ return (0);
+} /* isdn_divert_open */
/*******************/
/* close routine */
/*******************/
-static int isdn_divert_close(struct inode *ino, struct file *filep)
-{ struct divert_info *inf;
- int flags;
-
- save_flags(flags);
- cli();
- if_used--;
- inf = *((struct divert_info **)filep->private_data);
- while (inf)
- { inf->usage_cnt--;
- inf = inf->next;
- }
- restore_flags(flags);
- if (if_used <= 0)
- while (divert_info_head)
- { inf = divert_info_head;
- divert_info_head = divert_info_head->next;
- kfree(inf);
- }
- MOD_DEC_USE_COUNT;
- return(0);
-} /* isdn_divert_close */
+static int
+isdn_divert_close(struct inode *ino, struct file *filep)
+{
+ struct divert_info *inf;
+ int flags;
+
+ save_flags(flags);
+ cli();
+ if_used--;
+ inf = *((struct divert_info **) filep->private_data);
+ while (inf) {
+ inf->usage_cnt--;
+ inf = inf->next;
+ }
+ restore_flags(flags);
+ if (if_used <= 0)
+ while (divert_info_head) {
+ inf = divert_info_head;
+ divert_info_head = divert_info_head->next;
+ kfree(inf);
+ }
+ MOD_DEC_USE_COUNT;
+ return (0);
+} /* isdn_divert_close */
/*********/
/* IOCTL */
/*********/
-static int isdn_divert_ioctl(struct inode *inode, struct file *file,
- uint cmd, ulong arg)
-{ divert_ioctl dioctl;
- int i, flags;
- divert_rule *rulep;
- char *cp;
-
- if ((i = copy_from_user(&dioctl,(char *) arg, sizeof(dioctl))))
- return(i);
-
- switch (cmd)
- {
- case IIOCGETVER:
- dioctl.drv_version = DIVERT_IIOC_VERSION ; /* set version */
- break;
-
- case IIOCGETDRV:
- if ((dioctl.getid.drvid = divert_if.name_to_drv(dioctl.getid.drvnam)) < 0)
- return(-EINVAL);
- break;
-
- case IIOCGETNAM:
- cp = divert_if.drv_to_name(dioctl.getid.drvid);
- if (!cp) return(-EINVAL);
- if (!*cp) return(-EINVAL);
- strcpy(dioctl.getid.drvnam,cp);
- break;
-
- case IIOCGETRULE:
- if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
- return(-EINVAL);
- dioctl.getsetrule.rule = *rulep; /* copy data */
- break;
-
- case IIOCMODRULE:
- if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
- return(-EINVAL);
- save_flags(flags);
- cli();
- *rulep = dioctl.getsetrule.rule; /* copy data */
- restore_flags(flags);
- return(0); /* no copy required */
- break;
-
- case IIOCINSRULE:
- return(insertrule(dioctl.getsetrule.ruleidx,&dioctl.getsetrule.rule));
- break;
-
- case IIOCDELRULE:
- return(deleterule(dioctl.getsetrule.ruleidx));
- break;
-
- case IIOCDODFACT:
- return(deflect_extern_action(dioctl.fwd_ctrl.subcmd,
- dioctl.fwd_ctrl.callid,
- dioctl.fwd_ctrl.to_nr));
-
- case IIOCDOCFACT:
- case IIOCDOCFDIS:
- case IIOCDOCFINT:
- if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
- return(-EINVAL); /* invalid driver */
- if ((i = cf_command(dioctl.cf_ctrl.drvid,
- (cmd == IIOCDOCFACT) ? 1: (cmd == IIOCDOCFDIS) ? 0:2,
- dioctl.cf_ctrl.cfproc,
- dioctl.cf_ctrl.msn,
- dioctl.cf_ctrl.service,
- dioctl.cf_ctrl.fwd_nr,
- &dioctl.cf_ctrl.procid)))
- return(i);
- break;
-
- default:
- return(-EINVAL);
- } /* switch cmd */
- return(copy_to_user((char *) arg, &dioctl, sizeof(dioctl))); /* success */
-} /* isdn_divert_ioctl */
+static int
+isdn_divert_ioctl(struct inode *inode, struct file *file,
+ uint cmd, ulong arg)
+{
+ divert_ioctl dioctl;
+ int i, flags;
+ divert_rule *rulep;
+ char *cp;
+
+ if ((i = copy_from_user(&dioctl, (char *) arg, sizeof(dioctl))))
+ return (i);
+
+ switch (cmd) {
+ case IIOCGETVER:
+ dioctl.drv_version = DIVERT_IIOC_VERSION; /* set version */
+ break;
+
+ case IIOCGETDRV:
+ if ((dioctl.getid.drvid = divert_if.name_to_drv(dioctl.getid.drvnam)) < 0)
+ return (-EINVAL);
+ break;
+
+ case IIOCGETNAM:
+ cp = divert_if.drv_to_name(dioctl.getid.drvid);
+ if (!cp)
+ return (-EINVAL);
+ if (!*cp)
+ return (-EINVAL);
+ strcpy(dioctl.getid.drvnam, cp);
+ break;
+
+ case IIOCGETRULE:
+ if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
+ return (-EINVAL);
+ dioctl.getsetrule.rule = *rulep; /* copy data */
+ break;
+
+ case IIOCMODRULE:
+ if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
+ return (-EINVAL);
+ save_flags(flags);
+ cli();
+ *rulep = dioctl.getsetrule.rule; /* copy data */
+ restore_flags(flags);
+ return (0); /* no copy required */
+ break;
+
+ case IIOCINSRULE:
+ return (insertrule(dioctl.getsetrule.ruleidx, &dioctl.getsetrule.rule));
+ break;
+
+ case IIOCDELRULE:
+ return (deleterule(dioctl.getsetrule.ruleidx));
+ break;
+
+ case IIOCDODFACT:
+ return (deflect_extern_action(dioctl.fwd_ctrl.subcmd,
+ dioctl.fwd_ctrl.callid,
+ dioctl.fwd_ctrl.to_nr));
+
+ case IIOCDOCFACT:
+ case IIOCDOCFDIS:
+ case IIOCDOCFINT:
+ if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
+ return (-EINVAL); /* invalid driver */
+ if ((i = cf_command(dioctl.cf_ctrl.drvid,
+ (cmd == IIOCDOCFACT) ? 1 : (cmd == IIOCDOCFDIS) ? 0 : 2,
+ dioctl.cf_ctrl.cfproc,
+ dioctl.cf_ctrl.msn,
+ dioctl.cf_ctrl.service,
+ dioctl.cf_ctrl.fwd_nr,
+ &dioctl.cf_ctrl.procid)))
+ return (i);
+ break;
+
+ default:
+ return (-EINVAL);
+ } /* switch cmd */
+ return (copy_to_user((char *) arg, &dioctl, sizeof(dioctl))); /* success */
+} /* isdn_divert_ioctl */
#ifdef CONFIG_PROC_FS
@@ -282,79 +305,62 @@
isdn_divert_lseek,
isdn_divert_read,
isdn_divert_write,
- NULL, /* isdn_readdir */
- isdn_divert_poll, /* isdn_poll */
- isdn_divert_ioctl, /* isdn_ioctl */
- NULL, /* isdn_mmap */
+ NULL, /* isdn_readdir */
+ isdn_divert_poll, /* isdn_poll */
+ isdn_divert_ioctl, /* isdn_ioctl */
+ NULL, /* isdn_mmap */
isdn_divert_open,
- NULL, /* flush */
+ NULL, /* flush */
isdn_divert_close,
- NULL /* fsync */
-};
-
-struct inode_operations divert_file_inode_operations = {
- &isdn_fops, /* default proc file-ops */
- NULL, /* create */
- NULL, /* lookup */
- NULL, /* link */
- NULL, /* unlink */
- NULL, /* symlink */
- NULL, /* mkdir */
- NULL, /* rmdir */
- NULL, /* mknod */
- NULL, /* rename */
- NULL, /* readlink */
- NULL, /* follow_link */
- NULL, /* readpage */
- NULL, /* writepage */
- NULL, /* bmap */
- NULL, /* truncate */
- NULL /* permission */
+ NULL /* fsync */
};
+struct inode_operations divert_file_inode_operations;
/****************************/
/* isdn subdir in /proc/net */
/****************************/
static struct proc_dir_entry *isdn_proc_entry = NULL;
static struct proc_dir_entry *isdn_divert_entry = NULL;
-#endif CONFIG_PROC_FS
+#endif /* CONFIG_PROC_FS */
/***************************************************************************/
/* divert_dev_init must be called before the proc filesystem may be used */
/***************************************************************************/
-int divert_dev_init(void)
-{ int i;
+int
+divert_dev_init(void)
+{
#ifdef CONFIG_PROC_FS
- isdn_proc_entry = create_proc_entry("isdn", S_IFDIR | S_IRUGO | S_IXUGO ,proc_net);
- if (!isdn_proc_entry)
- return(-1);
- isdn_divert_entry = create_proc_entry("divert",S_IFREG | S_IRUGO,isdn_proc_entry);
- if (!isdn_divert_entry)
- {
- remove_proc_entry("isdn",proc_net);
- return(-1);
- }
- isdn_divert_entry->ops = &divert_file_inode_operations;
-#endif CONFIG_PROC_FS
+ isdn_proc_entry = create_proc_entry("isdn", S_IFDIR | S_IRUGO | S_IXUGO, proc_net);
+ if (!isdn_proc_entry)
+ return (-1);
+ isdn_divert_entry = create_proc_entry("divert", S_IFREG | S_IRUGO, isdn_proc_entry);
+ if (!isdn_divert_entry) {
+ remove_proc_entry("isdn", proc_net);
+ return (-1);
+ }
+ memset(&divert_file_inode_operations, 0, sizeof(struct inode_operations));
+ divert_file_inode_operations.default_file_ops = &isdn_fops;
+ isdn_divert_entry->ops = &divert_file_inode_operations;
+#endif /* CONFIG_PROC_FS */
- return(0);
-} /* divert_dev_init */
+ return (0);
+} /* divert_dev_init */
/***************************************************************************/
/* divert_dev_deinit must be called before leaving isdn when included as */
/* a module. */
/***************************************************************************/
-int divert_dev_deinit(void)
-{ int i;
+int
+divert_dev_deinit(void)
+{
#ifdef CONFIG_PROC_FS
- remove_proc_entry("divert",isdn_proc_entry);
- remove_proc_entry("isdn",proc_net);
-#endif CONFIG_PROC_FS
-
- return(0);
-} /* divert_dev_deinit */
+ remove_proc_entry("divert", isdn_proc_entry);
+ remove_proc_entry("isdn", proc_net);
+#endif /* CONFIG_PROC_FS */
+ return (0);
+} /* divert_dev_deinit */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)