Chapter 11 File Systems by ruf23140


									Chapter 11 File-System Interface


•   File Concept
•   Access Methods
•   Directory Structure
•   File-System Mounting
•   File Sharing
•   Protection

11.1 File Concept


• OS abstracts from the physical storage devices to define a
  logical storage unit: File
• Types:
   – Data: numeric, alphabetic, alphanumeric, binary
   – Program: source and object form

         File Attributes

• Name – only information kept in human-readable form
• Type – needed for systems that support different types
• Location – pointer to file location on device
• Size – current file (and the maximum allowable) size
• Protection – controls who can read, write, execute
• Time, date, and user identification – data for protection,
  security, and usage monitoring.
• Information about files are kept in the directory structure,
  which is maintained on the physical storage device.

             File Operations
•   Create                                 •   Delete
     – Allocate space                           – Search the directory
     – Make an entry in the directory           – Release all file space
•   Write                                  •   Truncate --
     – Search the directory                     – All attributes to remain unchanged,
                                                  but for the file to be reset to length
     – Write is to take place at the
       location of the write pointer
•   Read                                   •   Open(Fi)
                                                – Search the directory structure on
     – Search the directory
                                                  disk for Fi
     – Read is to take place at the
                                                – Move the content of the directory
       location of the read pointer
                                                  entry to memory
•   Reposition within file – file seek
                                           •   Close(Fi)
     – Set the current file pointer to a
                                                – move the content of entry Fi in
       given value
                                                  memory to directory structure on
           Open-File Table
• OS keeps a small table containing information about all
  open files
   – Each time a file is opened, the content of the directory entry of the
     file is moved into the table
        • File Handle (file descriptor, file control block): an index into the
          table for a file
• Two levels of internal tables in multi-user OS
   – Per-process table: All the files opened by a process
      • Current file pointer
   – System-wide open-file table: Process independent information
      • Location of file on disk, access dates, file size
      • File open count

A Typical Open-File Table

               Two-Level Open-File Table

File Pointer   …..

Open File Table
                       File name       Location on Disk   File Open Count   …….
for Proc. A

File Pointer   …..

Open File Table                          System-Wide Open File Table
for Proc. B

File Types – Name,
Extension If OS recognizes the type of a file, it can
          operate on the file in a reasonable way

             File Structure
•   None - sequence of words, bytes
•   Simple record structure
     – Lines
     – Fixed length
     – Variable length
•   Complex Structures
     – Formatted document
     – Relocatable load file
•   All operating systems must support at least one structure – that of an
    executable file
•   Who decides:
     – Operating system
     – Program

11.2 Access Methods

            Access Methods
• Sequential Access: information is processed in order
   –   read next
   –   write next (append to the end of the file)
   –   reset to the beginning of file
   –   skip forward or backward n records
• Direct Access: a file is made up of fixed length logical blocks
  or records
   –   read n
   –   write n
   –   position to n
   –   read next
   –   write next
   –   rewrite n
                                        Sequential-access file
Access Methods – Index and
Relative File

11.3 Directory Structure

         Directory Structure

• A collection of nodes containing information about all files.
• Both the directory structure and the files reside on disk.
• Backups of these two structures are kept on tapes.

A Typical File-System

           Information in a Device
•   Name
•   Type: file, directory, symbolic link, special file…
•   Address: device blocks to store a file
•   Current length
•   Maximum length
•   Date last accessed (for archival)
•   Date last updated (for dump)
•   Owner ID (who pays)
•   Protection information (discuss later)

           Operations Performed on
•   Search for a file
•   Create a file
•   Delete a file
•   List a directory
•   Rename a file
•   Traverse the file system

          Organize the Directory
          (Logically) to Obtain…
• Efficiency – locating a file quickly.
• Naming – convenient to users.
   – Two users can have same name for different files.
   – The same file can have several different names.
• Grouping – logical grouping of files by properties, (e.g., all
  Pascal programs, all games, …)

          Single-Level Directory

• A single directory for all users.

         Naming problem
         Grouping problem

         Two-Level Directory

• Separate directory for each user.

            Path name
            Can have the same file name for different user
            Efficient searching
            No grouping capability
Tree-Structured Directories

                 Subdirectory is just a
                 special type of file…
          Tree-Structured Directories
• Efficient searching
• Grouping Capability
• Current directory (working directory)
   – cd /spell/mail/prog
   – cat list
• Create a new file/subdirectory is done in current directory
• Absolute path name & relative path name
• How to handle the deletion of a directory

             Acyclic-Graph Directories
•   Can have shared subdirectories
    and files.
    – A shared file can have different
      names (aliasing)                          /spell/count

•   Shared file implementation
    – Symbolic link: a pointer to
      another file or directory
        • ln -s /spell/count /dict/count
    – Hard link: duplicate all
      information (especially device
      address) in shared directory

Symbolic VS. Hard Link

           Acyclic-Graph Directories
• If /dict/w/list is deleted ⇒ dangling pointer.
• Solutions: Preserve the file until all references to it are
   – Backpointers: a list of all references to a file (directory entries or
     symbolic links)
      • Variable size records a problem
   – Entry-hold-count solution: a count
      • A count of the number of references
      • Used in UNIX for hard links

General Graph Directory

          General Graph Directory
• How do we guarantee no cycles?
   – Allow only links to file not subdirectories
   – Garbage collection
   – Every time a new link is added use a cycle detection
     algorithm to determine whether it is OK
• Traversal problem…
   – Don’t traverse the same directory or file twice

11.4 File-System Mounting

          File-System Mounting
• A file system must be mounted before it can be accessed
• A file system is mounted at a directory called the mount
• Mounting steps: mount /device/dsk /users
   – Give the device name and the mount point
   – Verify that the device contains a valid file system
      • Check if the device directory has a valid format
   – OS notes that a file system is mounted at the specified mount point
• What if the mount-point contains files?
   – The original files are not available, until the file system is un-mounted
• Same file system can be mounted repeatedly, at different
  mount points

         File-System Mounting

   Existing                                Mount

Unavailable when /device/disk is mounted
11.5 File Sharing

          File Sharing

• Sharing of files on multi-user systems is desirable
• Sharing may be done through a protection scheme
• On distributed systems, files may be shared across a
• Network File System (NFS) is a common distributed file-
  sharing method
• A remote file system must be mounted before using
   – mount /chow/book
   – Once files are mounted, they are accessed by using the
     concatenated logical path names without referencing either the
     remote hosts or local devices

             Remote File-System
             Mounting Example
           root                                    root

          chow                            Export   OS

paper             book                     DFS            DSM

        DFS              DSM /chow/book/DSM

        Local Client                          Remote Server

          Remote File-System
• Different clients may perceive a different FS view
   – To achieve a global FS view – SA enforces mounting rules
• Export: a file server restricts/allows the mounting of all or
  parts of its file system to a predefined set of hosts
   – The information is kept in the server’s export file
• File system mounting:
   – Explicit mounting: clients make explicit mounting system calls
     whenever one is desired
   – Boot mounting: a set of file servers is prescribed and all mountings
     are performed the client’s boot time
   – Auto-mounting: mounting of the servers is implicitly done on demand
     when a file is first opened by a client

No Global Naming in NFS

A Simple Automounter for

11.6 Protection


• File owner/creator should be able to control
   – What can be done
   – By whom
• Types of access
   –   Read
   –   Write
   –   Execute
   –   Append
   –   Delete
   –   List

          Access Lists and Groups

• Mode of access: read, write, execute
• Three classes of users: owner, group, universe
   – User name and user identifier
   – Group name and group identifier
• Ask manager to create a group (unique name), say G, and
  add some users to the group
• For a particular file (say game) or subdirectory, define an
  appropriate access
• In UNIX: three field of 3 bits each
   – field: read, write, execute
   – Bits: r(4), w(2), x(1)

Access Lists and Groups


To top