File System: Access - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

File System: Access

Description:

Root file system mounted by ad hoc means at boot-time and contains programs and ... Consistency physical file may not be updated causing consistency problems when ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 11
Provided by: quynh6
Category:

less

Transcript and Presenter's Notes

Title: File System: Access


1
File System Access
  • Unix mounting
  • Operation makes a file system visible in the name
    space
  • Root file system mounted by ad hoc means at
    boot-time and contains programs and data needed
    to mount other file systems
  • Mount point
  • Directory on which file system is mounted
  • Previous contents of directory are no longer
    accessible
  • Syntax
  • /sbin/mount ltdevice or remote fsgt ltdirectorygt
  • /etc/fstab
  • file describing the file system and swapping
    partitions
  • Sysadmin can modify it with text editor
  • Also read by mount and un-mount commands
  • To un-mount, file system must have no users no
    open files or users whose current working
    directory is in the file system
  • Windows analog mapping file systems

2
File System Access
  • Why is mounting useful?
  • Allows addition of new file systems
  • Ability to un-mount and re-mount means that file
    system names can be re-used
  • Late binding server not forced to be ready when
    client comes up
  • Reasons for un-mounting
  • Backing up file system
  • Significant change of disk data structures or
    important files or changes to many files
  • Changing name of file system

3
File System Access
  • After file system is mounted, read/write from/to
    files enabled through system calls
  • System call is slower than memory access, so map
    files to memory locations
  • Memory-mapped access
  • Map portion of file to memory region designated
    by user or chosen by OS
  • Access to Nth byte of memory region is access to
    Nth byte of file
  • Updated pages are written back to disk eventually
  • Syntax 2 new system calls
  • Map
  • Unmap
  • When to write-back to disk?
  • When instructed by user
  • When process exits
  • When paged out
  • When unmap is called

4
File System Memory-mapped Access
  • Advantages
  • Simpler programming interface, but data typing
    can rarely be applied to memory regions filled at
    runtime
  • Since pages are faulted into memory, read exactly
    those pages that are referenced and not more
  • Eliminate double copying and double buffering
  • Copy file block into reserved OS buffer
  • Copy again into process virtual memory space
  • Disadvantages
  • Hard for system to know exact length of file
    since write command (which specifies number of
    bytes written) is not used
  • Consistency physical file may not be updated
    causing consistency problems when there are
    writers and readers
  • File may be larger than segment or virtual
    address space, so need to map only a portion of
    the file

5
File System Interface
  • File descriptors
  • Returned by open, creat, dup, pipe, socket,
    socketpair
  • Manipulated by fcntl
  • File descriptor is a small integer
  • Conventional meanings
  • 0) stdin
  • stdout
  • stderr
  • Why couldnt hash of file name serve as
    descriptor?
  • May have several descriptors per file
  • May want to reuse a descriptor for several
    different files over time

6
File System Interface
  • Per-process descriptor table
  • File descriptor indexes into descriptor table
  • An entry contains
  • Open mode (read, read/write, etc.)
  • special behaviour flags no-delay, asynch,
    close-on-exec, append, etc.
  • Pointer to global open file table
  • Unix global file table
  • Multiple file descriptors can point to same
    global file table entry created by
  • Dup within a single process
  • Fork across separate processes
  • 2nd open of same file in same process actually
    creates a new descriptor and 2nd entry in global
    table

7
File System Interface
  • Unix global file table entry contains
  • Type of object
  • Pointer to object-specific record inode, mode,
    sock (function pointers for operations)
  • File offset pointer for sequential access
  • Reference count
  • Incremented on dup, fork, etc.
  • Decremented on close, exit (implicit close) and
    exec if marked close-on-exec
  • Entry is destroyed when reference count goes to 0

8
File System Interface
  • Why 2 tables per-process and global?
  • Want separate processes to be able to share file
    pointer, so need a global table
  • Want to allow a process to use the same
    descriptor number for different purposes
    (different files or different open-modes of same
    file), so need a per-process table

9
File Allocation
  • Contiguous allocation
  • Not really used anymore on hard-drive, but used
    for read-only media (CDROMs and DVDs)
  • Each file stored in contiguous space
  • Store starting block and length of each file in a
    table
  • Linked-list allocation
  • File not in contiguous space
  • Each block of file points to the next block
  • For efficiency, store pointers to next block in a
    table instead of with file block File
    Allocation Table (FAT)
  • But table may get very large if disk is large, so
    store only open file block pointers in table
    (stored as an inode)

10
File Allocation
  • Inodes
  • Each file has an inode with file attributes and
    disk addresses of file blocks
  • Only inodes for open files are stored in memory
  • When files grow, access the additional free disk
    blocks pointed to in the last disk address of
    inode
Write a Comment
User Comments (0)
About PowerShow.com