diff --git a/docs/architecture/devices.md b/docs/architecture/devices.md index 7c5f23c..d1513e3 100644 --- a/docs/architecture/devices.md +++ b/docs/architecture/devices.md @@ -355,6 +355,14 @@ from the cycle counter on each byte so two readers do not continue one sequence. What changed is the property that made it dangerous rather than merely poor. +**For a long time it could not be read at all**, and neither could `/dev/zero`. +Both are minors of major 1, and `devsw[1]` is `memread`/`memwrite`, which hand +the console's minors to the console and the rest to their own functions. But +`consoleinit()` installed `consoleread` over the whole major, so a read of +`/dev/zero` waited for a line from the keyboard. `head -c 10 /dev/zero` +"worked" by taking the next command typed. The console now installs only its +`open` and `close` hooks. + ## What it does not do - **It is a flat list, not a device tree.** There is no parent/child nesting, diff --git a/kernel/core/console.c b/kernel/core/console.c index e9b2d14..c38fd7b 100644 --- a/kernel/core/console.c +++ b/kernel/core/console.c @@ -820,8 +820,12 @@ consoleinit(void) initlock(&cons.lock, "console"); initlock(&input_lock, "input"); - devsw[CONSOLE].write = consolewrite; - devsw[CONSOLE].read = consoleread; + // Not read and write. Major 1 is the whole mem major -- null, zero, full, + // random, urandom as well as the console and the ttys -- and devsw[1] is + // memread/memwrite, which send the console's minors here and the rest + // where they belong. Installing consoleread over it made /dev/zero and + // /dev/urandom wait for a line from the keyboard, which is why neither + // had ever seemed to work. devsw[CONSOLE].open = consoleopen; devsw[CONSOLE].close = consoleclose; cons.locking = 1; diff --git a/kernel/dev/cdev.c b/kernel/dev/cdev.c index afe2edf..077b9b0 100644 --- a/kernel/dev/cdev.c +++ b/kernel/dev/cdev.c @@ -170,6 +170,7 @@ memwrite(struct inode *ip, uint64 off, char *dst, int n) case 10: case 11: case 12: case 13: case 14: case 15: case 16: return consolewrite(ip, off, dst, n); case 7: return fullwrite(ip, off, dst, n); // /dev/full: always ENOSPC + case 3: // /dev/keyboard: discarded case 2: case 5: case 8: