devela/sys/os/linux/consts/ioctl.rs
1// devela::sys::os::linux::consts::ioctl
2//
3//! Linux `ioctl` constants.
4//
5// https://man7.org/linux/man-pages/man4/tty_ioctl.4.html
6
7use core::ffi::{c_int, c_ulong};
8
9/// Linux `ioctl` constants.
10#[allow(non_camel_case_types)]
11pub struct LINUX_IOCTL;
12
13/// # Get and set terminal attributes
14/// ---
15impl LINUX_IOCTL {
16 /// Get the current serial port settings.
17 ///
18 /// Argument: struct termios *argp
19 pub const TCGETS: c_ulong = 0x5401;
20
21 /// Set the current serial port settings.
22 ///
23 /// Argument: const struct termios *argp
24 pub const TCSETS: c_ulong = 0x5402;
25
26 /// Allow the output buffer to drain, and set the current serial port settings.
27 ///
28 /// Argument: const struct termios *argp
29 pub const TCSETSW: c_ulong = 0x5403;
30
31 /// Allow the output buffer to drain, discard pending input,
32 /// and set the current serial port settings.
33 ///
34 /// Argument: const struct termios *argp
35 pub const TCSETSF: c_ulong = 0x5404;
36
37 // The following four ioctls, added in Linux 2.6.20, are just like TCGETS,
38 // TCSETS, TCSETSW, TCSETSF, except that they take a struct termios2 *
39 // instead of a struct termios *.
40
41 /// Get the current serial port settings. (*termios2*)
42 ///
43 /// Argument: struct termios2 *argp
44 pub const TCGETS2: c_ulong = 0x802c_542a;
45
46 /// Set the current serial port settings. (*termios2*)
47 ///
48 /// Argument: const struct termios2 *argp
49 pub const TCSETS2: c_ulong = 0x402c_542b;
50
51 /// Allow the output buffer to drain, and set the current serial port settings.
52 /// (*termios2*)
53 ///
54 /// Argument: const struct termios2 *argp
55 pub const TCSETSW2: c_ulong = 0x402c_542c;
56
57 /// Allow the output buffer to drain, discard pending input,
58 /// and set the current serial port settings. (*termios2*)
59 ///
60 /// Argument: const struct termios2 *argp
61 pub const TCSETSF2: c_ulong = 0x402c_542d;
62
63 // The following four ioctls are just like TCGETS, TCSETS, TCSETSW, TCSETSF,
64 // except that they take a struct termio * instead of a struct termios *.
65
66 /// Get the current serial port settings. (*termio*)
67 ///
68 /// Argument: struct termio *argp
69 pub const TCGETA: c_ulong = 0x5405;
70
71 /// Set the current serial port settings. (*termio*)
72 ///
73 /// Argument: const struct termio *argp
74 pub const TCSETA: c_ulong = 0x5406;
75
76 /// Allow the output buffer to drain, and set the current serial port settings.
77 /// (*termio*)
78 ///
79 /// Argument: const struct termio *argp
80 pub const TCSETAW: c_ulong = 0x5407;
81
82 /// Allow the output buffer to drain, discard pending input,
83 /// and set the current serial port settings. (*termio*)
84 ///
85 /// Argument: const struct termio *argp
86 pub const TCSETAF: c_ulong = 0x5408;
87}
88
89/// # Software flow control
90/// ---
91impl LINUX_IOCTL {
92 /// Equivalent to tcflow(fd, arg).
93 ///
94 /// Argument: int arg
95 ///
96 /// See tcflow(3) for the argument values [`TCOOFF`][Self::TCOOFF],
97 /// [`TCOON`][Self::TCOON], [`TCIOFF`][Self::TCIOFF], [`TCION`][Self::TCION].
98 pub const TCXONC: c_ulong = 0x540A;
99
100 /// Suspends output.
101 pub const TCOOFF: c_int = 0;
102 /// Resumes suspended output.
103 pub const TCOON: c_int = 1;
104 /// Sends a STOP character to the terminal, to stop the terminal from sending
105 /// any further input.
106 pub const TCIOFF: c_int = 2;
107 /// Sends a START character to the terminal, to tell the terminal that it can
108 /// resume sending input.
109 pub const TCION: c_int = 3;
110}
111
112/// # Exclusive mode
113/// ---
114impl LINUX_IOCTL {
115 /// Put the terminal into exclusive mode.
116 ///
117 /// No further open(2) operations on the terminal are permitted. (They fail
118 /// with EBUSY, except for a process with the `CAP_SYS_ADMIN` capability.)
119 pub const TIOCEXCL: c_ulong = 0x540C;
120
121 /// Disable exclusive mode.
122 pub const TIOCNXCL: c_ulong = 0x540D;
123
124 /// (since Linux 3.8) If the terminal is currently in exclusive mode, place
125 /// a nonzero value in the location pointed to by argp; otherwise, place
126 /// zero in *argp.
127 pub const TIOCGEXCL: c_ulong = 0x8004_5440;
128}
129
130/// # Faking input
131/// ---
132impl LINUX_IOCTL {
133 /// Insert the given byte in the input queue.
134 ///
135 /// Argument: const char *argp
136 pub const TIOCSTI: c_ulong = 0x5412;
137}
138
139/// # Get and set window size
140/// ---
141impl LINUX_IOCTL {
142 /// Get window size.
143 ///
144 /// Argument: struct winsize *argp
145 pub const TIOCGWINSZ: c_ulong = 0x5413;
146
147 /// Set window size.
148 ///
149 /// Argument: const struct winsize *argp
150 pub const TIOCSWINSZ: c_ulong = 0x5414;
151}
152
153/// # Modem control
154/// ---
155impl LINUX_IOCTL {
156 /// Get the status of modem bits.
157 ///
158 /// Argument: int *argp
159 pub const TIOCMGET: c_ulong = 0x5415;
160
161 /// Set the indicated modem bits.
162 ///
163 /// Argument: const int *argp
164 pub const TIOCMBIS: c_ulong = 0x5416;
165
166 /// Clear the indicated modem bits.
167 ///
168 /// Argument: const int *argp
169 pub const TIOCMBIC: c_ulong = 0x5417;
170
171 /// Set the status of modem bits.
172 ///
173 /// Argument: const int *argp
174 pub const TIOCMSET: c_ulong = 0x5418;
175
176 /// DSR (data set ready/line enable)
177 pub const TIOCM_LE: c_int = 0x001;
178 /// DTR (data terminal ready)
179 pub const TIOCM_DTR: c_int = 0x002;
180 /// RTS (request to send)
181 pub const TIOCM_RTS: c_int = 0x004;
182 /// Secondary TXD (transmit)
183 pub const TIOCM_ST: c_int = 0x008;
184 /// Secondary RXD (receive)
185 pub const TIOCM_SR: c_int = 0x010;
186 /// CTS (clear to send)
187 pub const TIOCM_CTS: c_int = 0x020;
188 /// DCD (data carrier detect)
189 pub const TIOCM_CAR: c_int = 0x040;
190 /// see [`TIOCM_CAR`][Self::TIOCM_CAR]
191 pub const TIOCM_CD: c_int = Self::TIOCM_CAR;
192 /// RNG (ring)
193 pub const TIOCM_RNG: c_int = 0x080;
194 /// see [`TIOCM_RNG`][Self::TIOCM_RNG]
195 pub const TIOCM_RI: c_int = Self::TIOCM_RNG;
196 /// DSR (data set ready)
197 pub const TIOCM_DSR: c_int = 0x100;
198}
199
200/// # Marking a line as local
201/// ---
202impl LINUX_IOCTL {
203 /// ("Get software carrier flag")
204 ///
205 /// Get the status of the `CLOCAL` flag in the `c_cflag` field of the termios
206 /// structure.
207 ///
208 /// Argument: int *argp
209 pub const TIOCGSOFTCAR: c_ulong = 0x5419;
210
211 /// ("Set software carrier flag")
212 ///
213 /// Set the `CLOCAL` flag in the termios structure when `*argp` is nonzero, and
214 /// clear it otherwise.
215 ///
216 /// Argument: const int *argp
217 pub const TIOCSSOFTCAR: c_ulong = 0x541A;
218}
219
220/// # Buffer count and flushing
221/// ---
222impl LINUX_IOCTL {
223 /// Get the number of bytes in the input buffer.
224 pub const FIONREAD: c_ulong = 0x541B;
225
226 /// Same as [`FIONREAD`][Self::FIONREAD].
227 pub const TIOCINQ: c_ulong = Self::FIONREAD;
228
229 /// Get the number of bytes in the output buffer.
230 pub const TIOCOUTQ: c_ulong = 0x5411;
231
232 /// See tcflush(3) for the argument values `TCIFLUSH`, `TCOFLUSH`, `TCIOFLUSH`.
233 ///
234 /// Equivalent to tcflush(fd, arg).
235 pub const TCFLSH: c_ulong = 0x540B;
236
237 /// Get line status register.
238 ///
239 /// Status register has `TIOCSER_TEMT` bit set when output buffer is empty and
240 /// also hardware transmitter is physically empty.
241 pub const TIOCSERGETLSR: c_ulong = 0x5459;
242}
243
244/// # Linux-specific
245/// ---
246impl LINUX_IOCTL {
247 /// Linux-specific ioctls.
248 ///
249 /// The action of the following ioctls depends on the first byte in
250 /// the struct pointed to by argp, referred to here as the subcode.
251 /// These are legal only for the superuser or the owner of the
252 /// current terminal. Symbolic subcodes are available in
253 /// <linux/tiocl.h> since Linux 2.5.71.
254 ///
255 /// See <https://man7.org/linux/man-pages/man2/ioctl_console.2.html>.
256 pub const TIOCLINUX: c_ulong = 0x541C;
257}
258
259/// # Redirecting console output
260/// ---
261impl LINUX_IOCTL {
262 /// Redirect output that would have gone to `/dev/console` or `/dev/tty0` to
263 /// the given terminal.
264 ///
265 /// Argument: void
266 ///
267 /// If that was a pseudoterminal master, send it to the slave. Before Linux
268 /// 2.6.10, anybody can do this as long as the output was not redirected
269 /// yet; since Linux 2.6.10, only a process with the `CAP_SYS_ADMIN`
270 /// capability may do this. If output was redirected already, then EBUSY is
271 /// returned, but redirection can be stopped by using this ioctl with fd
272 /// pointing at /dev/console or /dev/tty0.
273 pub const TIOCCONS: c_ulong = 0x541D;
274}
275
276/// # Pseudoterminal ioctls
277/// ---
278impl LINUX_IOCTL {
279 /// Enable (when *argp is nonzero) or disable packet mode.
280 ///
281 /// Argument: const int *argp
282 ///
283 /// Can be applied to the master side of a pseudoterminal only (and will
284 /// return ENOTTY otherwise).
285 ///
286 /// In packet mode, each subsequent read(2) will return a packet that either
287 /// contains a single nonzero control byte, or has a single byte containing
288 /// zero ('\0') followed by data written on the slave side of the
289 /// pseudoterminal.
290 ///
291 /// If the first byte is not TIOCPKT_DATA (0), it is an OR of one or more of
292 /// the following bits:
293 ///
294 /// - `TIOCPKT_FLUSHREAD` The read queue for the terminal is flushed.
295 /// - `TIOCPKT_FLUSHWRITE` The write queue for the terminal is flushed.
296 /// - `TIOCPKT_STOP` Output to the terminal is stopped.
297 /// - `TIOCPKT_START` Output to the terminal is restarted.
298 /// - `TIOCPKT_DOSTOP` The start and stop characters are ^S/^Q.
299 /// - `TIOCPKT_NOSTOP` The start and stop characters are not ^S/^Q.
300 pub const TIOCPKT: c_ulong = 0x5420;
301
302 /// Set (if *argp is nonzero) or remove (if *argp is zero) the lock on the
303 /// pseudoterminal slave device.
304 ///
305 /// Argument: int *argp
306 pub const TIOCSPTLCK: c_ulong = 0x4004_5431;
307
308 /// Return the current packet mode setting in the integer pointed to by
309 /// argp.
310 ///
311 /// Argument: const int *argp
312 pub const TIOCGPKT: c_ulong = 0x8004_5438;
313
314 /// Place the current lock state of the pseudoterminal slave device in the
315 /// location pointed to by argp.
316 ///
317 /// Argument: int *argp
318 pub const TIOCGPTLCK: c_ulong = 0x8004_5439;
319
320 /// Open and return a new file descriptor that refers to the peer
321 /// pseudoterminal slave device.
322 ///
323 /// Argument: int flags
324 ///
325 /// Given a file descriptor in fd that refers to a pseudoterminal master,
326 /// open (with the given open(2)-style flags) and return a new file
327 /// descriptor that refers to the peer pseudoterminal slave device.
328 ///
329 /// This operation can be performed regardless of whether the pathname of
330 /// the slave device is accessible through the calling process's mount
331 /// namespace.
332 pub const TIOCGPTPEER: c_ulong = 0x5441;
333}
334
335/// # Controlling terminal
336/// ---
337impl LINUX_IOCTL {
338 /// Make the given terminal the controlling terminal of the calling process.
339 ///
340 /// Argument: int arg
341 ///
342 /// The calling process must be a session leader and not have a controlling
343 /// terminal already. For this case, arg should be specified as zero.
344 ///
345 /// If this terminal is already the controlling terminal of a different
346 /// session group, then the ioctl fails with `EPERM`, unless the caller has
347 /// the `CAP_SYS_ADMIN` capability and arg equals 1, in which case the
348 /// terminal is stolen, and all processes that had it as controlling
349 /// terminal lose it.
350 pub const TIOCSCTTY: c_ulong = 0x540E;
351
352 /// Give up this controlling terminal.
353 ///
354 /// Argument: void
355 ///
356 /// If the process was session leader, then send `SIGHUP` and `SIGCONT` to
357 /// the foreground process group and all processes in the current session
358 /// lose their controlling terminal.
359 pub const TIOCNOTTY: c_ulong = 0x5422;
360}
361
362/// # Line discipline
363/// ---
364impl LINUX_IOCTL {
365 /// Get the line discipline of the terminal.
366 ///
367 /// Argument: int *argp
368 pub const TIOCSETD: c_ulong = 0x5423;
369
370 /// Set the line discipline of the terminal.
371 ///
372 /// Argument: const int *argp
373 pub const TIOCGETD: c_ulong = 0x5424;
374}
375
376/// # Sending a break
377/// ---
378impl LINUX_IOCTL {
379 /// Equivalent to tcsendbreak(fd, arg).
380 ///
381 /// Argument: int arg
382 ///
383 /// If the terminal is using asynchronous serial data transmission, and arg is
384 /// zero, then send a break (a stream of zero bits) for between 0.25 and 0.5
385 /// seconds. If the terminal is not using asynchronous serial data
386 /// transmission, then either a break is sent, or the function returns without
387 /// doing anything. When arg is nonzero, nobody knows what will happen.
388 pub const TCSBRK: c_ulong = 0x5409;
389
390 /// So-called "POSIX version" of [`TCSBRK`][Self::TCSBRK].
391 ///
392 /// It treats nonzero arg as a time interval measured in deciseconds, and does
393 /// nothing when the driver does not support breaks.
394 ///
395 /// Argument: int arg
396 pub const TCSBRKP: c_ulong = 0x5425;
397
398 /// Turn break on, that is, start sending zero bits.
399 ///
400 /// Argument: void
401 pub const TIOCSBRK: c_ulong = 0x5427;
402
403 /// Turn break off, that is, stop sending zero bits.
404 ///
405 /// Argument: void
406 pub const TIOCCBRK: c_ulong = 0x5428;
407}
408
409/// Process group and session ID
410/// ---
411impl LINUX_IOCTL {
412 /// Get the session ID of the given terminal.
413 ///
414 /// Argument: pid_t *argp
415 ///
416 /// This fails with the error `ENOTTY` if the terminal is not a master
417 /// pseudoterminal and not our controlling terminal.
418 pub const TIOCGSID: c_ulong = 0x5429;
419
420 /// Get the process group ID of the foreground process group on this terminal.
421 ///
422 /// Argument: pid_t *argp
423 pub const TIOCGPGRP: c_ulong = 0x540F;
424
425 /// Set the foreground process group ID of this terminal.
426 ///
427 /// Argument: const pid_t *argp
428 pub const TIOCSPGRP: c_ulong = 0x5410;
429}
430
431/// # Miscellaneous
432/// ---
433#[allow(missing_docs)]
434impl LINUX_IOCTL {
435 /// Set non-blocking I/O mode if the argument is non-zero.
436 ///
437 /// In non-blocking mode, read(2) or write(2) calls return -1 and set errno to
438 /// `EAGAIN` immediately when no data is available.
439 pub const FIONBIO: c_ulong = 0x5421;
440
441 pub const TIOCGSERIAL: c_ulong = 0x541E;
442 pub const TIOCSSERIAL: c_ulong = 0x541F;
443
444 pub const TIOCGRS485: c_ulong = 0x542E;
445 pub const TIOCSRS485: c_ulong = 0x542F;
446 pub const TIOCGPTN: c_ulong = 0x8004_5430;
447 pub const TIOCGDEV: c_ulong = 0x8004_5432;
448 pub const TCGETX: c_ulong = 0x5432;
449 pub const TCSETX: c_ulong = 0x5433;
450 pub const TCSETXF: c_ulong = 0x5434;
451 pub const TCSETXW: c_ulong = 0x5435;
452 pub const TIOCSIG: c_ulong = 0x4004_5436;
453 pub const TIOCVHANGUP: c_ulong = 0x5437;
454 // pub const TIOCGISO7816: c_ulong = 0x8028_5442;
455 // pub const TIOCSISO7816: c_ulong = 0xc028_5443;
456 pub const FIONCLEX: c_ulong = 0x5450;
457 pub const FIOCLEX: c_ulong = 0x5451;
458 pub const FIOASYNC: c_ulong = 0x5452;
459 pub const TIOCSERCONFIG: c_ulong = 0x5453;
460 pub const TIOCSERGWILD: c_ulong = 0x5454;
461 pub const TIOCSERSWILD: c_ulong = 0x5455;
462 pub const TIOCGLCKTRMIOS: c_ulong = 0x5456;
463 pub const TIOCSLCKTRMIOS: c_ulong = 0x5457;
464 pub const TIOCSERGSTRUCT: c_ulong = 0x5458;
465 pub const TIOCSERGETMULTI: c_ulong = 0x545A;
466 pub const TIOCSERSETMULTI: c_ulong = 0x545B;
467 pub const TIOCMIWAIT: c_ulong = 0x545C;
468 pub const TIOCGICOUNT: c_ulong = 0x545D;
469 pub const BLKIOMIN: c_ulong = 0x1278;
470 pub const BLKIOOPT: c_ulong = 0x1279;
471 pub const BLKSSZGET: c_ulong = 0x1268;
472 pub const BLKPBSZGET: c_ulong = 0x127B;
473}