Reputation: 71
I have some questions about UNIX.
Upvotes: 5
Views: 4039
Reputation: 86393
There is one important distinction that you seem to be missing, more specifically the difference between on-disk and in-memory data:
Directory and file contents, access permissions, extended attributes and anything else that is expected to persist after e.g. a system reboot is stored in the filesystem on permanent storage, typically in the i-nodes. The owner, group and permissions of a file, for example, are traditionally stored in the i-nodes.
Anything that is related to the current operation of a filesystem, such as open file descriptors, file offsets and cached data is kept in the computer memory, within kernel-space data structures.
As far as storing the names that are associated with an i-node goes, most Unix-style filesystems do not have a specific data structure that allows mapping i-nodes to names in constant time. Considering that in general we are interested in the reverse mapping (i.e. names to i-nodes) that makes sense. Instead, the data blocks for each directory contain the names and associated i-node identifiers for each file and sub-directory. If one wanted a single list of names for a a specific i-node, they would typically have to traverse the whole directory tree of the filesystem looking for matches...
It should be pointed out that modern filesystems tend to blur the lines between data and metadata. For example, extended attributes may be stored in data blocks, or very small files may be completely packed within their own i-node. Some filesystems do not even have dedicated data blocks or i-nodes.
Upvotes: 3
Reputation: 212404
The file offsets are stored in the file description, and there is a global (system-wide) file description table. The file descriptor in each process is used to access the file description. Permissions are not stored: permission is only checked when the file is opened. The list of links that are associated with an inode are stored in the directories of the file system. Indeed, a reasonable definition of a directory is "a list of links to inodes".
Upvotes: 1