File Systems: Fundamentals: Files
File Systems: Fundamentals: Files
What is a file?
¾ A named collection of related information recorded on secondary
storage (e.g., disks)
File attributes
¾ Name, type, location, size, protection, creator, creation time, last-
modified-time, …
File Systems:
Fundamentals File operations
¾ Create, Open, Read, Write, Seek, Delete, …
1 2
Fundamental Duality of File Systems Block vs. Sector
3 4
File System Functionality and Implementation File System Properties
7 8
File Allocation Methods File Allocation Methods
Contiguous allocation Linked allocation
I
I
Pluses Minuses Pl
Pluses Minuses
¾ Best file read ¾ Easy to create, grow & shrink files ¾ Impossible to do true
¾ Fragmentation! random access
performance ¾ Problems with file growth ¾ No external fragmentation
¾ Reliability
¾ Efficient sequential & Pre-allocation? Break one link in the chain
random access On-demand allocation?
and...
9 10
File Allocation Methods File Allocation Methods
Linked allocation – File Allocation Table (FAT) (Win9x, OS2) Direct allocation
11 12
File Allocation Methods Indexed Allocation
Indexed allocation Handling large files
I IB IB IB
Create a non-data block for each file called the index block
¾ A list of pointers to file blocks
File header contains the index block
Multilevel index blocks (IB*IB*…)
Pl
Pluses Minuses
M
¾ Easy to create, grow & ¾ Overhead of storing index
shrink files when files are small I IB IB IB IB
¾ Little fragmentation ¾ How to handle large files?
¾ Supports direct access
13 14
Multi-level Indirection in Unix
¾ B.
B FFaster
t to
t create
t files.
fil Implications
¾ C. Simpler to grow files. ¾ Upper limit on file size (~2 TB)
¾ D. Simpler to prepend and append to files. ¾ Blocks are allocated dynamically (allocate indirect blocks only for
¾ E. Scott Summers is the X-men’s Cyclops large files)
Features
¾ Pros
Simple
Files can easily expand
Small files are cheap
¾ Cons
Large files require a lot of seek to access indirect blocks
15 16
Indexed Allocation in UNIX
Multilevel, indirection, index blocks
10 Data Blocks
1st Level
Inode Indirection
Block n How big is an inode?
Data ¾ A. 1 byte
Blocks
¾ B.
B 16 bbytes
t
n2 ¾ C. 128 bytes
IB Data ¾ D. 1 KB
IB Blocks
2nd Level ¾ E. 16 KB
Indirection
Block
IB
IB n3
Data
Blocks
IB IB
IB IB
3rd Level
Indirection
Block
IB IB
IB IB
17 18
Allocate from a free list Free list representation
19 20
Other Free List Representations Naming and Directories
Directory operations:
D G ¾ List contents of a directory
Next ¾ Search (find a file)
group Linear search
block Binary search
Hash table
¾ Create a file
¾ Delete a file
Allocated block Empty block
21 22
Directory Hierarchy and Traversal
23 24
Directory Traversal (Cont’d.) Naming and Directories
Once you have the file header, you can access all blocks within
How many disk accesses are needed to access file /A/B/C? a file
1. Read I-node for “/” (root) from a fixed location ¾ How to find the file header? Inode number + layout.
2. Read the first data block for root
3. Read the I-node for A Where are file headers stored on disk?
4. Read the first data block of A ¾ In early Unix:
5. Read the I-node for B Special reserved array of sectors
6. Read the first data block of B Files are referred to with an index into the array (I-node number)
7. Read I-node for C Limitations: (1) Header is not near data; (2) fixed size of array Æ fixed
number of files on disk (determined at the time of formatting the disk)
8. Read the first data block of C
¾ Berkeley fast file system (FFS):
Distribute file header array across cylinders.
Optimization:
¾ Ext2 (linux):
¾ Maintain the notion of a current working directory (CWD)
Put inodes in block group header.
¾ Users can now specify relative file names
¾ OS can cache the data blocks of CWD
How do we find the I-node number for a file?
¾ Solution: directories and name lookup
25 26
A corrupt directory can make a file system useless
¾ A. True
¾ B.
B FFalse
l
27