Published on 2024-12-29
Could be Interesting!A peak into how file storage works in computing devices running unix system.
uname -v
uname -a
ps aux
struct inode {
uint16_t i_mode; // bit vector of file // type and permissions
uint8_t i_nlink; // number of references to file
uint8_t i_uid; // owner
uint8_t i_gid; // group of owner
uint8_t i_size0; // most significant byte of size
uint16_t i_size1; // lower two bytes of size (size is encoded in a three-byte number)
uint16_t i_addr[8]; // device addresses constituting file
uint16_t i_atime[2]; // access time
uint16_t i_mtime[2]; // modify time
};
Note1: Two types of files data: (1) payload data (text in the documents, image in the png, etc.) (2) metadata (name, size, etc.). That means some blocks must store file payload data and some others, metadata.i_addr
stores the numbers of blocks that contain payload file data. Since there is only space for 8 block numbers per inode, the largest a file can be is 4096 * 8 = 32,768 bytes (~32KB). That is not realistic! What if we have more than 8 block numbers for a file? The workaround is to store the block number in a block, and so on. This is called indirect block.i_addr = [12, 200, 56, …]
.diskutil list
diskutil info /
For example, mine returns with
Device Block Size: 4096 Bytes
In a nutshell, Note: file descriptors are assigned in ascending order (next FD is lowest unused).