Your SlideShare is downloading. ×
  • Like
Chapter 10 File-System Interface
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Chapter 10 File-System Interface

  • 1,131 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,131
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
45
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Chapter 10 File-System Interface
  • 2. Contents
    • File Concept
    • Access Methods
    • Directory Structure
    • File-System Mounting
    • File Sharing
    • Protection
  • 3. Objectives
    • To explain the function of file systems
    • To describe the interfaces to file systems
    • To discuss file-system design tradeoffs , including access methods, file sharing, file locking, and directory structures
    • To explore file-system protection
  • 4. Interface versus Implementation
    • Interface : what you see, what you feel, how you handle it, …
    • Implementation : internal structures, made, basic flow
  • 5. 10.1 File Concepts
    • Computers store information on several nonvolatile media, such as
      • magnetic disks (diskettes, floppy disks)
      • magnetic tapes
      • optical disks
      • solid-state disks (flash disks)
    • The OS abstracts from the physical properties of its devices to define a logical storage unit – the file
  • 6. File Concept
    • A file is a named collection of related information that is recorded on secondary storage
    • Contiguous logical address space
    • Types:
      • Data
        • numeric
        • character
        • binary
      • Program
  • 7. File Structure
    • None - sequence of words, bytes
    • Simple record structure
      • Lines
      • Fixed length
      • Variable length
    • Complex structures
      • Formatted document
      • Relocatable load file
    • Can simulate last two with first method by inserting appropriate control characters
    • Who decides:
      • Operating system
      • Program
  • 8. 10.1.1 File Attributes
    • Name – only information kept in human-readable form
    • Identifier – unique tag (number) identifies file within file system
    • Type – needed for systems that support different types
    • Location – pointer to file location on device
    • Size – current file size
    • Protection – controls who can do reading, writing, executing
    • 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 disk
  • 9. 10.1.2 File Operations
    • Basic operations
      • create (allocate space, make an entry in directory)
      • write
      • read
      • reposition within file – file seek
      • delete
      • truncate (keep all attributes, reset to length zero)
    • Other operations
      • rename
      • copy
      • append
  • 10. File Operations
    • To save constant search of the directory, many OS require the open and close system call
      • open( F i ) – search the directory structure on disk for entry F i , and move the content of entry to memory
      • close( F i ) – move the content of entry F i in memory to directory structure on disk
        • a file can be closed explicitly, or implicitly when the process aborts/terminates
  • 11. Open Files
    • Several pieces of data are needed to manage open files:
      • File pointer : pointer to last read/write location, per process that has the file open
      • File-open count : counter of number of times a file is open – to allow removal of data from open-file table when last processes closes it
      • Disk location of the file: cache of data access information
      • Access rights : per-process access mode information
  • 12. Open-file Tables
    • A file can be opened simultaneously by more than one processes in name of several users
    • A per-process table tracks all files that a process has open
      • next read/write position, etc.
      • a pointer to an entry in the system-wide table
    • A system-wide table contains process-independent information
      • location on disk, access dates, file size, etc.
      • an open count tracks the number of processes
  • 13. Open File Locking
    • Provided by some operating systems and file systems
      • a shared lock
      • an exclusive lock
    • Mediates access to a file
    • Mandatory or advisory
      • Mandatory – access is denied depending on locks held and requested
      • Advisory – processes can find status of locks and decide what to do
  • 14. File Locking Example – Java API
    • import java.io.*;
    • import java.nio.channels.*;
    • public class LockingExample {
    • public static final boolean EXCLUSIVE = false;
    • public static final boolean SHARED = true;
    • public static void main(String arsg[]) throws IOException {
    • FileLock sharedLock = null;
    • FileLock exclusiveLock = null;
    • try {
    • RandomAccessFile raf = new RandomAccessFile("file.txt", "rw");
    • // get the channel for the file
    • FileChannel ch = raf.getChannel();
    • // this locks the first half of the file - exclusive
    • exclusiveLock = ch.lock(0, raf.length()/2, EXCLUSIVE);
    • /** Now modify the data . . . */
    • // release the lock
    • exclusiveLock.release();
  • 15. File Locking Example – Java API (cont)
    • // this locks the second half of the file - shared
    • sharedLock = ch.lock(raf.length()/2+1, raf.length(), SHARED);
    • /** Now read the data . . . */
    • // release the lock
    • exclusiveLock.release();
    • } catch (java.io.IOException ioe) {
    • System.err.println(ioe);
    • }finally {
    • if (exclusiveLock != null)
    • exclusiveLock.release();
    • if (sharedLock != null)
    • sharedLock.release();
    • }
    • }
    • }
  • 16. 10.1.3 File Types – Name, Extension
    • basename. extension
    • DOS, Windows
      • .com .exe
      • .bat
      • .asm .c
      • .obj
    • Unix, Linux
      • .c
      • .o
      • .tar .gz
    • Macintosh
      • store creator
  • 17. 10.1.4 File Structure
    • File types may indicate the internal structure of the file
    • Certain files must conform to a required structure that is understood by the OS
      • e.g. executable file, DLLs
      • a set of system supported files
    • Unix, Linux and DOS support a minimal number of file structures
  • 18. 10.1.5 Internal File Structure
    • Logical blocks
      • Unix OS defines all files to be simply a stream of bytes
    • Physical blocks (on disk)
      • a sector, typically 512 bytes
    • packing – store a number of logical records into physical blocks
    • internal fragmentation : some waste portion of the last block of each file
  • 19. 10.2 Access Methods
    • Sequential Access
    • Direct Access (a.k.a. Random Access)
  • 20. 10.2.1 Sequential Access
    • information in the file is processed in order, one record after the other
      • read next
      • write next
      • reset (rewind to the very beginning)
      • * skip forward or backward n records
  • 21. 10.2.2 Direct Access
    • Direct access (relative access) allows programs to read and write records rapidly in no particular order read n
    • write n
    • position to n
    • read next
    • write next
    • rewrite n
    • n = relative block number
  • 22. Simulation of Sequential Access on a Direct-access File
  • 23. 10.2.3 Other Access Method Example of Index and Relative Files Other access methods can be built on top of a direct-access method
  • 24. 10.3 Directory Structure
    • File organization
      • partition (minidisk, volume)
        • can be smaller or larger than a physical disk drive
        • a logical/virtual disks
        • different partitions can store multiple OS
      • directory
        • name, location, size, type etc. for all files on that partition
  • 25. A Typical File-system Organization
    • several partitions may share a disk
    • a partition may span over several disks
  • 26. 10.3.2 Directory Overview
    • A collection of nodes containing information about all files
    F 1 F 2 F 3 F 4 F n Directory Files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes
  • 27. Information in a Directory
    • name
    • type
    • address
    • current length
    • maximum length
    • date last accessed (for archival)
    • date last updated (for dump)
    • owner ID (who pays)
    • protection information
  • 28. Operations Performed on Directory
    • Search for a file
    • Create a file
    • Delete a file
    • List a directory
    • Rename a file
    • Traverse the file system
  • 29. Organize the Directory 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 Java programs, all games, …)
  • 30. 10.3.3 Single-Level Directory
    • A single directory for all users
    • Naming problem
      • require unique names
      • limited name length (e.g. DOS 8.3, Unix 255)
      • Grouping problem
  • 31. 10.3.4 Two-Level Directory
    • Separate directory for each user
      • master file directory (MFD)
      • user file directory (UFD)
    • Path name
    • Can have the same file name for different user
    • Efficient searching
    • No grouping capability
      • users may want to share files
  • 32. 10.3.5 Tree-Structured Directories
  • 33. Tree-Structured Directories (Cont)
    • Efficient searching
    • Grouping Capability
    • Current directory (working directory)
      • cd /spell/mail/prog
      • type list
  • 34. Tree-Structured Directories (Cont)
    • Absolute path name begins at the root
    • Relative path name is a path from the current directory
    • Creating a new file is done in current directory
    • Delete a file
    • rm <file-name>
    • Creating a new subdirectory is done in current directory
      • mkdir <dir-name>
    • Example: if in current directory /mail
    • mkdir count
    mail prog copy prt exp count Deleting “mail”  deleting the entire subtree rooted by “mail”
  • 35. 10.3.6 Acyclic-Graph Directories
    • Have shared subdirectories and files
  • 36. Acyclic-Graph Directories (Cont.)
    • A file may have multiple absolute path names
      • distinct file names may refer to the same file
    • Problems
      • disk usage (quota) calculation
      • backup
      • deletion
        • dangling pointers to non-existent file, and even worse, to the disk address reused by other files (maybe in the middle)
  • 37. Unix/Linux solution
    • hard link (traditional link)
      • a file is actually deleted only when the reference count hits zero
      • limit: file only, same file system
    • symbolic link (soft link)
      • can spans over file systems (volumes)
      • can link to a directory
      • Windows use the same approach ( short-cut )
    • lab exercise
  • 38. 10.3.7 General Graph Directory
  • 39. 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
  • 40. 10.4 File System Mounting
    • A file system must be mounted before it can be accessed
      • a directory structure can be built out of multiple partitions
    • An unmounted file system is mounted at a mount point , the location with the directory structure
    • Example
      • mount /dev/hda5 /mnt/diskD
      • umount /dev/hda5
      • umount /mnt/diskD
  • 41. Example (in Linux)
    • mount /dev/… /users
    • the previous contents of the directory (at the mount point) becomes invisible as long as the (new) file system remains mounted
    • a file system may be mounted only once
    existing unmounted partition mount point
  • 42. 10.5 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
  • 43. 10.5.1 Multiple Users
    • The OS must mediate the file sharing
    • Access control and protection
      • owner (user), who may change attributes, grant access, has the most control over the file and directory
      • group , a subset of users who may share access to the file
    • User identifiers (uid) and group identifies (gid) are associated with all of the user’s processes and threads
      • a user can be in one or more groups, depending on the OS
      • User IDs identify users, allowing permissions and protections to be per-user
      • Group IDs allow users to be in groups, permitting group access rights
    • User IDs and group IDs are stored with other file or directory attributes
    • The user information within a process are compared to the attributes of the file or directory to determine which permissions are applicable
  • 44. *10.5.2 Remote File Systems
    • Uses networking to allow file system access between systems
      • Manually via programs like FTP
      • Automatically, seamlessly using distributed file systems
      • Semi automatically via the world wide web
    • Client-server model allows clients to mount remote file systems from servers
      • Server can serve multiple clients
      • Client and user-on-client identification is insecure or complicated
      • NFS is standard UNIX client-server file sharing protocol
      • CIFS is standard Windows protocol
      • Standard operating system file calls are translated into remote calls
    • Distributed Information Systems ( distributed naming services ) such as LDAP, DNS, NIS, Active Directory implement unified access to information needed for remote computing
  • 45. RFS – Failure Modes
    • Remote file systems add new failure modes, due to network failure, server failure
    • Recovery from failure can involve state information about status of each remote request
    • Stateless protocols such as NFS include all information in each request, allowing easy recovery but less security
  • 46. 10.5.3 Consistency Semantics
    • Consistency semantics specify how multiple users are to access a shared file simultaneously)
      • Andrew File System (AFS) implemented complex remote file sharing semantics
    • Unix file system (UFS) implements:
      • Writes to an open file visible immediately to other users of the same open file
      • Sharing file pointer to allow multiple users to read and write concurrently
        • pointer moved by one user affects all sharing users
    • AFS has session semantics
      • Writes only visible to sessions starting after the file is closed
  • 47. 10.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
  • 48. Access Lists and Groups
    • Mode of access: read, write, execute
    • Three classes of users
    • RWX
    • a) owner access 7  1 1 1 RWX
    • b) group access 6  1 1 0
    • RWX
    • c) public access 1  0 0 1
    • 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.
    Attach a group to a file chgrp G game owner group public chmod 761 game
  • 49. A Sample UNIX Directory Listing
  • 50. Windows XP Access-Control List
  • 51. 10.7 Summary
    • a file is a named collection of information
    • a file is a sequence of logical records
      • a logical record may be a byte, a line, fixed or variable length structure, etc.
      • an OS may support various record types, or leave that support to the application programs
    • basic operations : read, write, etc.
  • 52. Summary
    • directories allow files to be organized
      • single-level
      • two-level, allow multiple users
      • tree-structured
      • acyclic-graph
        • (hard) link , symbolic link
    • directory includes information about files
      • name, location on disk, length, type, owner, time of creation, time of last use, access control list, etc.
  • 53. Summary
    • a disk may divided into multiple partitions , a partition (volume) may spans over disks
    • a volume (file system) should be mounted before use, and unmounted to disable access
  • 54. Summary
    • file sharing depends on the semantics provided by the OS
    • access control, protection
      • file attributes: owner (creator), group
      • user identity: uid, gid
      • type of access: read, write, execute, append, delete, list directory, etc.
  • 55. Homework
    • Paper work
      • 1, 4, 7
    • Oral work
      • all the remaining problems
    • Lab exercise (on Linux)
      • link, symbolic link
      • permissions and protections