OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [isdn/] [divert/] [divert_procfs.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* $Id: divert_procfs.c,v 1.1.1.1 2004-04-15 02:05:31 phoenix Exp $
2
 *
3
 * Filesystem handling for the diversion supplementary services.
4
 *
5
 * Copyright 1998       by Werner Cornelius (werner@isdn4linux.de)
6
 *
7
 * This software may be used and distributed according to the terms
8
 * of the GNU General Public License, incorporated herein by reference.
9
 *
10
 */
11
 
12
#include <linux/config.h>
13
#define __NO_VERSION__
14
#include <linux/module.h>
15
#include <linux/version.h>
16
#include <linux/poll.h>
17
#include <linux/smp_lock.h>
18
#ifdef CONFIG_PROC_FS
19
#include <linux/proc_fs.h>
20
#else
21
#include <linux/fs.h>
22
#endif
23
#include <linux/isdnif.h>
24
#include "isdn_divert.h"
25
 
26
/*********************************/
27
/* Variables for interface queue */
28
/*********************************/
29
ulong if_used = 0;               /* number of interface users */
30
static struct divert_info *divert_info_head = NULL;     /* head of queue */
31
static struct divert_info *divert_info_tail = NULL;     /* pointer to last entry */
32
static wait_queue_head_t rd_queue;
33
 
34
/*********************************/
35
/* put an info buffer into queue */
36
/*********************************/
37
void
38
put_info_buffer(char *cp)
39
{
40
        struct divert_info *ib;
41
        unsigned long flags;
42
 
43
        if (if_used <= 0)
44
                return;
45
        if (!cp)
46
                return;
47
        if (!*cp)
48
                return;
49
        if (!(ib = (struct divert_info *) kmalloc(sizeof(struct divert_info) + strlen(cp), GFP_ATOMIC)))
50
                 return;        /* no memory */
51
        strcpy(ib->info_start, cp);     /* set output string */
52
        ib->next = NULL;
53
        save_flags(flags);
54
        cli();
55
        ib->usage_cnt = if_used;
56
        if (!divert_info_head)
57
                divert_info_head = ib;  /* new head */
58
        else
59
                divert_info_tail->next = ib;    /* follows existing messages */
60
        divert_info_tail = ib;  /* new tail */
61
        restore_flags(flags);
62
 
63
        /* delete old entrys */
64
        while (divert_info_head->next) {
65
                if ((divert_info_head->usage_cnt <= 0) &&
66
                    (divert_info_head->next->usage_cnt <= 0)) {
67
                        ib = divert_info_head;
68
                        divert_info_head = divert_info_head->next;
69
                        kfree(ib);
70
                } else
71
                        break;
72
        }                       /* divert_info_head->next */
73
        wake_up_interruptible(&(rd_queue));
74
}                               /* put_info_buffer */
75
 
76
/**********************************/
77
/* deflection device read routine */
78
/**********************************/
79
static ssize_t
80
isdn_divert_read(struct file *file, char *buf, size_t count, loff_t * off)
81
{
82
        struct divert_info *inf;
83
        int len;
84
 
85
        if (!*((struct divert_info **) file->private_data)) {
86
                if (file->f_flags & O_NONBLOCK)
87
                        return -EAGAIN;
88
                interruptible_sleep_on(&(rd_queue));
89
        }
90
        if (!(inf = *((struct divert_info **) file->private_data)))
91
                return (0);
92
 
93
        inf->usage_cnt--;       /* new usage count */
94
        (struct divert_info **) file->private_data = &inf->next;        /* next structure */
95
        if ((len = strlen(inf->info_start)) <= count) {
96
                if (copy_to_user(buf, inf->info_start, len))
97
                        return -EFAULT;
98
                file->f_pos += len;
99
                return (len);
100
        }
101
        return (0);
102
}                               /* isdn_divert_read */
103
 
104
/**********************************/
105
/* deflection device write routine */
106
/**********************************/
107
static ssize_t
108
isdn_divert_write(struct file *file, const char *buf, size_t count, loff_t * off)
109
{
110
        return (-ENODEV);
111
}                               /* isdn_divert_write */
112
 
113
 
114
/***************************************/
115
/* select routines for various kernels */
116
/***************************************/
117
static unsigned int
118
isdn_divert_poll(struct file *file, poll_table * wait)
119
{
120
        unsigned int mask = 0;
121
 
122
        poll_wait(file, &(rd_queue), wait);
123
        /* mask = POLLOUT | POLLWRNORM; */
124
        if (*((struct divert_info **) file->private_data)) {
125
                mask |= POLLIN | POLLRDNORM;
126
        }
127
        return mask;
128
}                               /* isdn_divert_poll */
129
 
130
/****************/
131
/* Open routine */
132
/****************/
133
static int
134
isdn_divert_open(struct inode *ino, struct file *filep)
135
{
136
        unsigned long flags;
137
 
138
        lock_kernel();
139
        save_flags(flags);
140
        cli();
141
        if_used++;
142
        if (divert_info_head)
143
                (struct divert_info **) filep->private_data = &(divert_info_tail->next);
144
        else
145
                (struct divert_info **) filep->private_data = &divert_info_head;
146
        restore_flags(flags);
147
        /*  start_divert(); */
148
        unlock_kernel();
149
        return (0);
150
}                               /* isdn_divert_open */
151
 
152
/*******************/
153
/* close routine   */
154
/*******************/
155
static int
156
isdn_divert_close(struct inode *ino, struct file *filep)
157
{
158
        struct divert_info *inf;
159
        unsigned long flags;
160
 
161
        lock_kernel();
162
        save_flags(flags);
163
        cli();
164
        if_used--;
165
        inf = *((struct divert_info **) filep->private_data);
166
        while (inf) {
167
                inf->usage_cnt--;
168
                inf = inf->next;
169
        }
170
        restore_flags(flags);
171
        if (if_used <= 0)
172
                while (divert_info_head) {
173
                        inf = divert_info_head;
174
                        divert_info_head = divert_info_head->next;
175
                        kfree(inf);
176
                }
177
        unlock_kernel();
178
        return (0);
179
}                               /* isdn_divert_close */
180
 
181
/*********/
182
/* IOCTL */
183
/*********/
184
static int
185
isdn_divert_ioctl(struct inode *inode, struct file *file,
186
                  uint cmd, ulong arg)
187
{
188
        divert_ioctl dioctl;
189
        int i;
190
        unsigned long flags;
191
        divert_rule *rulep;
192
        char *cp;
193
 
194
        if ((i = copy_from_user(&dioctl, (char *) arg, sizeof(dioctl))))
195
                return (i);
196
 
197
        switch (cmd) {
198
                case IIOCGETVER:
199
                        dioctl.drv_version = DIVERT_IIOC_VERSION;       /* set version */
200
                        break;
201
 
202
                case IIOCGETDRV:
203
                        if ((dioctl.getid.drvid = divert_if.name_to_drv(dioctl.getid.drvnam)) < 0)
204
                                return (-EINVAL);
205
                        break;
206
 
207
                case IIOCGETNAM:
208
                        cp = divert_if.drv_to_name(dioctl.getid.drvid);
209
                        if (!cp)
210
                                return (-EINVAL);
211
                        if (!*cp)
212
                                return (-EINVAL);
213
                        strcpy(dioctl.getid.drvnam, cp);
214
                        break;
215
 
216
                case IIOCGETRULE:
217
                        if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
218
                                return (-EINVAL);
219
                        dioctl.getsetrule.rule = *rulep;        /* copy data */
220
                        break;
221
 
222
                case IIOCMODRULE:
223
                        if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
224
                                return (-EINVAL);
225
                        save_flags(flags);
226
                        cli();
227
                        *rulep = dioctl.getsetrule.rule;        /* copy data */
228
                        restore_flags(flags);
229
                        return (0);      /* no copy required */
230
                        break;
231
 
232
                case IIOCINSRULE:
233
                        return (insertrule(dioctl.getsetrule.ruleidx, &dioctl.getsetrule.rule));
234
                        break;
235
 
236
                case IIOCDELRULE:
237
                        return (deleterule(dioctl.getsetrule.ruleidx));
238
                        break;
239
 
240
                case IIOCDODFACT:
241
                        return (deflect_extern_action(dioctl.fwd_ctrl.subcmd,
242
                                                  dioctl.fwd_ctrl.callid,
243
                                                 dioctl.fwd_ctrl.to_nr));
244
 
245
                case IIOCDOCFACT:
246
                case IIOCDOCFDIS:
247
                case IIOCDOCFINT:
248
                        if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
249
                                return (-EINVAL);       /* invalid driver */
250
                        if ((i = cf_command(dioctl.cf_ctrl.drvid,
251
                                            (cmd == IIOCDOCFACT) ? 1 : (cmd == IIOCDOCFDIS) ? 0 : 2,
252
                                            dioctl.cf_ctrl.cfproc,
253
                                            dioctl.cf_ctrl.msn,
254
                                            dioctl.cf_ctrl.service,
255
                                            dioctl.cf_ctrl.fwd_nr,
256
                                            &dioctl.cf_ctrl.procid)))
257
                                return (i);
258
                        break;
259
 
260
                default:
261
                        return (-EINVAL);
262
        }                       /* switch cmd */
263
        return (copy_to_user((char *) arg, &dioctl, sizeof(dioctl)));   /* success */
264
}                               /* isdn_divert_ioctl */
265
 
266
 
267
#ifdef CONFIG_PROC_FS
268
static struct file_operations isdn_fops =
269
{
270
        llseek:         no_llseek,
271
        read:           isdn_divert_read,
272
        write:          isdn_divert_write,
273
        poll:           isdn_divert_poll,
274
        ioctl:          isdn_divert_ioctl,
275
        open:           isdn_divert_open,
276
        release:        isdn_divert_close,
277
};
278
 
279
/****************************/
280
/* isdn subdir in /proc/net */
281
/****************************/
282
static struct proc_dir_entry *isdn_proc_entry = NULL;
283
static struct proc_dir_entry *isdn_divert_entry = NULL;
284
#endif  /* CONFIG_PROC_FS */
285
 
286
/***************************************************************************/
287
/* divert_dev_init must be called before the proc filesystem may be used   */
288
/***************************************************************************/
289
int
290
divert_dev_init(void)
291
{
292
 
293
        init_waitqueue_head(&rd_queue);
294
 
295
#ifdef CONFIG_PROC_FS
296
        isdn_proc_entry = create_proc_entry("isdn", S_IFDIR | S_IRUGO | S_IXUGO, proc_net);
297
        if (!isdn_proc_entry)
298
                return (-1);
299
        isdn_divert_entry = create_proc_entry("divert", S_IFREG | S_IRUGO, isdn_proc_entry);
300
        if (!isdn_divert_entry) {
301
                remove_proc_entry("isdn", proc_net);
302
                return (-1);
303
        }
304
        isdn_divert_entry->proc_fops = &isdn_fops;
305
        isdn_divert_entry->owner = THIS_MODULE;
306
#endif  /* CONFIG_PROC_FS */
307
 
308
        return (0);
309
}                               /* divert_dev_init */
310
 
311
/***************************************************************************/
312
/* divert_dev_deinit must be called before leaving isdn when included as   */
313
/* a module.                                                               */
314
/***************************************************************************/
315
int
316
divert_dev_deinit(void)
317
{
318
 
319
#ifdef CONFIG_PROC_FS
320
        remove_proc_entry("divert", isdn_proc_entry);
321
        remove_proc_entry("isdn", proc_net);
322
#endif  /* CONFIG_PROC_FS */
323
 
324
        return (0);
325
}                               /* divert_dev_deinit */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.