Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2013 – 2

advertisement
Chapter 10:
File-System Interface
Operating System Concepts Essentials – 2nd Edition
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.2
Silberschatz, Galvin and Gagne ©2013
Objectives
 Explain function of file systems (FSs)
 Describe interfaces to file systems
 Discuss file-system design tradeoffs, e.g., access
methods, file sharing, file locking, and directory
structures
 Explore file-system protection
Operating System Concepts Essentials – 2nd Edition
10.3
Silberschatz, Galvin and Gagne ©2013
File Concept
 Contiguous logical address space
 Types:

Data
 numeric
 character
 binary

Program
 Contents defined by file’s creator

Many types
 Consider
text file, source file, executable file
Operating System Concepts Essentials – 2nd Edition
10.4
Silberschatz, Galvin and Gagne ©2013
File Attributes
 Name – only info kept in human-readable form
 Identifier – unique number identifies file within FS
 Type – for systems that support different types
 Location – pointer to file location on device
 Size – current file size
Operating System Concepts Essentials – 2nd Edition
10.5
Silberschatz, Galvin and Gagne ©2013
File Attributes
 Protection – who can read, write, execute
 Time, date, and user identification – data for
protection, security, and usage monitoring
 Information about files kept in directory structure,
maintained on disk
 Many variations, including extended file attributes
such as file checksum
 Information kept in directory structure
Operating System Concepts Essentials – 2nd Edition
10.6
Silberschatz, Galvin and Gagne ©2013
File info Window on Mac OS X
Operating System Concepts Essentials – 2nd Edition
10.7
Silberschatz, Galvin and Gagne ©2013
File Operations
 File is an abstract data type
 Create
 Open(Fi) – search directory structure on disk for
entry Fi, and move content of entry to memory
 Write – at write pointer location
 Read – at read pointer location
 Reposition within file - seek
 Close (Fi) – move content of entry Fi in memory to
directory structure on disk
 Delete
 Truncate
Operating System Concepts Essentials – 2nd Edition
10.8
Silberschatz, Galvin and Gagne ©2013
Open Files
 Info needed to manage open files:

Open-file table: tracks open files

File pointer: pointer to last read/write location
 One

per process with open file
File-open count: number of times a file is open
 Allows
removal of data from open-file table when last
process closes it

Disk location of file: cache of data access information

Access rights: per-process access mode information
Operating System Concepts Essentials – 2nd Edition
10.9
Silberschatz, Galvin and Gagne ©2013
Open File Locking
 Provided by some OSs and file systems

Similar to reader-writer locks

Shared lock similar to reader lock
 Several

processes can acquire concurrently
Exclusive lock similar to writer lock
 Only
one process can acquire at a time
Operating System Concepts Essentials – 2nd Edition
10.10
Silberschatz, Galvin and Gagne ©2013
Open File Locking
 Mediates file access
 Mandatory or advisory:

Mandatory – access denied based on locks held

Advisory – processes can find status of locks and
decide what to do
Operating System Concepts Essentials – 2nd Edition
10.11
Silberschatz, Galvin and Gagne ©2013
File Types – Name, Extension
Operating System Concepts Essentials – 2nd Edition
10.12
Silberschatz, Galvin and Gagne ©2013
File Structure
 None - sequence of words, bytes
 Simple record structure

Lines

Fixed length

Variable length
 Complex Structures

Formatted document

Relocatable load file
Operating System Concepts Essentials – 2nd Edition
10.13
Silberschatz, Galvin and Gagne ©2013
File Structure
 Can simulate simple and complex file structures
as seq. of bytes w/ appropriate control characters
 Who decides file structure?

OS

Program (e.g., MS Word)
Operating System Concepts Essentials – 2nd Edition
10.14
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.15
Silberschatz, Galvin and Gagne ©2013
Sequential Access
 Info in file processed in order, one record after another

read_next()

write_next()
 Both
automatically advance file pointer
Operating System Concepts Essentials – 2nd Edition
10.16
Silberschatz, Galvin and Gagne ©2013
Direct Access
 File made up of fixed-length logical records

Program can read / write records in no particular order

Read / write blocks directly
 Based on disk model of file

Disk allows random access to any file block

Leads to allocation problem- how store blocks on disk?
 Option for immediate access to large amounts of data

E.g., airline database- flights stored / access by number
Operating System Concepts Essentials – 2nd Edition
10.17
Silberschatz, Galvin and Gagne ©2013
Simulation of Sequential Access on Direct-access File
Operating System Concepts Essentials – 2nd Edition
10.18
Silberschatz, Galvin and Gagne ©2013
Other Access Methods
 Built on top of base methods
 Involves creating index for file
 Index kept in memory for fast determination of data
location
 If too large, index (in memory) of the index (on
disk)
Operating System Concepts Essentials – 2nd Edition
10.19
Silberschatz, Galvin and Gagne ©2013
Example of Index and Relative Files
Operating System Concepts Essentials – 2nd Edition
10.20
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.21
Silberschatz, Galvin and Gagne ©2013
Directory Structure
 Collection of nodes containing info about all files
Directory
Files
F1
F2
F3
F4
Fn
Both the directory structure and the files reside on disk
Operating System Concepts Essentials – 2nd Edition
10.22
Silberschatz, Galvin and Gagne ©2013
Disk Structure
 Disk can be subdivided into partitions
 Disks (or partitions) can be RAID protected
against failure
 Disk or partition can be used:

Raw – without a file system, or

Formatted - with a file system
Operating System Concepts Essentials – 2nd Edition
10.23
Silberschatz, Galvin and Gagne ©2013
Disk Structure
 Entity containing file system known as volume
 Each volume (containing FS) also tracks info in
device directory or volume table of contents
 There are both general-purpose file systems and
special-purpose file systems, frequently used by
same OS
Operating System Concepts Essentials – 2nd Edition
10.24
Silberschatz, Galvin and Gagne ©2013
A Typical File-system Organization
Operating System Concepts Essentials – 2nd Edition
10.25
Silberschatz, Galvin and Gagne ©2013
Operations Performed on Directory
 Search for a file
 Create a file
 Delete a file
 List a directory
 Rename a file
 Traverse file system
Operating System Concepts Essentials – 2nd Edition
10.26
Silberschatz, Galvin and Gagne ©2013
Directory Organization
 Directory organized logically for:

Efficiency
 Location

a file quickly
Naming
 Convenient

for users
Grouping
 Organize
files by properties
Operating System Concepts Essentials – 2nd Edition
10.27
Silberschatz, Galvin and Gagne ©2013
Single-Level Directory
 Single directory for all users
 Naming problem – files must have unique names
 Grouping problem – no grouping possible
Operating System Concepts Essentials – 2nd Edition
10.28
Silberschatz, Galvin and Gagne ©2013
Two-Level Directory
 Separate directory for each user
 Can have same file name for different users
 Efficient searching
 No grouping capability (no cooperation / sharing)
 Users isolated from each other
Operating System Concepts Essentials – 2nd Edition
10.29
Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories
Operating System Concepts Essentials – 2nd Edition
10.30
Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories (Cont.)
 Efficient searching
 Grouping Capability
 Current directory (working directory)

cd /spell/mail/prog

type list
Operating System Concepts Essentials – 2nd Edition
10.31
Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories (Cont)
 Absolute or relative path name
 Creating new file done in current working directory
 Delete a file
 Creating new subdirectory is done in current dir
Operating System Concepts Essentials – 2nd Edition
10.32
Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories
 Have shared subdirectories and files
Operating System Concepts Essentials – 2nd Edition
10.33
Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories (Cont.)
 Two different names (aliasing)
 If dict deletes list (previous slide) dangling pointer
Solutions:

Backpointers, to delete all pointers

Variable size records a problem

Backpointers use daisy chain organization

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
Operating System Concepts Essentials – 2nd Edition
10.34
Silberschatz, Galvin and Gagne ©2013
General Graph Directory
Operating System Concepts Essentials – 2nd Edition
10.35
Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
 How do we guarantee no cycles?

Allow only links to file not subdirectories

Garbage collection
 Periodically

traverse FS for inaccessible files, delete
Use cycle detection algorithm when new link added
Operating System Concepts Essentials – 2nd Edition
10.36
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.37
Silberschatz, Galvin and Gagne ©2013
File System Mounting
 FS must be mounted before it can be accessed
 FS mounted at a mount point
Operating System Concepts Essentials – 2nd Edition
10.38
Silberschatz, Galvin and Gagne ©2013
Mount Point
FS mounted at /users...
Operating System Concepts Essentials – 2nd Edition
10.39
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.40
Silberschatz, Galvin and Gagne ©2013
File Sharing
 Desirable to share files on multi-user system
 Sharing may be done through protection scheme
 On distributed systems, files may be shared across
a network
 Network File System (NFS) is common distributed
file-sharing method
Operating System Concepts Essentials – 2nd Edition
10.41
Silberschatz, Galvin and Gagne ©2013
File Sharing
 If multi-user system:

User IDs identify users, allowing permissions and
protections to be per-user

Group IDs allow users to be in groups, permitting
group access rights
Operating System Concepts Essentials – 2nd Edition
10.42
Silberschatz, Galvin and Gagne ©2013
File Sharing – Remote File Systems
 Uses networking to allow file system access between
systems

Manually via programs like FTP

Automatically using distributed file systems

Semi automatically via the world wide web
 Client-server model- clients mount remote file
systems from servers

Server can serve multiple clients

Client and user-on-client identification is insecure or
complicated

NFS - standard UNIX client-server file sharing protocol
Operating System Concepts Essentials – 2nd Edition
10.43
Silberschatz, Galvin and Gagne ©2013
File Sharing – Failure Modes
 All file systems have failure modes

E.g., corruption of directory structures or other nonuser data, called metadata
 Remote file systems add new failure modes, due to
network failure, server failure

Recovery can involve state information about status
of each remote request

Stateless protocols (e.g., NFS v3) include all
information in each request, allowing easy recovery
but less security
Operating System Concepts Essentials – 2nd Edition
10.44
Silberschatz, Galvin and Gagne ©2013
Chapter 10: File-System Interface
 File Concept
 Access Methods
 Disk and Directory Structure
 File-System Mounting
 File Sharing
 Protection
Operating System Concepts Essentials – 2nd Edition
10.45
Silberschatz, Galvin and Gagne ©2013
Protection
 File owner/creator controls:

What can be done

By whom
 Types of access

Read

Write

Execute

Append

Delete

List
Operating System Concepts Essentials – 2nd Edition
10.46
Silberschatz, Galvin and Gagne ©2013
Download