|
|
1.1 root 1: #include <errno.h>
2: #include <termios.h>
3:
4: #include <linux/sched.h>
5: #include <linux/kernel.h>
6: #include <linux/tty.h>
7:
8: #include <asm/segment.h>
9: #include <asm/system.h>
10:
11: static void flush(struct tty_queue * queue)
12: {
13: cli();
14: queue->head = queue->tail;
15: sti();
16: }
17:
18: static void wait_until_sent(struct tty_struct * tty)
19: {
20: /* do nothing - not implemented */
21: }
22:
23: static void send_break(struct tty_struct * tty)
24: {
25: /* do nothing - not implemented */
26: }
27:
28: static int get_termios(struct tty_struct * tty, struct termios * termios)
29: {
30: int i;
31:
32: verify_area(termios, sizeof (*termios));
33: for (i=0 ; i< (sizeof (*termios)) ; i++)
34: put_fs_byte( ((char *)&tty->termios)[i] , i+(char *)termios );
35: return 0;
36: }
37:
38: static int set_termios(struct tty_struct * tty, struct termios * termios)
39: {
40: int i;
41:
42: for (i=0 ; i< (sizeof (*termios)) ; i++)
43: ((char *)&tty->termios)[i]=get_fs_byte(i+(char *)termios);
44: return 0;
45: }
46:
47: static int get_termio(struct tty_struct * tty, struct termio * termio)
48: {
49: int i;
50: struct termio tmp_termio;
51:
52: verify_area(termio, sizeof (*termio));
53: tmp_termio.c_iflag = tty->termios.c_iflag;
54: tmp_termio.c_oflag = tty->termios.c_oflag;
55: tmp_termio.c_cflag = tty->termios.c_cflag;
56: tmp_termio.c_lflag = tty->termios.c_lflag;
57: tmp_termio.c_line = tty->termios.c_line;
58: for(i=0 ; i < NCC ; i++)
59: tmp_termio.c_cc[i] = tty->termios.c_cc[i];
60: for (i=0 ; i< (sizeof (*termio)) ; i++)
61: put_fs_byte( ((char *)&tmp_termio)[i] , i+(char *)termio );
62: return 0;
63: }
64:
65: static int set_termio(struct tty_struct * tty, struct termio * termio)
66: {
67: int i;
68: struct termio tmp_termio;
69:
70: for (i=0 ; i< (sizeof (*termio)) ; i++)
71: ((char *)&tmp_termio)[i]=get_fs_byte(i+(char *)termio);
72: *(unsigned short *)&tty->termios.c_iflag = tmp_termio.c_iflag;
73: *(unsigned short *)&tty->termios.c_oflag = tmp_termio.c_oflag;
74: *(unsigned short *)&tty->termios.c_cflag = tmp_termio.c_cflag;
75: *(unsigned short *)&tty->termios.c_lflag = tmp_termio.c_lflag;
76: tty->termios.c_line = tmp_termio.c_line;
77: for(i=0 ; i < NCC ; i++)
78: tty->termios.c_cc[i] = tmp_termio.c_cc[i];
79: return 0;
80: }
81:
82: int tty_ioctl(int dev, int cmd, int arg)
83: {
84: struct tty_struct * tty;
85: if (MAJOR(dev) == 5) {
86: dev=current->tty;
87: if (dev<0)
88: panic("tty_ioctl: dev<0");
89: } else
90: dev=MINOR(dev);
91: tty = dev + tty_table;
92: switch (cmd) {
93: case TCGETS:
94: return get_termios(tty,(struct termios *) arg);
95: case TCSETSF:
96: flush(&tty->read_q); /* fallthrough */
97: case TCSETSW:
98: wait_until_sent(tty); /* fallthrough */
99: case TCSETS:
100: return set_termios(tty,(struct termios *) arg);
101: case TCGETA:
102: return get_termio(tty,(struct termio *) arg);
103: case TCSETAF:
104: flush(&tty->read_q); /* fallthrough */
105: case TCSETAW:
106: wait_until_sent(tty); /* fallthrough */
107: case TCSETA:
108: return set_termio(tty,(struct termio *) arg);
109: case TCSBRK:
110: if (!arg) {
111: wait_until_sent(tty);
112: send_break(tty);
113: }
114: return 0;
115: case TCXONC:
116: return -EINVAL; /* not implemented */
117: case TCFLSH:
118: if (arg==0)
119: flush(&tty->read_q);
120: else if (arg==1)
121: flush(&tty->write_q);
122: else if (arg==2) {
123: flush(&tty->read_q);
124: flush(&tty->write_q);
125: } else
126: return -EINVAL;
127: return 0;
128: case TIOCEXCL:
129: return -EINVAL; /* not implemented */
130: case TIOCNXCL:
131: return -EINVAL; /* not implemented */
132: case TIOCSCTTY:
133: return -EINVAL; /* set controlling term NI */
134: case TIOCGPGRP:
135: verify_area((void *) arg,4);
136: put_fs_long(tty->pgrp,(unsigned long *) arg);
137: return 0;
138: case TIOCSPGRP:
139: tty->pgrp=get_fs_long((unsigned long *) arg);
140: return 0;
141: case TIOCOUTQ:
142: verify_area((void *) arg,4);
143: put_fs_long(CHARS(tty->write_q),(unsigned long *) arg);
144: return 0;
145: case TIOCSTI:
146: return -EINVAL; /* not implemented */
147: case TIOCGWINSZ:
148: return -EINVAL; /* not implemented */
149: case TIOCSWINSZ:
150: return -EINVAL; /* not implemented */
151: case TIOCMGET:
152: return -EINVAL; /* not implemented */
153: case TIOCMBIS:
154: return -EINVAL; /* not implemented */
155: case TIOCMBIC:
156: return -EINVAL; /* not implemented */
157: case TIOCMSET:
158: return -EINVAL; /* not implemented */
159: case TIOCGSOFTCAR:
160: return -EINVAL; /* not implemented */
161: case TIOCSSOFTCAR:
162: return -EINVAL; /* not implemented */
163: default:
164: return -EINVAL;
165: }
166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.