Chapter 11 File Systems by ruf23140

VIEWS: 12 PAGES: 42

									Chapter 11 File-System Interface




                               1
          Outline

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




                           2
11.1 File Concept




                    3
          Introduction

• 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




                                    4
         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.


                                5
             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
                                                  zero
       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
                                                  disk
                                           6
           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


                                        7
A Typical Open-File Table




            8
               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

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




                     10
             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
11.2 Access Methods




                      12
            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
                                       13
Access Methods – Index and
Relative File




           14
11.3 Directory Structure




                           15
         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.




                                16
A Typical File-System
Organization




            17
           Information in a Device
           Directory
•   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)


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




                               19
          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, …)




                                   20
          Single-Level Directory

• A single directory for all users.




         Naming problem
         Grouping problem




                                 21
         Two-Level Directory

• Separate directory for each user.




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




                 Subdirectory is just a
                 special type of file…
            23
          Tree-Structured Directories
          (Cont.)
• 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




                               24
             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




                                           25
Symbolic VS. Hard Link




            26
           Acyclic-Graph Directories
           (Cont.)
• If /dict/w/list is deleted ⇒ dangling pointer.
• Solutions: Preserve the file until all references to it are
  deleted
   – 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




                                       27
General Graph Directory




            28
          General Graph Directory
          (Cont.)
• 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




                                     29
11.4 File-System Mounting




                            30
          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
  point
• 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

                                     31
         File-System Mounting

   Existing                                Mount
                     Un-mounted
                                           Point
                       Partition
                    (/device/disk)




Unavailable when /device/disk is mounted
                                 32
11.5 File Sharing




                    33
          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
• Network File System (NFS) is a common distributed file-
  sharing method
• A remote file system must be mounted before using
   – mount claven.lib.nctu.edu.tw:/OS /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

                                   34
             Remote File-System
             Mounting Example
           root                                    root


          chow                            Export   OS

                         Mount
paper             book                     DFS            DSM
                                         /OS/DSM


        DFS              DSM /chow/book/DSM


        Local Client                          Remote Server




                                    35
          Remote File-System
          Mounting
• 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


                                      36
No Global Naming in NFS




           37
A Simple Automounter for
NFS




            38
11.6 Protection




                  39
           Protection

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



                               40
          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)

                                   41
Access Lists and Groups
(Cont.)




           42

								
To top