1 / 65

Chapter 10: File-System Interface

Chapter 10: File-System Interface. Chapter 10: File-System Interface. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection. Objectives. To explain the function of file systems To describe the interfaces to file systems

toan
Download Presentation

Chapter 10: File-System Interface

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 10: File-System Interface

  2. Chapter 10: File-System Interface • 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. File Concept • The OS must provide a uniform logical view of information storage. • OS abstracts from the physical properties of its storage devices • Defines a logical storage unit, the file • Files are mapped by the OS onto physical devices. • A file is a named collection of related information • Recorded on secondary storage • Files represent both programs and storage • Contiguous logical address space • Types: • Data • numeric • character • binary • Program (source) • Object file (organized to be recognizable by linker) • Executable file

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

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

  7. File Operations • File is an abstract data type • Create. 1. Find space in the file system. 2. Create entry in the directory. • Write. Need to maintain a write pointer. • Read. Need to maintain a current-file-position pointer. • Reposition within file • Delete • Truncate • Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory • Close (Fi) – move the content of entry Fi in memory to directory structure on disk

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

  9. Open File Locking • Provided by some operating systems and file systems • 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

  10. 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();

  11. 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(); } } }

  12. File Types – Name, Extension

  13. Access Methods • Sequential Access read next write next reset no read after last write (rewrite) • Direct Access read n write n position to n read next write next rewrite n n = relative block number

  14. Sequential-access File

  15. Simulation of Sequential Access on a Direct-access File

  16. Access Methods • Other Access Methods • Can build other access methods on top of a direct-access method • Generally construct an index for the file. • Index contains pointers to blocks • To find a record, search the index, then use the pointer

  17. Access Methods • Example: Retail-price file • Lists universal product codes (UPCs) and associated prices • Each record: 10-digit UPC, 6-digit price (16 byte total) • A file of 120,000 records would take 2,000 blocks (2 million bytes). • Keep file sorted by UPC, then can define an index consisting of the first UPC in each block. • The index would have 2,000 entries of 10 digits or 20,000 bytes • Could keep in memory. • To find the price of an item, binary search the index.

  18. Example of Index and Relative Files

  19. Access Methods • Problem: index file may become too large to keep in memory • Solution: index the index file. • Example: IBM’s indexed sequential-access method (ISAM) • Small master index • That points to disk blocks of a secondary index • Secondary index points to actual file blocks • Keep sorted on a defined key • To find an item: • Binary search master index, get block number of secondary index • Read in block, perform binary search on secondary index • Determine desired block from this search and read it in • Search this block sequentially to find record.

  20. Directory Structure • A collection of nodes containing information about all files Directory Files F 1 F 2 F 3 F 4 F n Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes

  21. Directory Structure • Disk can be used in its entirety for a file system (FS) • Or can partition a disk to contain different FS • May also combine partitions into volumes and create FS on these • Each volume that contains a FS must contain info about the files in the system • Kept in entries in a device directory or volume table of contents. Usually just called a directory. • See next slide

  22. A Typical File-system Organization

  23. Directories • A directory is like a symbol table that translates file names into their directory entries. • Directories can be organized in many ways. • Must allow operations on directories

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

  25. 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 Java programs, all games, …)

  26. Single-Level Directory • A single directory for all users Naming problem Grouping problem

  27. Two-Level Directory • Separate directory for each user • Path name • Can have the same file name for different user • Efficient searching • No grouping capability

  28. Tree-Structured Directories

  29. Tree-Structured Directories (Cont) • Efficient searching • Grouping Capability • Sharing of files is not allowed • New information that file manager will need: • Current directory (working directory) • Directory that user process is currently working in • Path information: what directory paths to search to find commands and programs

  30. mail prog copy prt exp count Tree-Structured Directories (Cont) • Absolute or relative path name • 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 Deleting “mail”  deleting the entire subtree rooted by “mail” rmdir mail or rm –r mail

  31. Acyclic-Graph Directories • Have shared subdirectories and files No cycles allowed!

  32. Acyclic-Graph Directories (Cont.) • Two different names (aliasing) may point to same file • Don’t want to traverse shared structures more than once • One solution: Ignore links when traversing directories to avoid cycles • If dict deletes list dangling pointer • If the file space is reused, the dangling pointer may point to this file • Unix lets the user deal with this problem Solutions: • Backpointers, so we can delete all pointersVariable size records a problem: how many pointers do you store? • Entry-hold-count solution • New directory entry type • Link – another name (pointer) to an existing file • Resolve the link – follow pointer to locate the file

  33. General Graph Directory • Have shared subdirectories and files cycles allowed!

  34. General Graph Directory (Cont.) • How do we deal with cycles? • Allow only links to file not subdirectories (would prevent cycles) • Garbage collection • Traverse entire file system, mark everything that can be accessed • Second pass collects everything that is not marked into a list of free space • Very time consuming • Every time a new link is added use a cycle detectionalgorithm to determine whether it is OK • Bypass links when during directory traversal

  35. File System Mounting • A file system must be mounted before it can be accessed • Directory structure for the new volume must be built and added to the FS • Mounting • First, choose the mount point: the location within the file structure where new file system is to be attached • Typically an empty directory • Example: /home in Linux • To access directory structure within that file system, precede the directory names with the mount point • Example: /home/barr, /home/poore, /home/kropa

  36. File System Mounting • A file system must be mounted before it can be accessed • Directory structure for the new volume must be built and added to the FS • Mounting • Next, file manager verifies that the device contains a valid FS • Asks device driver to read the device directlry • Verifies that the directory has the expected format • Finally, OS notes in its directory structure that a file system is mounted at the specified mount point

  37. File System Mounting • Example (see next slide) • Triangles represent subtress • Figure a is the existing FS, figure b is unmounted vlume on /device/dsk. • Only files on existing FS can be accessed.

  38. (a) Existing. (b) Unmounted Partition

  39. File System Mounting • Example (see next slide) • New FS is mounted over /users. • Existing users are lost or obscured

  40. Mount Point

  41. Mount Points • Mac OS • When OS encournters a disk for the first time, searches for a FS on the device. • If it finds one, will automatically mount the FS at the root level • Adds a folder icon on the screen labeled with the name of the FS (as stored in the device directory)

  42. Mount Points • Windows family (95 through XP) • Maintains an extended two-level directory structure • Devices and volumes are asigned drive letters • Volumes have a general graph directory structure assoicated with the drive letter: • Drive-letter:\path\to\file • More recent versions allow a FS to be mounted anywhere in the directory tree (similar to UNIX). • Windows OS automatically discover all devices and mount at boot time

  43. Mount Points • UNIX • Mount commands are explicit. • A ssytems config file contains a list of devices and mount points for automatic mounting at boot time • Other mounts are executed manually.

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

  45. File Sharing – Multiple Users • Issues: • File sharing • File naming • File protection

  46. File Sharing – Multiple Users • System must mediate the file sharing • Must maintain more file and directory attributes than a single-user system • Most systems use two concepts: • file (or directory) owner (or user) • Group • The owner can change attributes and grant access • The group attribute defines a subset of users who can share access to the file (or directory)

  47. File Sharing – Multiple Users • When a user requests an operation on a file, file manager • Compares the user ID of the use requesting the operation with the owner attribute of the file • Then compares group IDs • Then can apply appropriate permissions

  48. File Sharing – Multiple Users • New attributes necessay: • User IDs identify users, allowing permissions and protections to be per-user • Group IDs allow users to be in groups, permitting group access rights

  49. File Sharing – Remote File Systems • Uses networking to allow file system access between systems • Manually via programs like FTP • Anonymous (no account on remote machine). • www uses this almost exclusively • Authenticated. • Used in DFS • Automatically, seamlessly using distributed file systems (DFS) • Semi automatically via theworld wide web • Need a browser • Use separate operations (essentially a wrapper for ftp) to transfer files

  50. File Sharing – Remote File Systems • Client-server model allows clients to mount remote file systems from servers • Machine containing the files is the server • Machine seeking access is the client • Server can serve multiple clients/client can use multiple servers • Client identification and authentication difficult • Network names and IP addresses can be spoofed • Can use encrypted keys; need to ensure same algm is used in client and server

More Related