|
|
1.1 root 1: #include <errno.h>
2:
3: #include <linux/sched.h>
4: #include <linux/kernel.h>
5:
6: extern int tty_read(unsigned minor,char * buf,int count);
7: extern int tty_write(unsigned minor,char * buf,int count);
8:
9: static int rw_ttyx(int rw,unsigned minor,char * buf,int count);
10: static int rw_tty(int rw,unsigned minor,char * buf,int count);
11:
12: typedef (*crw_ptr)(int rw,unsigned minor,char * buf,int count);
13:
14: #define NRDEVS ((sizeof (crw_table))/(sizeof (crw_ptr)))
15:
16: static crw_ptr crw_table[]={
17: NULL, /* nodev */
18: NULL, /* /dev/mem */
19: NULL, /* /dev/fd */
20: NULL, /* /dev/hd */
21: rw_ttyx, /* /dev/ttyx */
22: rw_tty, /* /dev/tty */
23: NULL, /* /dev/lp */
24: NULL}; /* unnamed pipes */
25:
26: static int rw_ttyx(int rw,unsigned minor,char * buf,int count)
27: {
28: return ((rw==READ)?tty_read(minor,buf,count):
29: tty_write(minor,buf,count));
30: }
31:
32: static int rw_tty(int rw,unsigned minor,char * buf,int count)
33: {
34: if (current->tty<0)
35: return -EPERM;
36: return rw_ttyx(rw,current->tty,buf,count);
37: }
38:
39: int rw_char(int rw,int dev, char * buf, int count)
40: {
41: crw_ptr call_addr;
42:
43: if (MAJOR(dev)>=NRDEVS)
44: panic("rw_char: dev>NRDEV");
45: if (!(call_addr=crw_table[MAJOR(dev)])) {
46: printk("dev: %04x\n",dev);
47: panic("Trying to r/w from/to nonexistent character device");
48: }
49: return call_addr(rw,MINOR(dev),buf,count);
50: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.