Inodes exist in a static form on disk, and the kernel reads them into an in-core inode to manipulate them. The internal representation of a file is given by an inode which contains a description of the disk layout of the life data and other information such as the file owner, access permissions and access times. (Bach 22) Inode is short for index node and is commonly used in UNIX terminology. Each file has one inode but it could have several other names, all which map into the inode. Each of these names is called a link. When a process refers to a file by name, the kernel parses the file name one component at a time, checks that the process has permission to search the directories in the path and eventually retrieves the inode for the file. (Bach 22) When a process creates a new file, the kernel assigns it to an unused inode. Inodes are stored in the file system, but the kernel reads them into an inode table in the core of the primary memory when manipulating files. (Bach 23)
The kernel contains two other data structures, the file table and the user file descriptor table. The file table is the global kernel structure, but the user file descriptor table is allocated per process. (Bach 23) When a process opens or creats a file, the kernel allocates an entry from each table, corresponding to the file's inode. (Bach 23) The user file descriptor table, file table, and inode table maintain the state of the file and the user's access to it.
The file table keeps track of the byte offset in the file where the user's next read or write will start, and the access permissions allowed to the opening process. The user file descriptor table identifies all open files for a process. The kernel returns a file descriptor for the open and creat system calls, which is an index into the user file descriptor table. When executing read and write system calls, the kernel uses the file descriptor to access the user file descriptor table, follows pointers to the file table and inode table entries, and from the inode, finds the data in the file. (Bach 23)
- File owner identifier. Ownership is divided between an individual owner and a "group" owner and defines the set of users who have access rights to a file. The superuser has access rights to all files in the system.
- File type. Files may be of type regular, directory, character or block special FIFO (pipes).
- File access permissions
- File access times, giving the time the file was last modified, when it was last accessed, and when the inode was last modified.
- Number of links to the file, representing the number of names the file has in the directory hierarchy.
- Table of contents for the disk addresses of data in a file. Although users treat the data in a file as a logical stream of bytes, the kernel saves the data in discontiguous disk blocks. The inode identifies the disk blocks that contain the file's data.
- File size. Data in a file is addressable 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.
(Bach 62).
- The inode does not specify the path name(s) that access the file.
- The status of the in-core inode, indicating whether
-- the inode is locked,
-- a process is waiting for the inode to become unlocked,
-- the in-core representation of the inode differs from the disk copy as a result of a change to the data in the inode,
-- the in-core representation of the file differs from the disk copy as a result of a change to the file data,
-- the file is a mount point.
- The logical device number of the file system that contains the file.
- The inode number. The disk inode does not need this field.
- Pointers to other in-core inodes.
- A reference count, indicating the number of instances of the file that are active. (Bach 63)
The super block describes the state of a file system -- how large it is, how many files it can store, where to find free space on the file system, and other information. (Bach 24)
The super block consists of the following fields:
- the size of the file system,
- the number of free blocks in the file system,
- a list of free blocks available on the file system,
- the index of the next free block in the free block list,
- the size of the inode list,
- the number of free inodes in the file system,
- a list of free inodes in the file system,
- the index of the next free inode in the free inode list,
- lock fields for the free block and free inode lists,
(Bach 76)
- a flag indicating that the super block has been modified.