KBDFS(8) KBDFS(8) NAME kbdfs, console - keyboard and console filesystem SYNOPSIS aux/kbdfs [ -Dd ] [ -s srv ] [ -m mntpnt ] [ consfile ] mount -b /srv/cons /dev /dev/cons /dev/consctl /dev/kbd /dev/kbdin /dev/kbin /dev/kbmap console [ cmd args... ] DESCRIPTION Started on boot(8), kbdfs translates raw keyboard scancodes from /dev/scancode (see kbd(3)) and its kbin and kbdin file and optionally reads console input from consfile to provide initial keyboard and console input. It serves a one-level directory containing the files cons, consctl, kbd, kbdin, kbin and kbmap. The -D flag enables a debug trace of 9p messages and -d pre- vents kbdfs from making its memory private. The -s option causes kbdfs to post its channel on /srv/srv. On system startup, boot(8) sets this to cons. With the -m option, kbdfs mounts itself on mntpnt (see bind(2)), other- wise on /dev (the default). The console command executes cmd (defaults to the system shell) under its own kbdfs instance providing a serial con- sole if $console environment variable is set. Console Reading the cons file returns characters typed on the con- sole. Normally, characters are buffered to enable erase and kill processing. A control-U, `^U', typed at the keyboard erases the current input line (removes all characters from the buffer of characters not yet read via cons), and a back- space erases the previous non-kill, non-erase character from the input buffer. The combination control-W, `^W', deletes the input last word. Killing and erasing only delete char- acters back to, but not including, the last newline. Char- acters typed at the keyboard actually produce 16-bit runes (see utf(6)), but the runes are translated into the variable-length UTF encoding (see utf(6)) before putting KBDFS(8) KBDFS(8) them into the buffer. A read(2) of a 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. 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, `^U,' `^W' 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 (see read(2)) to cons causes the characters to be printed on the console screen. When a consfile is passed to kbdfs(8) as its last argument, it reads and processes the characters from that file and forwards them to the cons file with the same text processing applied as on keyboard input. This is used to provide a serial console when $console environment variable is set. (see plan9.ini(8)). Holding `Ctrl' + `Alt' and then pressing the `Del' key will trigger a reboot of the terminal. To forward this sequence downstream, `Shift' + `Ctrl' + `Alt' and then pressing `Del' will cause to send a `Shift' up before the `Del' key. This is useful for programs like vnc(1) and vmx(1). Keyboard A read on the kbd file returns the character k, K or c fol- lowed by a null terminated, variable-length, UTF encoded string. The k message is sent when a key is pressed down and K when a key is released. The following string contains all the keycodes of the keys that are currently pressed down in unshifted form. This includes all keys that have a keyboard mapping and modifier keys. The string following the c mes- sage contains the single character that would have been returned on the cons file instead. The c message will be resent at the keyboard repeat rate. A single read(2) can return multiple concatenated messages at once (delimited by the null byte) or block when there are no messages queued. Opening the kbd file disables input processing on the cons file until it is closed again. K, k and c messages can be written to kbdin and will for- warded to the reader of cons or kbd. Writing a r or R mes- sage followed by a UTF encoded rune will simulate the press or release of that particular rune. KBDFS(8) KBDFS(8) Raw scancodes can be written to the kbin file for external keyboard input (used for USB keyboards). Keyboard map PS/2 keyboards generate one and two byte scancodes sequences which give keyboard events relative to physical key loca- tion. These codes are then translated to Unicode runes using a series of tables hereafter referred to as layers. The true mapping of scancodes is locale and potentially device specific. The PS/2 interface presents two physical layers, switched on if the input scancode is one or two bytes. This second "escaped" layer is typically generated for keys like `Home' and `Ins'. Kbdfs additionally maintains eight more virtual layers that are switched on `Shift', `Ctl', `AltGr', and `Mod4' modifier key state. Not all permutations of these modifiers are represented as layers, the exhaustive list is as follows: none Key shift Shift + Key esc Escaped Key altgr AltGr + Key ctl Ctl + Key ctlesc Ctl + Escaped Key shiftesc Shift + Escaped Key shiftaltgr Shift + AltGr + Key mod4 Mod4 + Key altgrmod4 AltGr + Mod4 + Key These layers can be accessed with the kbmap file. A map entry is a line containing three whitespace separated fields: the layer name, the scancode, and the resulting Uni- code value. A layer may also historically be addressed by its numeric index in the above list. A Unicode value of zero indicates to drop that particular input. Reads return the current contents of the map. Each map entry has its fields padded to 11 characters. Writes accept new map entries. Numeric values are taken to be decimal unless they start with 0x (hexadecimal) or 0 (octal). The Unicode character can also be represented as 'x where x gives the UTF-8 representation of the character (see utf(6)), or as ^X to represent a control character. Opening kbmap with OTRUNC resets the map back to the preloaded ascii defaults. SEE ALSO cons(3), keyboard(6), utf(6), kbd(3), plan9.ini(8) KBDFS(8) KBDFS(8) FILES /sys/lib/kbmap/* SOURCE /sys/src/cmd/aux/kbdfs /rc/bin/console HISTORY Kbdfs first appeared in 9front (May, 2011).