File Management Flashcards
What is a file?
A file is a named collection of related information stored on secondary (non-volatile) memory.
File extensions (.txt, .png, .wav) tell the operating system how to deal with the file when executed.
What is an inode (index node)?
In a Linux file system, an inode (short for “index node”) is a data structure that stores information about a file or directory. It includes information such as the file’s size, ownership, access permissions, and location on the physical storage device.
When a file is created in a Linux file system, the file system allocates a new inode for it and assigns it a unique inode number.
When a file is accessed, the file system looks up the inode using the inode number and retrieves the necessary information from it. This allows the file system to locate the file’s data and provide it to the requesting application.
An inode will then point to its “block” in storage.
What is a block?
A block is simply a chunk of storage, usually 4096 bytes large.
What is the difference between a direct and an indirect inode?
A direct inode stores pointers to blocks of data on the storage device where the file’s contents are stored. Direct inodes are used for small files, as there is enough space in the inode to store the pointers to the blocks of data.
An indirect inode, on the other hand, stores pointers to blocks of indirect pointers, rather than directly to the blocks of data. These indirect pointers, in turn, point to the blocks of data where the file’s contents are stored.
Indirect inodes are used for larger files, as there may not be not enough space in the inode to store pointers to all the blocks of data directly.
What is a pipe? (Linux)
A pipe is a file descriptor that is used to transfer data between processes. It allows processes to communicate with each other and exchange data by writing to and reading from the pipe.
One file descriptor, called the read end, is used to read data from the pipe, and the other, called the write end, is used to write data to the pipe.
When a process writes data to the write end of the pipe, the data is placed into a buffer in the kernel. The data remains in the buffer until it is read from the read end of the pipe by another process.
If the buffer becomes full, the write operation will block until there is sufficient space in the buffer to store the data.
What is the difference between a magnetic disk and a solid-state disk?
A magnetic disk contains multiple platters, consisting of circumference-wide tracks containing individual sectors of information. A magnetic head hovers over each platter. When data is read, all heads moves to the corresponding physical cylinder and read the magnetism of that cylinder.
A solid-state disk consists of a controller, volatile buffer memory and its non-volatile flash memory. A solid state disk is read by copying a flash memory page into the buffer, and then reading data from that buffer. Erasing flash memory requires high voltage, and therefore can only be done on block level.
What is the major downside to a solid-state disk?
Due to the high voltages required to erase flash memory, overwriting and writing data to a block on the disk leads to electrical wear, or deterioration, which, at a critical threshold (its wear limit), will lead to the permanent failure, or death, of that block.
How is SSD wear handled by the disk?
The controller on the SSD applies a technique called wear-levelling, where data is written to the least-recently-used block in the disk. This way, we avoid writing to the same block repeatedly and accelerating wear.
A static approach to wear levelling also moves cold, never accessed data to these least-recently-used blocks, which avoids some blocks never being accessed and weared.
This results in each block having an equal level of wear, rather than certain blocks failing before the others.
How do the heads move on a magnetic disk?
Since the platter rotates, each head only needs to move forwards and backwards. They all move simultaneously, to reach the same cylinder.