Linux File System Flashcards
Key Fundamental of Unix
Everything is a file, including:
- pipes
- sockets
- processes
- USB ports
- printers
- hard drives
- kernel data structures
This allows us to use syscalls on everything.
Representation of File Systems in Linux
Users can see the file systems as a tree-like structure, the logical representation (abstraction).
Top Level Directories
Each Linux file system has certain top level directories. Some examples include:
/root
/boot
/dev
/home
/proc
/root directory
Home directory of the root user
/boot directory
Files needed while the system is booting
/dev directory
Virtual files mapped to physical devices
/home directory
Home directories for every user on the system
/proc directory
Virutal files mapped to running processes (including housekeeping)
EXT4 File System
Common file system for linux.
High performance, limited required maintenance.
Disk size being 1 exabyte.
Individual files being 16 TB.
Standard disk block being 4 KB up to 64KB.
EXT4 Disk Format
Super Block -> EXT4 settings and flags (housekeeping).
Group Descriptors -> block locations of data bitmap, inode bitmap and inode table.
Reserved Space -> free space allowing more groups to be added to group descriptors.
Data Bitmap -> freelist for blocks.
Inode Bitmap -> free inode list for inodes.
Inode Table -> table of inode data (metadata).
Data Blocks -> physical data for files.
(note that data bitmap, inode bitmap and inode table can be repeated).
Inode Information
Every file has an inode associated with it, which includes:
- size
- owner
- group
- octal permissions value
- type of inode (normal file, directory, symbolic link etc)
- timestamps (created, modified)
- start and end block numbers of actual data
Filenames are stored in directory files.
Nested Directories
Since directories can be nested, some of the inodes listed in the directory block could point to other directory blocks.
For example, we could have a directory /home/scap21/work/file3.c. We first then look at home directory, and find out that scap21 has information, or metadata, which is stored on inode 34.We then read inode 34, which contains start and end block numbers which represents the data of scap21. We then go to where this start block number is, and read the blocks/file until the end block number. Now lets say this block contains information on work, specifically the location of work’s inode. We, again, to the work’s inode, find where the block is, and find where file3.c’s inode is, and then its block.
Remember, we can have multiple sections of blocks. We can have two start and ends blocks, but then this is still read normally and in order.
Symbolic Link (hard and soft)
A symbolic link can be used to references a file/directory. There are two ways of doing this:
Hard Link -> gives files a second filename with the ln command. It creates a new directory entry that points to the same inode as the original file or directory, giving two points of reference for the same directory.
For example, let’s say you have a file named “file1.txt” in your home directory, and you want to create a hard link to it called “file2.txt” in the same directory. We use ln file1.txt file2.txt which creates this, and points both of these at the same inode.
Soft Link -> creates a new file and stores the original file’s name in it.
For example, let’s say you have a file named “file1.txt” in your home directory, and you want to create a soft link to it called “file2.txt” in the same directory. We use ln -s file1.txt file2.txt, which points file2.txt at file1.txt.
Scattering
New files are spread evenly across disk, allowing contiguous growth and reduces defragmentation of files.
Delayed Allocation
Creates virtual blocks in memory while file is written, and commits to physical blocks when file size is known. This allows system to find contiguous free space on disk, but lost data could occur if memory is eventually not written on disk.