Docsity

file system implementation, Exercises of Operating Systems

Toggle sidebar
bg1
Topics - emphasis on local file systems
•File-System Structure
•File-System Implementation
•Directory Implementation
•Allocation Methods
•Free-Space Management
•Efficiency and Performance
•Recovery
•Virtual File System
File and directory = abstraction of disk blocks
•logical disk blocks
Where are the disk blocks and how are they organized?
•disk sector = unit of storage
•disk block = unit of transfer, 1 or more sectors
•physical disk blocks, physical disk sectors
File System Structure and Implementation
Abstraction
•logical storage unit
•collection of related information
Implementation
•physical storage unit on disk
•logical to physical mapping
•free-space manager
Layered software design
•application programs
•virtual file system
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download file system implementation and more Exercises Operating Systems in PDF only on Docsity!

Topics - emphasis on local file systems

  • File-System Structure
  • File-System Implementation
  • Directory Implementation
  • Allocation Methods
  • Free-Space Management
  • Efficiency and Performance
  • Recovery
  • Virtual File System

File and directory = abstraction of disk blocks

  • logical disk blocks Where are the disk blocks and how are they organized?
  • disk sector = unit of storage
  • disk block = unit of transfer, 1 or more sectors
  • physical disk blocks, physical disk sectors

File System Structure and Implementation

Abstraction

  • logical storage unit
  • collection of related information Implementation
  • physical storage unit on disk
  • logical to physical mapping
  • free-space manager Layered software design
  • application programs
  • virtual file system
  • uniform abstractions
  • logical file system
  • metadata, file control block, protection and security
  • file-organization module
  • logical blocks, free-space manager
  • basic file system
  • physical blocks
  • buffers, caches
  • I/O control
  • device drivers, interrupt handlers
  • device controller
  • remote file system
  • raw disk File Control Block
  • permissions
  • usage times - create, access, write
  • owner, group
  • access control information
  • size
  • list of data blocks On disk (per partition)
  • boot control block
  • enough information to load and start the OS
  • partition control block
  • volume control block
  • superblock
  • directories
  • file control blocks
  • file contents
  • free-space information In memory
  • mount table
  • contraction Directory entry
  • file name, attributes
  • pointer to data blocks

Allocation Methods - physical disk blocks

Contiguous allocation

  • contiguous blocks on disk
  • starting block number, number of blocks
  • fast access, random access
    • n = (physical block size)
    • logical block = starting block + (logical byte address) / n
    • offset into logical block = (logical byte address) % n
  • treat disk blocks as linear array with dynamic partitioning
    • ordered by logical block number, OS translates to physical cylinder / track / sector
    • ordered by logical block number, disk controller translates to physical c/ t/s
  • all the problems of dynamic partitioning for main memory
    • external fragmentation
  • files cannot grow beyond initial allocation
    • compaction may be required
  • when is contiguous allocation appropriate? Extent-based allocation
  • extent = contiguous blocks on disk
  • file = sequence of extents
  • fast access if the extents are large
  • random access if the list of extents can be searched quickly Linked allocation
  • file = sequence of disk blocks as a linked list
  • starting block number, pointer to next block, pointer to last block
  • pointer in disk block?
    • m = (size of pointer to disk block)
    • n = (physical block size) - m
    • sequence number of logical block = (logical byte address) / n
    • offset into logical block = m + (logical byte address) % n
  • pointer in descriptor block?
    • File Allocation Table, MS-DOS
  • fast access? random access? fast append? large files?
  • free-space also a linked list? Comparison - linked allocation vs. FAT, which is better? [OSC 8e Fig. 11.6, 11.7; 9e Fig. 12.6, 12.7]
  • file control block information
  • direct blocks
    • linear array of pointers to disk blocks
  • single-indirect
    • pointer to root page of one-level index
  • double indirect
    • pointer to root page of two-level index
  • triple indirect
    • pointer to root page of three-level index Exercise. Given a file size and a block size, how many pointers do we need?

Free-space Management Which blocks on the disk are free?

  • Do we need a list of the blocks that are allocated? Bit vector
  • one bit per block, free or occupied
  • minor storage overhead
  • best matched to contiguous allocation Free list
  • best matched to linked allocation
  • pointer to next free block
  • linear array of pointers to free blocks Be careful!
  • bit vector in memory must agree with bit vector on disk
  • to allocate a free block -
  • set bit[i] = 1 on disk
  • allocate block[i]
  • set bit[i] = 1 in memory
  • to free an allocated block -
  • left as an exercise

Exercise. How many times do you need to read the disk before finding a free block?

Efficiency and Performance

  • disk allocation strategy
  • directory search algorithms
  • in-memory actions whenever possible Disk caching
  • keep recently-accessed disk blocks in main memory
  • use additional memory in disk controller Can access be improved by reordering requests?
  • synchronous writes
  • in order of request
  • asynchronous writes
  • collect several requests, act later in some order Optimized sequential access
  • free-behind
  • read-ahead
  • similar to page buffer for virtual memory? Page cache
  • virtual memory pages
  • memory-mapped file access
  • memory-mapped I/O Buffer cache, Disk cache
  • page cache is a subset
  • regular file access
  • regular I/O Unified buffer cache
  • managed by the OS for virtual memory, memory-mapped I/O and regular I/O Virtual disk, RAM disk
  • similar to memory-mapped files

■ may require interpreting the data

  • part of the file system
  • access method
  • standard interface between application programs and file system ■ requires interpreting the data
  • user's view of the file system File management functions
  • typical commands - create, delete, open, close, read, write
  • initiate file request
  • locate file
  • directory structure
  • obtain file attributes
  • verify permission
  • compare file and user attributes related to the specific request
  • access records (logical I/O)
  • access blocks (physical I/O)

Virtual File System

  • multiple file systems in one directory structure
  • object-oriented style
    • uniform method interfaces and naming conventions
    • unique implementations for each file system type
    • runtime mapping from generic to specific File system interface layer
  • open(), etc. (valid for any file or file system type)
  • file descriptors (including file system type and file location) VFS interface layer
  • generic operations are mapped to specific operations based on actual file system type or location
  • table of function pointers
  • fs_open(), etc. (specific to this file system type)
  • generic open() does table lookup then calls the appropriate specific fs_open()