File Descriptors, Files and Inodes
-
- At the base of this system is the inode
- This is a structure that holds information about a file.
- Defined for various file systems in /usr/include/linux
- ext2fs_fs.h is the clearest
- Mode info
- Owner
- Access Info
- Time info
- number of links.
- Permissions
- Surprisingly, no name. (Symbolic,hard links)
- A pointer to blocks on the disk.
- This is a hierarchical system
- There is a posix standard.
- More on this later (possibly)
- I have never really had to work directly with inodes.
- Inodes are associated with the file system.
- These are most likely stored in an in-memory table.
- And on the file system
- Next is the open file table.
- This is maintained by the kernel.
- There is one entry in this table per call to open.
- This will contain the flags set by open
- A pointer to the inode table.
- The file offset (lseek, ...)
- Note: multiple processes can have the file open at any time
- Or even one process twice.
- Finally the per-process file descriptor table.
- Some things to note on the picture:
- fd2 of process A and B both point to the same file handle, ie the result of a fork.
- fd1 and 20 of process A both refer to the same file handle, a dup
- fd0 of process A and fd3 of process B both refer to the same file, Different opens but same file.