44 | | An inode can be a device node (block or character), directory, FIFO, regular file, link, or socket. Current RTEMS does not support FIFO or socket nodes in its file systems so they are ignored. Inodes are numbered from 1 so there is no inode number 0. The root inode is always 1 and therefore the first inode of the first group and its mode is directory. This directory can contain any number of inodes including directories. Files can be link using hard or symbolic links. Directories cannot be linked therefore avoiding the creation of a directed acyclic graph or DAG. An inode can have a map of blocks associated to it. The use of the data depends on the mode of the inode. If the inode is a directory the data in the block map is the contents of the directory. If a regular file the block map contains the file's data and if a symbolic link the data is the link path. The block map has three levels. The first is a series of block numbers held in the inode. The current value is 5 blocks. When the block map is less than or equal to 5 blocks the mapping is called direct as the block numbers map directly to data blocks. If there are more than 5 blocks the 5 inode slots point to blocks that hold the data blocks. This called singly indirect. The number of blocks that can be addressed with a single indirect map depends on the block size. For a block size of 1024 bytes and a 32bit block number a block holds 256 blocks, and with 5 indirect blockes addressable from the inode this is a total of 1280 blocks or 1.3M. If the map grows to have more blocks the map changes to a doubly indirect map. Here the block addressed from the inode holds block numbers to singly indirect blocks. |
| 46 | An inode can be a device node (block or character), directory, FIFO, regular file, link, or socket. Current RTEMS does not support FIFO or socket nodes in its file systems so they are ignored. Inodes are numbered from 1 so there is no inode number 0. The root inode is always 1 and therefore the first inode of the first group and its mode is directory. This directory can contain any number of inodes including directories. Files can be link using hard or symbolic links. Directories cannot be linked therefore avoiding the creation of a directed acyclic graph or DAG. An inode can have a map of blocks associated to it. The use of the data depends on the mode of the inode. If the inode is a directory the data in the block map is the contents of the directory. If a regular file the block map contains the file's data and if a symbolic link the data is the link path. The block map has three levels. The first is a series of block numbers held in the inode. The current value is 5 blocks. When the block map is less than or equal to 5 blocks the mapping is called direct as the block numbers map directly to data blocks. If there are more than 5 blocks the 5 inode slots point to blocks that hold the data blocks. This called singly indirect. The number of blocks that can be addressed with a single indirect map depends on the block size. For a block size of 1024 bytes and a 32bit block number a block holds 256 blocks, and with 5 indirect blockes addressable from the inode this is a total of 1280 blocks or 1.3M bytes. If the map grows to have more blocks the map changes to a doubly indirect map. Here the block addressed from the inode holds block numbers to singly indirect blocks. With our example block size of 1024 bytes this takes the maximum file size up to 327,680 blocks or 335M bytes. A block size of 4096 allows a single file to be 21.4G bytes. |
| 47 | |
| 48 | Inodes hold the number of links to itself. If 0 the inode is not linked and therefore should be marked as free in the group's inode allocator bitmap. An inode can have a number of links or hard links it is not of type directory. Inodes also hold the owner details and the permission bits. These control access to the inode via the operating calls. Finally inodes hold the access, modified and changed times. The access time if the last time the file was read, the modified time the last time file was written to and the changed time the last time the inode was written to. |
| 49 | == Device Nodes == |
| 50 | |
| 51 | |
| 52 | A block or character device node is an inode that holds the major and minor device number. These numbers are held in the block map's slots. A directory entry links to the inode therefore giving it a name in the file system. |
| 53 | == Directory == |
| 54 | |
| 55 | |
| 56 | A directory is like a regular file how-ever its format is internal to the file system. The RFS directory is a block map of variable length directory entries. A directory has the following format: |
| 57 | |
| 58 | <blockquote> |
| 59 | {| border="1" cellpadding="5" cellspacing="0" |
| 60 | |- |
| 61 | ! align="center" | Inode Number (INO) |
| 62 | |- |
| 63 | ! align="center" | Hash |
| 64 | |- |
| 65 | ! align="center" | Length |
| 66 | |- |
| 67 | ! align="center" | Data |
| 68 | |} |
| 69 | </blockquote> |
| 70 | |
| 71 | The Inode number of INO is the 32bit inode number this entry references, the hash is a 32bit hash of the data, and length is the number of bytes in the directory entry. This means the minimum size for a directory entry is 12 bytes. The hash provided a fast way to check if a directory entry matches. |
| 72 | |
| 73 | Directories are maintained unsorted, sparse and not indexed. If directory performance is an issue it can be addressed in future versions. Blocks of directory entried are maintained compacted. As entries are removed the entried in the block are compacted, how-ever intermediate blocks in a block map are not removed and freed when they become empty while trailing empty blocks are. |
| 74 | == Regular Files == |
| 75 | |
| 76 | |
| 77 | Regular files are an inode with a block map. Internally the RFS code maintains the inode data in memory while a file is open. If the file is opened a second time the inode data is shared between the file handles. This allows the POSIX required time fields to be maintained with minimal overhead. |