]> granicus.if.org Git - strace/blob - term.c
mtd: clamp ubi name strings
[strace] / term.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "defs.h"
29 /*
30  * The C library's definition of struct termios might differ from
31  * the kernel one, and we need to use the kernel layout.
32  */
33 #include <linux/termios.h>
34 #ifdef HAVE_SYS_FILIO_H
35 # include <sys/filio.h>
36 #endif
37
38 static const struct xlat tcxonc_options[] = {
39         { TCOOFF,       "TCOOFF"        },
40         { TCOON,        "TCOON"         },
41         { TCIOFF,       "TCIOFF"        },
42         { TCION,        "TCION"         },
43         { 0,            NULL            },
44 };
45
46 #ifdef TCLFLSH
47 static const struct xlat tcflsh_options[] = {
48         { TCIFLUSH,     "TCIFLUSH"      },
49         { TCOFLUSH,     "TCOFLUSH"      },
50         { TCIOFLUSH,    "TCIOFLUSH"     },
51         { 0,            NULL            },
52 };
53 #endif
54
55 static const struct xlat baud_options[] = {
56         { B0,           "B0"            },
57         { B50,          "B50"           },
58         { B75,          "B75"           },
59         { B110,         "B110"          },
60         { B134,         "B134"          },
61         { B150,         "B150"          },
62         { B200,         "B200"          },
63         { B300,         "B300"          },
64         { B600,         "B600"          },
65         { B1200,        "B1200"         },
66         { B1800,        "B1800"         },
67         { B2400,        "B2400"         },
68         { B4800,        "B4800"         },
69         { B9600,        "B9600"         },
70 #ifdef B19200
71         { B19200,       "B19200"        },
72 #endif
73 #ifdef B38400
74         { B38400,       "B38400"        },
75 #endif
76 #ifdef B57600
77         { B57600,       "B57600"        },
78 #endif
79 #ifdef B115200
80         { B115200,      "B115200"       },
81 #endif
82 #ifdef B230400
83         { B230400,      "B230400"       },
84 #endif
85 #ifdef B460800
86         { B460800,      "B460800"       },
87 #endif
88 #ifdef B500000
89         { B500000,      "B500000"       },
90 #endif
91 #ifdef B576000
92         { B576000,      "B576000"       },
93 #endif
94 #ifdef B921600
95         { B921600,      "B921600"       },
96 #endif
97 #ifdef B1000000
98         { B1000000,     "B1000000"      },
99 #endif
100 #ifdef B1152000
101         { B1152000,     "B1152000"      },
102 #endif
103 #ifdef B1500000
104         { B1500000,     "B1500000"      },
105 #endif
106 #ifdef B2000000
107         { B2000000,     "B2000000"      },
108 #endif
109 #ifdef B2500000
110         { B2500000,     "B2500000"      },
111 #endif
112 #ifdef B3000000
113         { B3000000,     "B3000000"      },
114 #endif
115 #ifdef B3500000
116         { B3500000,     "B3500000"      },
117 #endif
118 #ifdef B4000000
119         { B4000000,     "B4000000"      },
120 #endif
121 #ifdef EXTA
122         { EXTA,         "EXTA"          },
123 #endif
124 #ifdef EXTB
125         { EXTB,         "EXTB"          },
126 #endif
127         { 0,            NULL            },
128 };
129
130 static const struct xlat modem_flags[] = {
131 #ifdef TIOCM_LE
132         { TIOCM_LE,     "TIOCM_LE",     },
133 #endif
134 #ifdef TIOCM_DTR
135         { TIOCM_DTR,    "TIOCM_DTR",    },
136 #endif
137 #ifdef TIOCM_RTS
138         { TIOCM_RTS,    "TIOCM_RTS",    },
139 #endif
140 #ifdef TIOCM_ST
141         { TIOCM_ST,     "TIOCM_ST",     },
142 #endif
143 #ifdef TIOCM_SR
144         { TIOCM_SR,     "TIOCM_SR",     },
145 #endif
146 #ifdef TIOCM_CTS
147         { TIOCM_CTS,    "TIOCM_CTS",    },
148 #endif
149 #ifdef TIOCM_CAR
150         { TIOCM_CAR,    "TIOCM_CAR",    },
151 #endif
152 #ifdef TIOCM_CD
153         { TIOCM_CD,     "TIOCM_CD",     },
154 #endif
155 #ifdef TIOCM_RNG
156         { TIOCM_RNG,    "TIOCM_RNG",    },
157 #endif
158 #ifdef TIOCM_RI
159         { TIOCM_RI,     "TIOCM_RI",     },
160 #endif
161 #ifdef TIOCM_DSR
162         { TIOCM_DSR,    "TIOCM_DSR",    },
163 #endif
164         { 0,            NULL,           },
165 };
166
167 int term_ioctl(struct tcb *tcp, long code, long arg)
168 {
169         struct termios tios;
170         struct termio tio;
171         struct winsize ws;
172 #ifdef TIOCGSIZE
173         struct  ttysize ts;
174 #endif
175         int i;
176
177         if (entering(tcp))
178                 return 0;
179
180         switch (code) {
181
182         /* ioctls with termios or termio args */
183
184 #ifdef TCGETS
185         case TCGETS:
186                 if (syserror(tcp))
187                         return 0;
188         case TCSETS:
189         case TCSETSW:
190         case TCSETSF:
191                 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
192                         return 0;
193                 if (abbrev(tcp)) {
194                         tprints(", {");
195                         printxval(baud_options, tios.c_cflag & CBAUD, "B???");
196                         tprintf(" %sopost %sisig %sicanon %secho ...}",
197                                 (tios.c_oflag & OPOST) ? "" : "-",
198                                 (tios.c_lflag & ISIG) ? "" : "-",
199                                 (tios.c_lflag & ICANON) ? "" : "-",
200                                 (tios.c_lflag & ECHO) ? "" : "-");
201                         return 1;
202                 }
203                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
204                         (long) tios.c_iflag, (long) tios.c_oflag);
205                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
206                         (long) tios.c_cflag, (long) tios.c_lflag);
207                 tprintf("c_line=%u, ", tios.c_line);
208                 if (!(tios.c_lflag & ICANON))
209                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
210                                 tios.c_cc[VMIN], tios.c_cc[VTIME]);
211                 tprintf("c_cc=\"");
212                 for (i = 0; i < NCCS; i++)
213                         tprintf("\\x%02x", tios.c_cc[i]);
214                 tprintf("\"}");
215                 return 1;
216 #endif /* TCGETS */
217
218 #ifdef TCGETA
219         case TCGETA:
220                 if (syserror(tcp))
221                         return 0;
222         case TCSETA:
223         case TCSETAW:
224         case TCSETAF:
225                 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
226                         return 0;
227                 if (abbrev(tcp)) {
228                         tprints(", {");
229                         printxval(baud_options, tio.c_cflag & CBAUD, "B???");
230                         tprintf(" %sopost %sisig %sicanon %secho ...}",
231                                 (tio.c_oflag & OPOST) ? "" : "-",
232                                 (tio.c_lflag & ISIG) ? "" : "-",
233                                 (tio.c_lflag & ICANON) ? "" : "-",
234                                 (tio.c_lflag & ECHO) ? "" : "-");
235                         return 1;
236                 }
237                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
238                         (long) tio.c_iflag, (long) tio.c_oflag);
239                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
240                         (long) tio.c_cflag, (long) tio.c_lflag);
241                 tprintf("c_line=%u, ", tio.c_line);
242 #ifdef _VMIN
243                 if (!(tio.c_lflag & ICANON))
244                         tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
245                                 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
246 #else /* !_VMIN */
247                 if (!(tio.c_lflag & ICANON))
248                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
249                                 tio.c_cc[VMIN], tio.c_cc[VTIME]);
250 #endif /* !_VMIN */
251                 tprintf("c_cc=\"");
252                 for (i = 0; i < NCC; i++)
253                         tprintf("\\x%02x", tio.c_cc[i]);
254                 tprintf("\"}");
255                 return 1;
256 #endif /* TCGETA */
257
258         /* ioctls with winsize or ttysize args */
259
260 #ifdef TIOCGWINSZ
261         case TIOCGWINSZ:
262                 if (syserror(tcp))
263                         return 0;
264         case TIOCSWINSZ:
265                 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
266                         return 0;
267                 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
268                         ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
269                 return 1;
270 #endif /* TIOCGWINSZ */
271
272 #ifdef TIOCGSIZE
273         case TIOCGSIZE:
274                 if (syserror(tcp))
275                         return 0;
276         case TIOCSSIZE:
277                 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
278                         return 0;
279                 tprintf(", {ts_lines=%d, ts_cols=%d}",
280                         ts.ts_lines, ts.ts_cols);
281                 return 1;
282 #endif
283
284         /* ioctls with a direct decodable arg */
285 #ifdef TCXONC
286         case TCXONC:
287                 tprints(", ");
288                 printxval(tcxonc_options, arg, "TC???");
289                 return 1;
290 #endif
291 #ifdef TCLFLSH
292         case TCFLSH:
293                 tprints(", ");
294                 printxval(tcflsh_options, arg, "TC???");
295                 return 1;
296 #endif
297 #ifdef TIOCSCTTY
298         case TIOCSCTTY:
299                 tprintf(", %ld", arg);
300                 return 1;
301 #endif
302
303         /* ioctls with an indirect parameter displayed as modem flags */
304
305 #ifdef TIOCMGET
306         case TIOCMGET:
307         case TIOCMBIS:
308         case TIOCMBIC:
309         case TIOCMSET:
310                 if (umove(tcp, arg, &i) < 0)
311                         return 0;
312                 tprints(", [");
313                 printflags(modem_flags, i, "TIOCM_???");
314                 tprints("]");
315                 return 1;
316 #endif /* TIOCMGET */
317
318         /* ioctls with an indirect parameter displayed in decimal */
319
320         case TIOCSPGRP:
321         case TIOCGPGRP:
322 #ifdef TIOCGETPGRP
323         case TIOCGETPGRP:
324 #endif
325 #ifdef TIOCSETPGRP
326         case TIOCSETPGRP:
327 #endif
328 #ifdef FIONREAD
329         case FIONREAD:
330 #endif
331         case TIOCOUTQ:
332 #ifdef FIONBIO
333         case FIONBIO:
334 #endif
335 #ifdef FIOASYNC
336         case FIOASYNC:
337 #endif
338 #ifdef FIOGETOWN
339         case FIOGETOWN:
340 #endif
341 #ifdef FIOSETOWN
342         case FIOSETOWN:
343 #endif
344 #ifdef TIOCGETD
345         case TIOCGETD:
346 #endif
347 #ifdef TIOCSETD
348         case TIOCSETD:
349 #endif
350 #ifdef TIOCPKT
351         case TIOCPKT:
352 #endif
353 #ifdef TIOCREMOTE
354         case TIOCREMOTE:
355 #endif
356 #ifdef TIOCUCNTL
357         case TIOCUCNTL:
358 #endif
359 #ifdef TIOCTCNTL
360         case TIOCTCNTL:
361 #endif
362 #ifdef TIOCSIGNAL
363         case TIOCSIGNAL:
364 #endif
365 #ifdef TIOCSSOFTCAR
366         case TIOCSSOFTCAR:
367 #endif
368 #ifdef TIOCGSOFTCAR
369         case TIOCGSOFTCAR:
370 #endif
371 #ifdef TIOCISPACE
372         case TIOCISPACE:
373 #endif
374 #ifdef TIOCISIZE
375         case TIOCISIZE:
376 #endif
377 #ifdef TIOCSINTR
378         case TIOCSINTR:
379 #endif
380 #ifdef TIOCSPTLCK
381         case TIOCSPTLCK:
382 #endif
383 #ifdef TIOCGPTN
384         case TIOCGPTN:
385 #endif
386                 tprints(", ");
387                 printnum_int(tcp, arg, "%d");
388                 return 1;
389
390         /* ioctls with an indirect parameter displayed as a char */
391
392 #ifdef TIOCSTI
393         case TIOCSTI:
394 #endif
395                 tprints(", ");
396                 printstr(tcp, arg, 1);
397                 return 1;
398
399         /* ioctls with no parameters */
400
401 #ifdef TIOCNOTTY
402         case TIOCNOTTY:
403 #endif
404 #ifdef FIOCLEX
405         case FIOCLEX:
406 #endif
407 #ifdef FIONCLEX
408         case FIONCLEX:
409 #endif
410 #ifdef TIOCCONS
411         case TIOCCONS:
412 #endif
413                 return 1;
414
415         /* ioctls which are unknown */
416
417         default:
418                 return 0;
419         }
420 }