File System
File System
• Boot Loader
– Understands different OS and file systems.
– Reside in a particular location in disk.
– Read Boot Block to find boot image.
Block Allocation
• Contiguous allocation
• Linked allocation
• Indexed allocation
Contiguous Block Allocation
Contiguous Block Allocation
• Pros:
– Efficient read/seek.
Why?
disk location for both
sequential & random
access can be obtained
instantly.
Spatial locality in disk
Contiguous Block Allocation
• Pros:
– Efficient read/seek. Why?
disk location for both
sequential & random access
can be obtained instantly.
Spatial locality in disk
• Cons:
– When creating a file, we don’t
know how many blocks may
be required…
what happens if we run out of
contiguous blocks?
– Disk fragmentation!
Linked Block Allocation
Linked Block Allocation
• Pros:
– Less fragmentation
– Flexible file allocation
Linked Block Allocation
• Pros:
– Less fragmentation
– Flexible file allocation
• Cons:
– Sequential read requires
disk seek to jump to the
next block. (Still not too
bad…)
– Random read will be
very inefficient!!
O(n) time seek operation
(n = # of blocks in the file)
Indexed Block Allocation
• Maintain an array of
pointers to blocks.
• Random access
becomes as easy as
sequential access!
• Cons
– We have to access each block
in the disk one by one to find
more than one free block.
– Traversing the free list may
require substantial I/O
UNIX file layout overview
I-node
• FCB(file control block) of UNIX
• Block size is 4K
Thus, with 12 direct pointers, first 48K are
directly reachable from the i-node.
I-node block indexing
I-node addressing space
Recall block size is 4K, then
Indirect block contains 1024(=4KB/4bytes)entries
• Boot block
• Super block
• FCBs
– (I-nodes in Unix, FAT or MST in Windows)
• Data blocks
Unix Directory
• Internally, same as a file.
• A file with a type field as a directory.
– so that only system has certain access
permissions.
• <File name, i-node number> tuples.
Unix Directory Example
- how to look up /usr/bob/mbox ?
Root Directory Block 132 Block 406
1 . 6 .
I-node 6 I-node 26 26 .
1 .. 1 ..
6 ..
4 bin 26 bob
12 grants
7 dev 17 jeff
81 books
14 lib 132 14 sue
406 60 mbox
9 etc 51 sam
17 Linux
6 usr 29 mark
8 tmp
Looking up Aha!
Looking up bob gives I-node 60
usr gives Relevant Data for has contents
I-node 26
I-node 6 data (bob) /usr/bob is of mbox
is in in block 406
block 132
File System Maintenance
• Format
– Create file system layout: super block, I-nodes…
• Bad blocks
– Most disks have some, increase over age
– Keep them in bad-block list
– “scandisk”
• De-fragmentation
– Re-arrange blocks rather contiguously
• Scanning
– After system crashes
– Correct inconsistent file descriptors
Windows File System
• FAT
• FAT32
• NTFS
FAT
• FAT == File Allocation Table
• FAT is located at the top of the volume.
– two copies kept in case one becomes damaged.
• Design Objectives
1) Fault-tolerance
Built-in transaction logging feature.
2) Security
Granular (per file/directory) security support.
3) Scalability
Handling huge disks efficiently.
Bonus Materials
Open Directories
file
pointer
..
array
.
File data
open(file…) under the hood
1. Search directory
structure for the given file fd = open( FileName, access)
path
2. Copy file descriptors into
in-memory data structure PCB Allocate & link up
data structures
3. Create an entry in
system-wide open-file-
table Open
file
Directory look up
4. Create an entry in PCB table by file path
5. Return the file pointer to
user
Metadata File system on disk
read(file…) under the hood
read( fd, userBuf, size )
PCB
Find open file
descriptor
Open
file read( fileDesc, userBuf, size )
table
Logical phyiscal