I recently began studying Linux's source code in order to create my own POSIX operating system from scratch. From what I understand, everything on a UNIX-like system is a file. Anything that you can read bytes from / write bytes to can be abstracted as a "stream". But here I've stumbled onto a problem no one on the Internet seems to care about (at least I didn't find anything explaining it) : What exactly does Linux do under the hood to manage everything as a file?
My question might be unclear, so here's an example of what I'd like to understand : When you type "ls -l" in a shell, it not only lists physical files stored on the disk, but also block and char devices, links, and other things that are not files stored on disk. How does it work?
Thanks in advance, Dave.
man readdir getdents. Readman -k inode. Thed_typefield in the inode holds the info.ls"lists block and char devices [...] and other things that are not stored on disk." Yes, but the directory entries are stored in the same place on the disk as the entries for disk files. (With the exception of virtual file systems like/proc.) You can think of a directory as a file with records of (name, inode number) pairs that each map a name to an inode.