This source file includes following definitions.
- tty_read
- tty_write
- inb
- get_fs_byte
- panic
- printk
- panic
- MINOR
1
2
3
4
5
6
7 #include <errno.h>
8 #include <sys/types.h>
9
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12
13 #include <asm/segment.h>
14 #include <asm/io.h>
15
16 extern int tty_read(unsigned minor,char * buf,int count);
17 extern int tty_write(unsigned minor,char * buf,int count);
18
19 typedef (*crw_ptr)(int rw,unsigned minor,char * buf,int count,off_t * pos);
20
21 static int rw_ttyx(int rw,unsigned minor,char * buf,int count,off_t * pos)
22 {
23 return ((rw==READ)?tty_read(minor,buf,count):
24 tty_write(minor,buf,count));
25 }
26
27 static int rw_tty(int rw,unsigned minor,char * buf,int count, off_t * pos)
28 {
29 if (current->tty<0)
30 return -EPERM;
31 return rw_ttyx(rw,current->tty,buf,count,pos);
32 }
33
34 static int rw_ram(int rw,char * buf, int count, off_t *pos)
35 {
36 return -EIO;
37 }
38
39 static int rw_mem(int rw,char * buf, int count, off_t * pos)
40 {
41 return -EIO;
42 }
43
44 static int rw_kmem(int rw,char * buf, int count, off_t * pos)
45 {
46 return -EIO;
47 }
48
49 static int rw_port(int rw,char * buf, int count, off_t * pos)
50 {
51 int i=*pos;
52
53 while (count-->0 && i<65536) {
54 if (rw==READ)
55 put_fs_byte(inb(i),buf++);
56 else
57 outb(get_fs_byte(buf++),i);
58 i++;
59 }
60 i -= *pos;
61 *pos += i;
62 return i;
63 }
64
65 static int rw_memory(int rw, unsigned minor, char * buf, int count, off_t * pos)
66 {
67 switch(minor) {
68 case 0:
69 return rw_ram(rw,buf,count,pos);
70 case 1:
71 return rw_mem(rw,buf,count,pos);
72 case 2:
73 return rw_kmem(rw,buf,count,pos);
74 case 3:
75 return (rw==READ)?0:count;
76 case 4:
77 return rw_port(rw,buf,count,pos);
78 default:
79 return -EIO;
80 }
81 }
82
83 #define NRDEVS ((sizeof (crw_table))/(sizeof (crw_ptr)))
84
85 static crw_ptr crw_table[]={
86 NULL,
87 rw_memory,
88 NULL,
89 NULL,
90 rw_ttyx,
91 rw_tty,
92 NULL,
93 NULL};
94
95 int rw_char(int rw,int dev, char * buf, int count, off_t * pos)
96 {
97 crw_ptr call_addr;
98
99 if (MAJOR(dev)>=NRDEVS)
100 panic("rw_char: dev>NRDEV");
101 if (!(call_addr=crw_table[MAJOR(dev)])) {
102 printk("dev: %04x\n",dev);
103 panic("Trying to r/w from/to nonexistent character device");
104 }
105 return call_addr(rw,MINOR(dev),buf,count,pos);
106 }