Docsity

File System Implementation - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download File System Implementation - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

File System Implementation

Chapter 11

File-System Structure

  • A file system poses two distinct design problems - Defining how the file system should look to the user - Creating algorithms and data structures to map the logical file system onto the physical device
  • File system resides on secondary storage (disks)
  • File system organized into layers.
    • Each level uses the lower level to create new features for use by higher levels
  • File control block – storage structure consisting of information about a file

File-System Implementation

  • Several on-disk and in-memory structures are used

to implement a file system

  • On-disk structures
    • A boot control block
    • A partition control block (superblock)
    • A directory structure
    • file control blocks
  • In-memory structures
    • An in-memory partition table
    • An in-memory directory structure
    • The system-wide open-file table
    • The per-process open-file table

Creating a File

  • To create a new file the application program calls the logical

file system (which knows the format of the directory structures)

  • Allocates a new FCB
  • Reads the appropriate directory into memory
  • Updates the directory with new file name and FCB
  • Writes back to disk
  • Some operating systems (UNIX) treat a directory exactly as a

file, other operating systems (Windows), implement separate system calls for files and directories and treat directories separate from files.

In-Memory File System Structures

(a) refers to opening a file. (b) refers to reading a file.

Closing a File

  • After all I/O operations are complete a file should be

closed

  • The per-process table entry is removed and the system- wide entry’s open count is decremented
  • When all users that have opened the file close it, the updated file information is copied back to the disk-based directory structure and the system-wide open-file table entry is removed
  • Some systems Use a caching a scheme. All

information about an open file, except for its actual

data blocks, is in memory

Directory Implementation

  • Linear List
    • Uses a linear list of file names with pointers to data blocks, requires a linear search to find a particular entry
    • Simple to program but time-consuming to execute
  • Hash Table
    • Uses a linear list to stores directory entries but uses hashing to find the entry
    • Hashing can greatly decrease the directory search time
    • Handle collisions – situations where two file names hash to the same location
    • Major difficulties with a hash table are its fixed size and dependence on the hash function

Allocation Methods

  • An allocation method refers to how disk blocks are allocated

for files

  • Three major methods of allocating disk space are in wide use
    • Contiguous allocation
    • Linked allocation
    • Indexed allocation
  • Each method has its advantages and disadvantages
  • Some systems support all three but more commonly a system

will use one particular method

Contiguous Allocation of Disk Space

Contiguous Allocation (Cont.)

  • Contiguous allocation has some problems
    • Dynamic storage-allocation
      • How to satisfy a request of size n from a list of free blocks
    • External fragmentation
      • Free space is broken into chunks and the largest chunk is insufficient for a request
    • Determining how much space is needed for a file
      • Allocate too little and the file may not be extended
      • Allocate too much and space is wasted
    • File cannot grow

Linked Allocation

  • Solves all the problems of contiguous allocation
  • Each file is a linked list of disk blocks: blocks may be scattered

anywhere on the disk

  • The directory contains a pointer to the first and last blocks of

a file

block = pointer

Linked Allocation

File-Allocation Table

Indexed Allocation

  • Solves the external-fragmentation and size-declaration

problems of contiguous allocation

  • Supports direct access by bringing all the pointers together

into the index block

  • Each file has its own index block, which is an array of disk-

block addresses

index table