Chapter 12: FileSystem Implementation - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Chapter 12: FileSystem Implementation

Description:

File/directory names & pointers to FCB's ... FCB representation includes data blocks of a file ... Log-Based Recovery ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 21
Provided by: dUmn
Category:

less

Transcript and Presenter's Notes

Title: Chapter 12: FileSystem Implementation


1
Chapter 12 File-System Implementation
  • Translation of logical to physical addresses
  • Logical file blocks 0, 1, , N-1
  • Physical disk addresses device, cylinder,
    sector
  • File control block, Directory implementation
  • Allocation methods
  • Free space management
  • Log-structured file systems

2
File Control Blocks (FCB)
  • Files are represented on disk by file control
    blocks
  • FCBs contain
  • Permissions
  • Dates
  • Owner, group, ACL
  • Size
  • Data blocks (e.g., pointers to these blocks)
  • FCB may actually be multiple blocks on disk
  • E.g., if pointers to data blocks require more
    space than can fit in a single disk block

3
Directory Representation
  • Directories contain
  • File/directory names pointers to FCBs
  • On UNIX, directories represented just like files,
    except data blocks of a directory file contain a
    series of name/FCB pointer entries

On Linux, directory entries form a linked list.
Why?

4
Some Relevant Methods for a Directory Class
  • class Directory
  • Directory()
  • Directory ()
  • void Add(char name, Entry e)
  • void Remove(char name)
  • void Entry Find(char name)

5
Directory Find Method
  • Want to implement method
  • // retrieve directory entry for a given file name
  • // e.g., method of Directory class/type
  • Entry Find(char fileName)
  • Linear List
  • List of names of files pointers to data blocks
  • Find/insert/delete Need to sequentially search
    list
  • O(n) time complexity to search list n
    directory size
  • Hash Table
  • Given a file name, hash function gives index into
    table
  • Need collision resolution upon insert/delete/find

6
Hierarchical directories
  • How do you represent a hierarchical directory
    structure?
  • E.g., for system call creat(/home/users/data.txt
    , 0777)
  • How do you locate appropriate directory?

7
Pseudo-code
  • // assume we have Directory root
  • // giving us a pointer to / directory
  • Entry e root-gtFind(home)
  • If (e NULL) (! e-gtIsDirectory()) then
    error
  • Directory d e-gtConvertToDirectory()
  • e d-gtFind(users)
  • If (e1 NULL) (! e-gtIsDirectory()) then
    error
  • d e-gtConvertToDirectory()
  • e d-gtFind(data.txt)
  • If (e NULL) then
  • // No file exists, so create new file
  • If (e-gtIsDirectory() then error
  • // otherwise, file exists, so make zero length

Note Complete implementation would iterate
through path name
8
FCB (File Control Block)Data Block Organization
  • FCB representation includes data blocks of a file
  • File contains blocks 0, 1, , N-1, and we need to
    map those blocks to the physical blocks of a disk
  • How should this representation be organized?
  • Constraints on disk block allocation
  • Effectively use disk space
  • Provide fast file access

9
Common methods of allocation
  • Contiguous blocks for a specific file allocated
    together, in a sequence on the physical device
  • FCB has pointer to first block number blocks in
    file
  • Linked Use space in each data block for a
    pointer to next block indicate end block with
    special value pointer (e.g., -1)
  • FCB contains pointer to first block in linked
    list
  • Indexed Use separate (index) blocks of disk
    space for pointers to data blocks of the file
  • FCB contains pointer(s) to index block(s)

10
Contiguous allocation
  • Efficient method for direct (relative) access
  • In direct access we need to be able to compute
    the disk address relative to the start of a file
  • Easy here, because the blocks are in a linear
    sequence from some starting address on device
  • Issues
  • Internal fragmentation we may have to specify
    the maximum extent that the file will grow to
  • External fragmentation
  • We may have sufficient number of disk blocks to
    create a new file, but they may not be in a
    contiguous sequence

11
Linked Allocation
  • Efficient method for sequential access
  • File pointer is represented by disk block and
    offset
  • No external fragmentation
  • Issues
  • Direct access is slow!
  • Access to ith block requires i disk accesses
  • In each block, use some space for disk block
    pointer (e.g., 32, 64 bits)
  • On average ½ block internal fragmentation
  • Reliability If we one block pointer is
    corrupted, we loose file after that point

12
FAT Variation on Linked Allocation
  • Additional information in disk partition
  • File allocation table (FAT)
  • Array of blocks on a disk
  • Each array entry is
  • 0 (unused), or
  • index of next block in particular file, or
  • EOF indication for particular file
  • If FAT is cached
  • speeds direct access to file blocks

13
Indexed Allocation
  • Positive aspects
  • More efficient method for direct access
  • Also good for sequential access
  • No external fragmentation (all disk blocks can be
    used)
  • Issues
  • Overhead for pointers increases
  • On average ½ of a block internal fragmentation
  • What if a large file requires more space than a
    single index block?
  • Linked index blocks
  • Multilevel indexing

14
UNIX inode structure
  • inode is the UNIX FCB (file control block)
  • Variable level indexed allocation method
  • Direct pointers contained in FCB
  • Multi-level indirect index blocks
  • Question Is the Unix inode suitable for
    sequential or direct (relative) file access?

15
Free-Space Management
  • Need to keep track of disk blocks (sectors) not
    allocated to a file or directory
  • Creating a file
  • Allocate blocks from free space
  • Deleting a file
  • Return blocks to the free space
  • Free space data structures
  • Bit vector each bit indicates if a block is free
  • Linked list link each free block together on the
    disk
  • Grouping index blocks of free blocks
  • Counting count of contiguous blocks available

16
Disk Device Access
  • Disk devices are not truly random access
  • Head(s) on disk move across disk surface
  • To tracks, cylinders of disk
  • Faster access to data block currently under head
  • Rotational latency
  • Time to rotate to a sector on current track
  • Seek latency
  • Time to move head from current track to another
    track
  • Contiguous blocks on a track will be accessed
    faster
  • Rotational seek latencies are amortized
    (divided) across the number of contiguous blocks
  • UNIX makes use of this by attempting to keep
    data blocks for a file near the inode for a file

17
File System Consistency
  • Metadata file system structure, not user file
    contents
  • File system operations typically involve several
    metadata changes
  • E.g., file create involves
  • Directory modification, FCB allocation, Data
    blocks allocated, Free counts decremented
  • If system crashes part way through file creation
    sequence, then
  • File system metadata () will be inconsistent
  • Want sequences of metadata changes to be atomic
  • Sequence of changes should be all completed or
    not done at all
  • E.g., want all of file create changes to occur or
    none

18
Log-Based Recovery
  • A solution to this problem is to apply log-based
    techniques to file-system meta-data updates
  • Write meta-data changes to a log file,
    sequentially
  • Log file is a disk structure, separate from file
    system
  • Each series of changes that performs some task
    (e.g., create a file) is a transaction
  • Once series of changes written to log, they are
    committed
  • File system is now updated from the log
  • Entries for the transaction removed when update
    to file system is completed
  • Upon a system crash
  • Check if there unprocessed transactions in log
  • Reverse (rollback) partially completed
    transactions

19
Network File Systems - 1
  • NFS
  • Generic abbreviation for network file systems
  • Also, a specific network file system, NFS
  • Textbook discusses specific NFS system
  • NFS is a Unix network file system
  • Goals
  • Allow some degree of file sharing among a set of
    independent computers
  • Should provide transparent access
  • Provide sharing between any two computers
  • Heterogeneous set of computers, O/S, networks

20
Network File Systems - 2
  • Client-server organization
  • Uses RPC based services based on XDR (external
    data representation)
  • XDR converts between data representation of
    client/server computer
  • Each computer runs a server
  • Client operation
  • Mount remote directory mounted over directory of
    local file system
  • 1) name of remote (server) directory sent to
    server computer via RPC
  • 2) server checks export list of export-allowable
    file systems
  • 3) server returns to client a file handle
  • Similar to a file descriptor, but works across
    network and allows access to file system and not
    just a single file
  • File access
  • Files are opened, read, written, closed etc.
    using same system calls as with non-NFS files
  • File system uses client NFS file handle to
    access remote file system
Write a Comment
User Comments (0)
About PowerShow.com