“Linux follows the philosophy that every thing is a file. For example, a keyboard, monitor, mouse, printer… You name it and it is classified as a file in Linux. Each of these pieces of hardware have got unique file descriptors associated with it. Now this nomenclature has got its own advantages. The main one being you can use all the common command line tools you have in Linux to send, receive or manipulate data with these devices.”
If “everything is a file”, then where are the semantics of file operations defined? I’m especially interested in the semantics of ‘ioctl’.
– Morin
I always found it odd that I always hear “everything is a file” yet my network cards are not files.
You’re just not looking in the right place, try mounting proc and sysfs.
Ioctls are good until you have to write code that uses them.
Semantics is defined at some appropriate driver level.
For example, do a ‘ls -l’ on the files in the /dev directory, these are special devices with major/minor number pairs which maps to a device driver in kernel space, hence the semantics is left to that driver.
The same can be applied to ordinary files and directories, The VFS layer performs the mapping to the appropriate file system driver for those.
The character far left of an ‘ls -l’ on a file tells the file type (e.g. ‘-‘, ‘d’, ‘b’ or ‘c’ to mention a few)
Heh, I once did cat /dev/kbd on NetBSD. Rendered the system unusable for that session (because it wasn’t an xterm or something like that).
(Don’t try at home, kids.)
schnipschnap said…
Heh, I once did cat /dev/kbd on NetBSD. Rendered the system unusable for that session (because it wasn’t an xterm or something like that).
(Don’t try at home, kids.)
Actually you could type the command
$ reset
to get the terminal back to normal. Doesn’t it work in NetBSD ? It works in Linux quite well.
Kill keyboard and Linux
#!/bin/sh
while :
do
setleds -L +caps ; setleds -L -caps ;# missing sleep 1;
done