written 5.5 years ago by |
Every file on a UNIX system has a unique i-node. The i-node has the information necessary for a process to access a file. It contains the information like file ownership, access rights, file size, and location of the file's data in the file system. Processes can access files by a well defined set of system calls and specify a file by a character string that is the path name. Each path name uniquely specifies a file. The kernel converts the path name to the file's i-node.
i-nodes
i-nodes presents in a static form on disk, and the kernel reads the i-node’s information into an in-core i-node to manipulate them. Disk i-nodes consist of the following fields
File owner identifier.
Ownership is categorised into two parts individual owner and a "group" owner and also defines the set of users who have access rights to a file. The super user has access rights to all files in the system.
File type.
Files can have many types like regular, directory, character or block special, or FIFO (pipes).
File access permissions.
The system protects files using to three classes: the owner and the group owner of the file, and other users; each class has given an access rights to read, write and execute the file, which can be set individually. Because directories cannot be executed, execution permission for a directory gives the right to search the directory for a file name.
File access times
It gives the time the file was last modified, when it was last accessed, and when the mode was last modified.
Number of links to the file
It represents the number of names the file has in the directory hierarchy.
Table of contents for the disk addresses of data in a file.
Users treat the file data as a logical stream of bytes; but the kernel saves the data in discontinuous disk blocks. The i-node identifies the disk blocks that contain the file's data.
File size.
A file data is recognised by the number of bytes from the beginning of the file, starting from byte offset 0, and the file size is 1 greater than the highest byte offset of data in the file. For example, if a user creates a file and writes only 1 byte of data at byte offset 1000 in the file, the size of the file is 1001 bytes.
The i-node does not specify the path name(s) that access the file.
Owner Namrata
group OS
type regular file
perm rwxr-xr-x
accessed Dec 06 2018 11:03 A.M
modified Dec 05 2018 10:00 A.M
inode Dec 06 2018 11:00 A.M.
size 4040 bytes
disk addresses
The in-core copy of the i-node contains the following fields in addition to the fields of the disk i-node:
• The status of the in-core i-node, indicating whether
The i-node is locked; a process is waiting for the i-node to become unlocked,
The in-core representation of the i-node different from the disk copy i.e. there are some change to the data in the i-node,
The in-core representation of the file differs from the disk copy as a result of a change to the file data also,
The file is considered as a mount point. The logical device number of the file system that contains the file.
The i-node number: Since i-nodes are stored in a linear array on disk , the kernel identifies the number of a disk i-node by its position in the array. The disk i-node does not need this field.
Pointers to other in-core i-nodes: The kernel links i-nodes on hash queues and on a free list just as it links buffers on buffer hash queues and on the buffer free list. A hash queue is recognised according to the i-node's logical device number and i-node number as a identity. The kernel can contain at most one in-core copy of a disk i-node, but i-nodes can be simultaneously on a hash queue as well as on the free list.
A reference count, indicating the number of instances of the file that are active (such as when opened).
Accessing i-nodes
The kernel identifies particular i-nodes with the help of their file system and i-node number. It also allocates in-core i-nodes by requesting higher-level algorithms. The algorithm i-get does the task of allocating an in-core copy of an i-node; it is almost similar to the algorithm getblk for finding a disk block in the buffer cache. The kernel maps the device number and i-node number into a hash queue and searches the queue for the i-node. If it cannot find the i-node, it allocates one i-node from the free list and locks it. After that the kernel prepares to read the disk copy of the newly accessed i-node into the in-core copy. It already knows the i-node number and logical device and computes the logical disk block that contains the i-node according to how many disk i-nodes fit into a disk block.
Releasing i-nodes
The kernel releases an i-node, when it do so, it decrements its in-core reference count. If the count goes 0, the kernel writes the i-node to disk if the in-core copy varies from the disk copy. They differ according to some conditions if the file data has changed, if the file access time has changed, or if the owner of the file or access permissions have changed. The kernel places the i-node on the free list of i-nodes, effectively caching the i-node in case it is needed again soon. The kernel may also release all data blocks associated with the file and free the i-node if the number of links to the file is 0.