File System Implementation 1!11!21
File System Implementation 1!11!21
File System
Implementation
FS Implementation
Overview
◼ File-System Structure
◼ File System Implementation
◼ Disk Allocation Methods
◼ Free-Space Management
FS Implementation
File-System Structure
◼ I/O transfers between memory and disk are
performed in units of blocks
➢ one block is one or more sectors
➢ one sector is usually 512 bytes
FS Implementation
Layered File System
read(fh, buf, size) app program (API)
FS manager
FS Implementation
On-Disk Structure
◼ Boot control block (per partition): information needed
to boot an OS from that partition
➢ typical the first block of the partition (empty means no OS)
➢ UFS (Unix File Sys.): boot block, NTFS: partition boot sector
◼ Partition control block (per partition): partition details
➢ details: # of blocks, block size, free-block-list, free FCB
pointers, etc
➢ UFS: superblock, NTFS: Master File Table
◼ File control block (per file): details regarding a file
➢ details: permissions, size, location of data blocks
➢ UFS: inode, NTFS: stored in MFT (relational database)
◼ Directory structure (per file system): organize files
FS Implementation
File Control Block
A File Control Block (FCB) is a file system structure
in which the state of an open file is maintained. A
FCB is managed by the operating system, but it
resides in the memory of the program that uses
the file, not in operating system memory. This
allows a process to have as many files open at one
time as it wants to, provided it can spare enough
memory for an FCB per file.
FS Implementation
On-Disk Structure
Partition File Control Block (FCB)
Boot Control
Block (Optional)
Partition Control
Block
List of Directory
Control Blocks
Lis of File
Control Blocks
Data Blocks
FS Implementation
In-Memory Structure
◼ in-memory partition table: information about
each mounted partition
◼ in-memory directory structure: information of
recently accessed directories
◼ system-wide open-file table: contain a copy of
each opened file’s FCB
◼ per-process open-file table: pointer (file
handler/descriptor) to the corresponding
entry in the above table
FS Implementation
File-Open & File-Read
FS Implementation
File Creation Procedure
1. OS allocates a new FCB
2. Update directory structure
1. OS reads in the corresponding directory
structure into memory
2. Updates the dir structure with the new file
name and the FCB
3. (After file being closed), OS writes back the
directory structure back to disk
3. The file appears in user’s dir command
FS Implementation
Virtual File System
◼ VFS provides an object-oriented way of
implementing file systems
◼ VFS allows the same system call interface to be used
for different types of FS
◼ VFS calls the appropriate FS routines based on the
partition info
FS Implementation
Virtual File System
◼ Four main object types defined by Linux VFS:
➢ inode ➔ an individual file
➢ file object ➔ an open file
➢ superblock object ➔ an entire file system
➢ dentry object ➔ an individual directory entry
◼ VFS defines a set of operations that must be
implemented (e.g. for file object)
➢ int open(…) ➔ open a file
➢ ssize_t read() ➔ read from a file
FS Implementation
Directory Implementation
◼ Linear lists
➢ list of file names with pointers to data
blocks
➢ easy to program but poor performance
insertion, deletion, searching
FS Implementation
Directory Implementation
◼ Hash table – linear list w/ hash data structure
➢ constant time for searching
➢ linked list for collisions on a hash
entry
➢ hash table usually has fixed # of entries
FS Implementation