File System Implementation
File System Implementation
File-System Structure
File-System Implementation
Directory Implementation
Allocation Methods
Free-Space Management
File-System Structure
File is a collection of related information.File System resides on Secondary
Storage.
File Systems provide efficient and convenient access to the disk by allowing
data to be stored, located, and retrieved easily.
A file system poses two quite different design problems. The first problem is
defining how the file system should look to the user.
This task involves defining a file and its attributes, the operations allowed on a file,
and the directory structure for organizing files.
The second problem is creating algorithms and data structures to map the
logical file system onto the physical secondary-storage devices.
File-System Structure
File structure
Logical storage unit
Collection of related information
File system resides on secondary storage (disks)
File system organized into layers
File control block – storage structure consisting of information about a file
The file system itself is generally composed of many different levels.
Each level in the design uses the features of lower levels to create new features for
use by higher levels.
The lowest level, the I/O control, consists of device drivers and interrupt handlers to
transfer information between the main memory and the disk system.
Layered File System
File System Implementation
Several On Disk and In Memory Structures are used.
On disk Structures
-How to boot an OS stored there, total number of disk blocks,
Number and location of free disk blocks,directory structure,
Individual files.
In-memory structures
- File-system management, Caching
On Disk Structures
Boot Control block
-Contains information needed to boot an OS
-if the disk has no OS , this block is empty.
Volume Control block
-Contains partition details , no. of blocks in partition ,
size of blocks , Free block count and Free block pointers.
Directory Structure(for each file system)
-Used to Organize files
Per file File Control Block(FCB)
-Contains details about the files
-Unique identifier
A Typical File Control Block
In-Memory File System Structures
Mount Table – Information about each mounted volume
Directory – Structure Cache – Holds directory information of recently
accessed directories
System wide open file table
Contains a copy of the FCB of each open file.
Per process open file table – Points to the appropriate entry in the System
wide open file table.
Buffers
In Memory Structures – Create a New file
Application program calls new file system
Logical file system knows the name of the directory
sturctures
Allocates a new FCB.
System reads appropriate directory into memory.
Update the directory with the new file name and FCB
and writes back to disk.
In Memory Structures –Open an Existing file
Open() call passes a file name to the logical file system.
The call first searches the system-wide open – file table to see if the file is
already in use by another process.
If it is,a per-process open-file table entry is created pointing to the existing
system-wide open-file table entry.
If the file is not alreay open,the directory structure is searched for the given
file name.
Parts of the directory structure are cached in memory.
Once the file is found, The FCB is copied into an entry in the system-wide
open file table in memory.
The following figure illustrates the necessary file system structures
provided by the operating systems.
Figure 12-3(a) refers to opening a file.
Figure 12-3(b) refers to reading a file.
In-Memory File System Structures
In Memory Structures – Close a file
When a process closes a file,the per process open file table’s
entry is removed
The count in the system wide open file table entry is
decremented.
When the count becomes zero,the updated metadata is
copied to the directory structure in the disk.
Directory Implementation
Linear list of file names with pointer to the data blocks.
simple to program
time-consuming to execute
To create a new file , search the directory if another file with a similar
name exists.
If no such file , a new entry is added to the end of the directory
To delete a file , search the directory for that file and release the space
allocated to it.
Disadvantages:
Finding a file requires linear search – makes access slow.
Hash Table – linear list with hash data structure.
A linear list stores the directory entries , a hash data structure is also
used.
Hash table takes a value computed from the file name and returns a
pointer to the the file name in the linear list.
decreases directory search time
collisions – situations where two file names hash to the same location
fixed size
Allocation Methods
An allocation method refers to how disk blocks are allocated for files:
Disk space should be allocated so that disk space is utilized effectively and
files can be accessed quickly.
Contiguous allocation
Linked allocation
Indexed allocation
Contiguous Allocation of Disk Space
Each file occupies a set of contiguous blocks on the disk
Simple – only starting location (block #) and length (number of
blocks) are required
Sequential and Direct Access.
Dis Advantages
Random access
External Fragmentation
Wasteful of space (dynamic storage-allocation problem)
-How to satisfy a request of size n from a list of free holes
(First Fit or Best Fit)
Difficult to determine how much space is needed for a file.
Files cannot grow – Can Over estimate the space needed,results in
wastage of Space.
Contiguous Allocation of Disk Space
Extent-Based Systems
Many newer file systems (I.e. Veritas File System) use a modified
contiguous allocation scheme.
Initially , contiguous chunk of space is allocated
If this is not large enough , another chunk of space(extent) is allocated.
Extent-based file systems allocate disk blocks in extents
An extent is a contiguous block of disks
Extents are allocated for file allocation
A file consists of one or more extents.
Linked Allocation
block = pointer
Linked Allocation (Cont.)
Solves all problems of contiguous allocation.
Each file is a linked list of disk blocks: blocks may be scattered
anywhere on the disk.
Directory entry has a pointer to the first and last blocks of the file
Advantages:
Simple – need only starting address
No External Fragmentation
Size of a file need not be declared when the file is created
Files can continue to grow as long as free blocks are availble
Compaction not needed.
Linked Allocation
Dis advantages
No random access(Only sequential access)
Space required for pointers
(Each and every disk block has a pointer to the next disk block)
If pointers are lost or damaged?
Variation of linked allocation – File allocation Table (FAT) – Disk space
allocation used by MS DOS
A Section of disk at the beginning of each volume contains this table
File-Allocation Table
Indexed Allocation
Solves Direct access problem in linked allocation
Brings all pointers together into the index block rather than having a pointer in each and every disk block.
Logical view.
index table
Example of Indexed Allocation
Indexed Allocation (Cont.)
I th entry in the index block points to the ith block of the file.
Random access
Dynamic access without external fragmentation, but have overhead
of index block.
Dis advantages
Suffers from wasted space
More pointer overhead.
When there is a file occupying only two blocks , in linked
allocation , space for only two pointers is wasted , in indexed
allocation , one whole block is wasted.
How large the index block should be?
Mechanisms for index block variants
Linked scheme – Link together index blocks
An index block will contain addresses of disk blocks as well as address of
next index block
Two level index
First level index block points to a second level index block
second level index block points to file blocks
Indexed Allocation – Two level index
outer-index
index table file
Free-Space Management
To keep track of free disk space
To reuse the space from deleted files for new files
Free space list records all free disk blocks
To create a file , search for the space in the free list
Remove the space from the free space list
If file is deleted, add the space to the free - space list
Implementation of Free-Space Management – Bit vector
Bit vector (n blocks)
0 1 2 n-1
…
0 block[i] free
bit[i] =
1 block[i] occupied
Say , blocks 2,5,8,22 are free
1101101101111111111111011
Free-Space Management (Cont.)
Advantages
Simple
Efficient in finding the first free block, m consecutive free blocks
Dis Advantages
Requires extra space and is kept in main memory
Block size = 212 bytes
Disk size = 230 bytes
Number of blocks = 230 / 212 = 218
Number of bits in bit map is 218
Implementation of Free-Space Management – Linked List
Link together all the free blocks
Keep a pointer to the first free block on the disk and cache it in memory
The first block contains a pointer to the next block and so on
Cannot get contiguous space easily
No waste of space
Traversing the list takes time
Linked Free Space List on Disk
Implementation of Free-Space Management – Grouping
Store addresses of n free blocks in the first free block
Nth block contains the address of another n free blocks
Addresses of large number of free blocks can be found quickly
Implementation of Free-Space Management – Counting
Keep the address of the first free block and the number n of free
contiguous blocks that follow the first block
Each entry – a disk address and a count