Download 10. FileSys Intf

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

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

Document related concepts
Transcript
Operating Systems
Certificate Program in Software Development
CSE-TC and CSIM, AIT
September -- November, 2003
10. File System Interface
(Ch. 10 S&G)
 Objectives
– describe the user interface to the file
system (files, directories, access)
OSes: 10. FileSys Intf.
1
Contents
1. The File Concept
2. Access Methods
3. Directory Structure
4. Protection
5. Consistency Semantics
OSes: 10. FileSys Intf.
2
1. The File Concept
 The
file system provides a uniform logical
view of physical storage.
 Smallest
logical storage unit is the file
– usually mapped to storage on a nonvolatile
physical device
OSes: 10. FileSys Intf.
3
1.1. File Attributes
 Name
 Type
 Location
 Size
 Protection
– access controls for who can read,
write, execute the file
 Time(s)
OSes: 10. FileSys Intf.
4
1.2. File Operations
 View
a file as an abstract data type
– data as bits/bytes/lines/records
– operations
 Six
basic operations:
– create, write, read, seek in a file, delete,
truncate
OSes: 10. FileSys Intf.
continued
5
 Requires
read and write pointers, or a
current-file-position pointer.
 Other
possible operations:
– append, copy, rename
– get/set file attributes
– etc.
OSes: 10. FileSys Intf.
6
1.3. Opening a File

open() finds the file and stores a pointer to
it in an open file table (OFT).
 I/O
operations use the pointer rather than
the file name so there is no need to search
for the file each time.
OSes: 10. FileSys Intf.
7
Multi-user Variation
 Several
users may have the same file open
at the same time.
 Use
two levels of internal tables:
– an OFT per process storing details on the
open files of the process
 e.g.
file pointers, access rights
– a system-wide OFT storing
process-independent details on the files
 location
OSes: 10. FileSys Intf.
on disk, size, open count, lock(s)
8
Two-level File Tables
VUW CS 305
OFT
process P1
OFT
system OFT
process P2
OSes: 10. FileSys Intf.
9
1.4. File Types
 Useful
so the OS can automatically modify
its processing behaviour
– e.g. differentiate between source code (open
with an editor) and object code (execute)
– know that files are ‘related’
e.g. example.c and example.o
OSes: 10. FileSys Intf.
continued
10
 Approaches:
– file name extensions (e.g. Windows)
– creator attributes (e.g. Mac)
– magic numbers (e.g. UNIX)
OSes: 10. FileSys Intf.
11
1.5. File Structures
 Most
modern OSes support a minimal
number of file structures directly
– e.g. UNIX sees every file as a sequence of
8-bit bytes
 Benefits:
– applications have more flexibility
– simplifies the OS
OSes: 10. FileSys Intf.
12
Internal File Structures
 Packing
is required to convert between
logical records and physical blocks
– internal fragmentation will occur
Logical records
Physical blocks
OSes: 10. FileSys Intf.
13
2. Access Methods
 2.1.
Sequential Access
Fig. 10.3, p.347
current
position
beginning
end
rewind
read or write
OSes: 10. FileSys Intf.
14
2.2. Direct Access
 A file
is made up of fixed length logical
records (a disk model).
 Can
move quickly to any record location by
supplying a relative record number
– relative to the current record position
– e.g.
seek(20);
// move to rec. 20
seek(-1);
// move to rec. 19
read();
OSes: 10. FileSys Intf.
15
2.3. Indexed Access
Fig. 10.5, p.349
 Make
an index file for the file, which
contains pointers to various records
– improves search time
index Adams
file Arthur
Asher
:
:
Smith
Smith, John 007
23
direct access file
OSes: 10. FileSys Intf.
16
2.4. Memory Mapping
 Map
sections of a file into virtual memory.
 Reads
and writes to the mapped region act
as reads and writes to the file.
 Useful
way of sharing a file
– but requires a mutual exclusion mechanism
OSes: 10. FileSys Intf.
continued
17
Memory Mapping Diagram
file
region
region
Process B
virtual memory
Process A
virtual memory
physical memory
OSes: 10. FileSys Intf.
18
3. Directory Structure
 Partitions
(mini-disks, volumes)
– provide separate logical spaces on one disk
– group several disks into a single logical space
 Device
directory
– holds file information (e.g. name, location, size,
type) for all files in that partition
OSes: 10. FileSys Intf.
19
Typical Directory Operations
 Search
 Create
a file
 Delete a file
 List a directory
 Remove a file
 Traverse all the files
– e.g. for making backups
OSes: 10. FileSys Intf.
20
Types of Directory Structure
 3.1.
Single-level Directory
 3.2.
Two-level Directory
 3.3.
Tree-structured Directory
 3.4.
Acyclic Graph Directory
 3.5.
General Graph Directory
OSes: 10. FileSys Intf.
21
3.1. Single-level Directory
Fig. 10.7, p.351
 Easy
to support and understand.
 Problems start when there are large
numbers of files and/or users.
log
OSes: 10. FileSys Intf.
foo
recs1
test
data
mail
recs2
22
3.2. Two-level Directory Fig. 10.8, p.352
user1
user2
Master File
user3 Directory (MFD)
User File
Directory
(UFD)
log
OSes: 10. FileSys Intf.
foo
recs1
test
data
mail
recs2
continued
23
Some Issues
 How
isolated are users?
 How
is a path defined?
– e.g. /user1/foo
 How
do users access system files?
– copying
– (extendible) search paths
OSes: 10. FileSys Intf.
24
3.3. Tree-structured Directory
Fig. 10.9, p.354
root
dict
list
all
w
count words
count
list
OSes: 10. FileSys Intf.
spell
rade
list
w7
continued
25
 Treat
a subdirectory like another file
– use a special bit in the directory entry to
distinguish a file (0) from a subdirectory (1)
 Absolute
– e.g.
 How
OSes: 10. FileSys Intf.
vs. relative path names?
/spell/words/rade
../spell/words/rade
is a non-empty subdirectory deleted?
26
3.4. Acyclic Graph Directory
Fig. 10.10, p.357
root
dict
list
all
w
count words
count
list
OSes: 10. FileSys Intf.
spell
rade
list
w7
continued
27
 A natural
generalisation of a tree-structured
directory scheme
– allows files/subdirectories to be shared
 How
are cycles avoided?
 A file/subdirectory
may have multiple
absolute path names
– complicates traversal
OSes: 10. FileSys Intf.
continued
28
 How
are shared files/subdirectories deleted?
– leave ‘dangling pointers’ (cheap)
– use an access list (expensive)
– use a reference count
OSes: 10. FileSys Intf.
29
Sharing in UNIX
 Symbolic
links
– a pointer to another file/subdirectory
– easily identified by a bit set in the file entry
– deletion leaves links ‘dangling’
 Hard
links
– keep a reference count for hard links to a file
– cannot link to a subdirectory
 avoids
OSes: 10. FileSys Intf.
cyclic graphs
30
3.5. General Graph Directory
Fig. 10.10, p.357
root
avi
text
mail
count
jim
book
book
avi
OSes: 10. FileSys Intf.
mail
count
continued
31
 Traversal
could go into an infinite loop
– use a bounded search
 A subdirectory
that refers to itself will never
have a reference count of 0
– not possible to delete it
 Garbage
collection is required to reclaim
inaccessible files/subdirectories
– very expensive
OSes: 10. FileSys Intf.
32
4. Protection
 Protection
mechanisms control/limit file and
directory access operations, such as:
– reading, writing, execution,
appending, deletion, listing
 Protection
levels and types depend on the
system
– PC --> corporate installation
OSes: 10. FileSys Intf.
33
4.1. Access Lists & Fields
 Access
List
– specify access rights for every user of every file
– tedious; leads to very large lists
 Fields
(Groups)
– owner/group/world
– each field in UNIX has 3 bits for read, write,
and execute permissions
OSes: 10. FileSys Intf.
34
UNIX Example

bazooka<ad>47: ls
total 62
drwxr-xr-x 2 ad
-rw-r--r-- 1 ad
-rw-r--r-- 1 ad
-rw-r--r-- 1 ad
drwxr-xr-x 2 ad
-rw-r--r-- 1 ad
drwxr-xr-x 2 ad
-rwxr-xr-x 1 ad
-rw-r--r-- 1 ad
-rw-r--r-- 1 ad
OSes: 10. FileSys Intf.
Fig. 10.12, p.364
-l
512
14109
1878
782
512
24450
512
11676
4150
887
Nov
Nov
Nov
Nov
Feb
Nov
Nov
Feb
Dec
Nov
4 1998 Figures/
12 1998 Listings
4 1998 abstract.tex
4 1998 cover-note
16 08:59 old_code/
4 1998 progHTTP.txt
12 1998 revisted/
16 08:52 sock_brow*
22 17:07 sock_brow.c
4 1998 web-tech-addr
35
4.2. Passwords
 A password
per file
– too hard to remember
 A password
per subdirectory
– too course-grained
OSes: 10. FileSys Intf.
36
5. Consistency Semantics
 Consistency
semantics is how an OS deals
with modifications to a shared file by
multiple users who are accessing the file at
the same time.
OSes: 10. FileSys Intf.
37
Consistency Sems for UNIX
 A write
is immediately visible to every
shared users.
 Processes
may share the current position
pointer of the file.
 Users
see a shared file as representing a
single physical entity.
OSes: 10. FileSys Intf.
38
Consistency Sems for Andrew FS
 A distributed
file system from CMU.
 A write
is not immediately visible.
 A change becomes visible to subsequent
opens after the file has been closed.
 Users
see a shared file as representing
several temporary (possibly different)
images of the single physical entity.
OSes: 10. FileSys Intf.
39
Immutable Shared Files
 A type
of file which cannot be modified if
it is declared as shareable by its creator.
 Greatly
simplifies sharing in a distributed
file system.
OSes: 10. FileSys Intf.
40