Week 10 - The Linux Filesystem Flashcards
File system
– The way files are stored and organized to:
* Simplify access to data
* Help OS keep track of how files are organized and how available space is managed on a disk
– Consists of disk partitions
* Disk partitions allow better organization and productivity, data security, data backup, and more
Linux File system
Hierarchical directory structure descending from root
directory (/)
– All partitions are contained under root directory
– All objects, such as devices and directories, treated as files
– Treats each device, such as a monitor, keyboard, or hard drive, as a single file and stores it in /dev directory
Creating links
Use ln command
Inode
Inode
Data structure that stores all information about a file except the actual data and filename
* Stores Filesystem Attributes such as:
– Metadata (create time, modify time)
– Owner and permission data
– Disk block location of data
Inode number
Like an address
References an entry in inode table
– List of inodes for all files on a Linux partition
– Table entry points to the data’s location on the disk
Command to view a file’s inode number
ls -il
Hard links
Files that point to data on hard drive
Create a file (e.g. touch)
– Automatically linked to the actual data stored on a partition
– Assigned an inode number referencing this data
Create a hard link
Create a hard link:
– ln existingFile hardLinkToExisingFile
– > ln notes ~/Math
- Delete files
– Data isn’t deleted until the last link is deleted
Symbolic (Soft) links
Symbolic links
– Also called soft links
– Special types of files that point to other files instead of pointing to data on the hard drive
– Do not share the same inode number
* Benefit of creating a symbolic link
– Link files that are on separate partitions or even different computers
Storage access
File Space = Collection of Storage Devices
* Storage Devices
– Hard Disks
– Optical Disks
– Solid State Drives
– USB Drives
– Tape Drives
- File Space exists two levels of abstraction–
- Logical: Partitions, Directories, Files
–Physical: File Systems, Disk Blocks, Pointers
Use file space to store executable programs and data files - two operations Read or write
Disk storage and blocks
To store a file, it is decomposed into fixed size blocks
Each block is then stored at a disk location
Kernel must manage distribution of files to blocks in three ways
1. Given a file and block: map that block onto a physical location on storage medium
- Direct the disk drive to access that particular block through (via SSD electrical circuits, or via read/write head of HD)
- Maintain free file space (available blocks), including the return of file blocks once a file has been deleted
How does the Kernel locate a particular block of a disk?
File systems use an indexing scheme
- Windows used File Allocation Table (FAT)
- Upgraded to NFTS (New Technology File System)
In Linux, indexing is handled through inode data structure
Inode structure
Typically, an inode will contain 15 pointers
– 12 Direct pointers
– 1 indirect pointer
– 1 double indirect pointer
– 1 triple indirect pointer
- Indirect pointers point to Indirect Block
- Disk block stores ~1-8Kb
– If our file uses 500 blocks: 500 * 8kb = 4000KB ( 4MB)
If one pointer is 8 bytes, how many can we fit inside an Indirect Block
Number Pointers = Size Of Indirect Block / Size Of Pointer
Number Pointers = 4KB / 8 B
Number Pointer = 4096B / 8B
Number Pointers = 512
Inodes and Files
The system admin will rarely (if ever) have to deal
directly with inodes or pointers
* The Linux filesystem commands operate at a higher level of abstraction
– Admin or Users Operate on Files and Directories
– Device drivers must deal with inodes and the location of disk blocks
Directories
Directory does not store content like files
File = Collection of data blocks on File Content
Directory = Collection of data blocks on Directory Structure
– Directory data blocks are different
– Blocks contain lists of names and inode numbers
Filesystem
can be thought of as a type of database of files and directories
– Supplies structure to transform simple block device into sophisticated hierarchy of files and sub directories that users can understand