Download Chapter 10: File System

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
Chapter 10: File System
Operating System Concepts – 9th Edition
Silberschatz, Galvin and Gagne ©2013
File Concept
n
Contiguous logical address space
n
Types:
l
l
n
Data
4
numeric
4
character
4
binary
Program
Contents defined by file’s creator
l
Many types
4
Consider text file, source file, executable file
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File Attributes
n
Name – only information kept in human-readable form
n
Identifier – unique tag (number) identifies file within file system
n
Type – needed for systems that support different types
n
Location – pointer to file location on device
n
Size – current file size
n
Protection – controls who can do reading, writing, executing
n
Time, date, and user identification – data for protection, security, and
usage monitoring
n
Information about files are kept in the directory structure, which is
maintained on the disk
n
Many variations, including extended file attributes such as file checksum
n
Information kept in the directory structure
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File Operations
n
File is an abstract data type
n
Create
n
Write – at write pointer location
n
Read – at read pointer location
n
Reposition within file - seek
n
Delete
n
Truncate
n
Open(Fi) – search the directory structure on disk for entry Fi, and
move the content of entry to memory
n
Close (Fi) – move the content of entry Fi in memory to directory
structure on disk
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Open Files
n
Several pieces of data are needed to manage open files:
l
Open-file table: tracks open files
l
File pointer: pointer to last read/write location, per process that
has the file open
l
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
l
Disk location of the file: cache of data access information
l
Access rights: per-process access mode information
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Open File Locking
n
Provided by some operating systems and file systems
l
Similar to reader-writer locks
l
Shared lock similar to reader lock – several processes can acquire
concurrently
l
Exclusive lock similar to writer lock
n
Mediates access to a file
n
Mandatory or advisory:
l
Mandatory – access is denied depending on locks held and
requested
l
Advisory – processes can find status of locks and decide what to
do
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File Types – Name, Extension
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File Structure
n
n
n
n
n
None - sequence of words, bytes
Simple record structure
l Lines
l Fixed length
l Variable length
Complex Structures
l Formatted document
l Relocatable load file
Can simulate last two with first method by inserting appropriate
control characters
Who decides:
l Operating system
l Program
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Access Methods
n
n
n
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access – file is fixed length logical records
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
Relative block numbers allow OS to decide where file should be placed
l
See allocation problem in Ch 11
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Directory Structure
n
A collection of nodes containing information about all files
Director
y
Files
F
1
F
2
F
3
F
4
F
n
Both the directory structure and the files reside on disk
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Types of File Systems
n
We mostly talk of general-purpose file systems
n
But systems frequently have may file systems, some general- and
some special- purpose
n
Consider Solaris has
l
tmpfs – memory-based volatile FS for fast, temporary I/O
l
objfs – interface into kernel memory to get kernel symbols for
debugging
l
ctfs – contract file system for managing daemons
l
lofs – loopback file system allows one FS to be accessed in place
of another
l
procfs – kernel interface to process structures
l
ufs, zfs – general purpose file systems
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Operations Performed on Directory
n
Search for a file
n
Create a file
n
Delete a file
n
List a directory
n
Rename a file
n
Traverse the file system
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Organize the Directory (Logically) to Obtain
n
Efficiency – locating a file quickly
n
Naming – convenient to users
n
l
Two users can have same name for different files
l
The same file can have several different names
Grouping – logical grouping of files by properties, (e.g., all Java
programs, all games, …)
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Single-Level Directory
n
A single directory for all users
Naming problem
Grouping problem
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Two-Level Directory
n
Separate directory for each user
n
Path name
n
Can have the same file name for different user
n
Efficient searching
n
No grouping capability
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Tree-Structured Directories (Cont.)
n
Efficient searching
n
Grouping Capability
n
Current directory (working directory)
l cd /spell/mail/prog
l
type list
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Acyclic-Graph Directories
n
Have shared subdirectories and files
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
General Graph Directory (Cont.)
n
How do we guarantee no cycles?
l
Allow only links to file not subdirectories
l
Garbage collection
l
Every time a new link is added use a cycle detection algorithm to
determine whether it is OK
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File System Mounting
n
A file system must be mounted before it can be accessed
n
A unmounted file system (i.e., Fig. 10-11(b)) is mounted at a
mount point
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
File Sharing
n
Sharing of files on multi-user systems is desirable
n
Sharing may be done through a protection scheme
n
On distributed systems, files may be shared across a network
n
Network File System (NFS) is a common distributed file-sharing method
n
If multi-user system
l
User IDs identify users, allowing permissions and protections to be
per-user
Group IDs allow users to be in groups, permitting group access rights
l
Owner of a file / directory
l
Group of a file / directory
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013
Protection
n
n
File owner/creator should be able to control:
l
what can be done
l
by whom
Types of access
l
Read
l
Write
l
Execute
l
Append
l
Delete
l
List
Operating System Concepts – 9th Edition
11.*
Silberschatz, Galvin and Gagne ©2013