CONS(3) CONS(3) NAME cons - console device SYNOPSIS bind #c /dev /dev/cons /dev/consctl /dev/drivers /dev/jit /dev/keyboard /dev/klog /dev/kprint /dev/memory /dev/msec /dev/null /dev/notquiterandom /dev/pgrpid /dev/pin /dev/pointer /dev/random /dev/sysname /dev/time /dev/user DESCRIPTION The console device serves a one-level directory giving access to the console and miscellaneous information. Reading the cons file returns characters typed on the key- board. Normally, characters are buffered to enable erase and kill processing. A control-U, `^U', typed at the key- board kills the current input line (removes all characters from the buffer of characters not yet read via cons), and a backspace erases the previous non-kill, non-erase character from the input buffer. Killing and erasing only delete characters back to, but not including, the last newline. Typed keystrokes produce 16-bit characters that are trans- lated into the variable-length UTF encoding (see utf(6)) before putting them into the buffer. A read of length greater than zero causes the process to wait until a newline or a `^D' ends the buffer, and then returns as much of the buffer as the argument to read allows, but only up to one complete line. A terminating `^D' is not put into the buffer. If part of the line remains, the next read will return bytes from that remainder and not part of any new line that has been typed since. A single line containing a `^D' can be used as an end of file indication to programs that take interactive input. Page 1 Plan 9 (printed 11/17/24) CONS(3) CONS(3) If the string rawon has been written to the consctl file and the file is still open, cons is in raw mode: characters are not echoed as they are typed, backspace and `^D' are not treated specially, and characters are available to read as soon as they are typed. Ordinary mode is reentered when rawoff is written to consctl or this file is closed. A write to cons causes the characters to be printed on the console screen. The keyboard file returns the underlying tokens produced by the keyboard hardware as they are produced; in the emulation environment, it is like an always-raw cons file. The null file throws away anything written to it and always returns zero bytes when read. The klog file returns the tail of messages written by kernel logging statements. The kprint file returns console output: messages written by kernel print statements and messages written by processes to this driver's cons file. Until kprint is opened, system console output is handled normally. Once kprint has been opened, if the machine's console is a serial line, the data is sent both to the serial console and to kprint; if the console is a graphics screen, the data is sent only to kprint. A read of the pointer file returns the status of the mouse or other pointing device: its position and button state. The read blocks until the state has changed since the last read. The read returns an m character followed by three integers in the standard Inferno 12-character decimal for- mat: right-adjusted numerals with leading blanks to fill the field to 11 characters, followed by a blank. The integers are the device's coordinates on the screen and a bit mask with the 1, 2, and 4 bits when the pointer's left, middle, and right buttons, respectively, are down. The pin file, when read, returns either the string no pin if no PIN has been set for authentication, or pin set if one has. The pin file may be written once with a decimal repre- sentation of the PIN to use on this Inferno machine. The random device returns as many bytes of random data as are requested in the read. The notquiterandom device returns as many bytes of pseudo- random data as are requested in the read; this is typically faster than random but the results are more predictable. Page 2 Plan 9 (printed 11/17/24) CONS(3) CONS(3) The rest of the files contain (mostly) read-only strings. Each string has a fixed length: a read (see sys-read(2)) of more than that gives a result of that fixed length (the result does not include a terminating zero byte); a read of less than that length leaves the file offset so the rest of the string (but no more) will be read the next time. To reread the file without closing it, seek must be used to reset the offset. When the file contains numeric data, each number is formatted in decimal as an 11-digit number with leading blanks and one trailing blank: twelve bytes total. The sysname file holds the textual name of the machine. The user file contains the name of the user associated with the current process. The memory file returns a formatted presentation of the state of the memory allocation pools in the system. Each line of output returned reports, for a single pool, the amount of memory in use, the upper size limit, the number of allocations done, the number of frees done, the number of extensions done, and the name of the pool. The drivers file returns a list of the device drivers loaded in the system. Each line gives the name of the device for bind(1), such as #c, followed by the name of the driver as used in the system configuration file. The other files served by the cons device are all single numbers: jit non-zero if `just in time' compilation is configured (can be written to change the state). msec the value of a millisecond counter time number of microseconds since the epoch 00:00:00 GMT, Jan. 1, 1970. (Can be written once, to set at boot time.) SOURCE /emu/devcon.c /os/port/devcons.c SEE ALSO draw(3), keyboard(6), utf(6) BUGS For debugging, on native systems only, two control-T's fol- lowed by a letter generate console output: `^T^Tp' prints data about kernel processes, `^T^Ts' prints the kernel stack, `^T^Tx' prints data about memory allocation. Page 3 Plan 9 (printed 11/17/24) CONS(3) CONS(3) The system can be rebooted by typing `^T^Tr'. Page 4 Plan 9 (printed 11/17/24)