Docsity

File Systems: Implementation and Allocation Methods - Prof. Michael W. Hicks, Study notes of Operating Systems

Partial preview of the text

Download File Systems: Implementation and Allocation Methods - Prof. Michael W. Hicks and more Study notes Operating Systems in PDF only on Docsity!

CMSC 412

File System Implementation

Announcements

  • Reading
    • Chapter 12
    • Chapter 14 next time

Virtual File Systems

  • Virtual File Systems (VFS) provide an

object-oriented way of implementing

file systems.

  • VFS allows the same system call

interface (the API) to be used for

different types of file systems.

  • The API is to the VFS interface, rather

than any specific type of file system.

Virtual File System

A Typical File Control Block

Caching Metadata

Allocation Methods

  • An allocation method refers to how

disk blocks are allocated for files:

  • Contiguous allocation
  • Linked allocation
  • Indexed allocation

Contiguous Allocation

  • Each file is a set of contiguous blocks on disk
  • Pros
    • Simple – only starting location (block #) and length (number of blocks) are required.
    • Random access.
  • Cons
    • Wasteful of space (external fragmentation).
    • Files cannot grow without some headaches

Linked Allocation

Modified Linked Allocation

(FAT)

  • Section of disk contains a table
    • called the file allocate table (FAT)
    • used in MS-DOS
  • Directory entry contains the block

number of the first block in the file

  • Table entry contains the number of

the next block in the file

  • Last block has a end-of-file value as a

table entry

FAT Example

Extents

  • An extent combines linked and

contiguous allocation:

  • Have a contiguous chunk of data, but then also have a pointer to the next chunk, if such a chunk is needed.
  • In other words, blocks can either be linked to, or adjacent to another block

Indexed Allocation

  • Pros
    • Random access
    • No external fragmentation
  • Cons
    • Must go through index block on dynamic accesses
    • May need very large index blocks to support large files; depends on the size of file blocks. Imposes per-file overhead.

Indexed Allocation

  • How to make index block extensible?
  • Linked scheme:
    • maintain a linked list of indexed blocks
  • Multilevel index:
    • Index block can point to other index blocks (which point to index blocks ....), which point to files
  • Hybrid multi-level index (UNIX)
    • first n blocks are from a fixed index
    • next m blocks from an indirect index
    • next o blocks from a double indirect index

UNIX (4K per block)

UNIX File Sizes

  • Assume 4096 byte block:
    • first 12 blocks (48 KB) from a fixed index
    • next 1024 blocks (4 MB) from an indirect index
    • next 10242 blocks (4 GB) from a double indirect index
    • final 1024^3 blocks (4 TB) from a triple indirect index

Linked List

  • Each disk block contains the pointer to

the next free block

  • Pointer to first free block is keep in a

special location on disk

Linked Free Space List on Disk

Run Length Encoding

  • Pointer to first free block is kept in a

special location on disk

  • Each free block also includes a count

of the number of consecutive blocks

that are free

  • Called counting in book
    • Similar to extents for allocated files

Implementing Directories

  • Linear List
    • array of names for files
    • must search entire list to find or allocate a filename
    • sorting can improve search performance, but adds complexity
  • Hash table
    • use hash function to find filenames in directory
    • needs a good hash function
    • need to resolve collisions
    • must keep table small and expand on demand since many directories are mostly empty

Inodes

  • File i ndex node
  • Contains:
    • Pointers to blocks in a file (direct, single indirect, double indirect, triple indirect)
    • Type and access mode
    • File’s owner
    • Number of references to file
    • Size of file
    • Number of physical blocks

Unix directories - links

  • Each file has unique inode but it may have multiple directory entries in the same filesystem to reference inode
  • Each directory entry creates a hard link of a filename to the file’s inode - Number of links to file are kept in a reference count variable in the inode - If links are removed, file is deleted when number of links becomes zero
  • Symbolic or soft link
    • Implemented as a file that contains a pathname
    • Symbolic links do not have an effect on inode reference count

File Lookup (/usr/bin/vi)

Indirect Index Root “/” inode = Directory Entry usr Directory Entry bin Directory Entry vi bin inode usr inode Data Block vi inode

UNIX data structures

  • Example: find /usr/bin/vi
    • (from Leffler, McKusick, Karels and Quarterman)
    • Search root directory of filesystem to find /usr
      • root directory inode is, by convention, stored in inode #
      • inode shows where data blocks are for root directory - these blocks (not the inode itself) must be retrieved and searched for directory entry usr
      • from its entry we discover that usr ’s inode is #
    • Search usr for bin
      • access blocks pointed to by inode #4 and search contents of blocks for entry that gives us bin’s inode
      • we discover that bin’s inode is #
    • Search bin for vi
      • access blocks pointed to by inode #7 and search contents of block for an entry that gives us vi’s inode
      • we discover that vi’s inode is inode #
    • Access inode #7 - this is vi’s inode

Log-Structured File Systems

  • Key Idea
    • Use transactions-like model for filesystem updates
  • Write data to a log (also called a journal)
    • Records meta data changes
    • Records data blocks written
    • File operation is committed when added to the log
    • Partial updates to log are lost on failure
  • Next Step
    • Eliminate the filesystem and just keep the log
    • Requires a process called a cleaner
      • Copies old data from log to head of log to allow compaction

NFS : Network File System

  • Provides a set of remote procedure calls for remote file operations.
  • NFS servers are stateless ; each request has to provide a full set of arguments.
  • Modified data must be committed to the server’s disk before results are returned to the client (lose advantages of caching).

Layers of NFS Architecture

  • UNIX file-system interface - based on the open, read, write, and close calls, and file descriptors.
  • Virtual File System (VFS) layer – distinguishes local files from remote ones, and local files are further distinguished according to their file-system types. - The VFS activates file-system-specific operations to handle local requests according to their file- system types. - Calls the NFS protocol procedures for remote requests.
  • NFS service layer – bottom layer of the architecture; implements the NFS protocol.

NFS Architecture