This is a rather low-level question, and I understand that it might not be the best place to ask. But, it seemed more appropriate than any other SE site, so here goes.
I know that on the Linux filesystem, some files actually exist, for example: /usr/bin/bash
is one that exists. However, (as far as I understand it), some also don't actually exist as such and are more virtual files, eg: /dev/sda
, /proc/cpuinfo
, etc. My questions are (they are two, but too closely related to be separate questions):
- How does the Linux kernel work out whether these files are real (and therefore read them from the disk) or not when a read command (or such) is issued?
- If the file isn't real: as an example, a read from
/dev/random
will return random data, and a read from/dev/null
will returnEOF
. How does it work out what data to read from this virtual file (and therefore what to do when/if data written to the virtual file too) - is there some kind of map with pointers to separate read/write commands appropriate for each file, or even for the virtual directory itself? So, an entry for/dev/null
could simply return anEOF
.