Ch11 File System
description
Transcript of Ch11 File System
Course 11: File-System
11.2 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Course 10: Review
Virtual memory – separation of user
logical memory from physical memory.
Only part of the program needs to be
in memory for execution
Logical address space can therefore
be much larger than physical address
space
Allows address spaces to be shared
by several processes
Allows for more efficient process
creation
11.3 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Course 10: Review – Demand Paging
11.4 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Course 10: Review – Copy on Write
11.5 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Course 10: Review – Page Replacement
11.6 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Course 11: File-System
File Concept
Access Methods
Directory Structure
Protection
File-System Structure
File-System Implementation
Allocation Methods
11.7 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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
To describe the details of implementing local file systems and
directory structures
11.8 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File Concept
11.9 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File Concept
Resource for storing information
Contiguous logical address space
User point of view
Interface to information (usually hierarchical)
OS point of view
Data structures and allocation management algorithms
Files contains
Data
Meta-data - FCB
11.10 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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 – e.g. XML
Who decides:
Operating system
Program
11.11 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File Types – Name, Extension
11.12 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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
11.13 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File Operations
File is an abstract data type
Operations:
Create
Write
Read
Reposition within file
Delete
Truncate
11.14 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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
11.15 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Access Methods
11.16 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Sequential-access File
11.17 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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
11.18 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Simulation of Sequential Access on a Direct-access File
11.19 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Example of Index and Relative Files
11.20 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Directory Structure
11.21 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Directory Structure
A collection of nodes containing information about all files
F 1 F 2F 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
11.22 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
A Typical File-system Organization
11.23 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Operations Performed on Directory
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
11.24 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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, …)
11.25 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Single-Level Directory
A single directory for all users
Naming problem
Grouping problem
11.26 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Two-Level Directory
Separate directory for each user
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
11.27 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Tree-Structured Directories
Efficient searching
Grouping capability
11.28 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
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
prog copy prt exp count
Deleting “mail” deleting the entire subtree rooted by “mail”
11.29 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Acyclic-Graph Directories
Have shared subdirectories and files
11.30 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Acyclic-Graph Directories (Cont.)
Two different names (aliasing)
If dict deletes list dangling pointer
Solutions:
Backpointers, so we can delete all pointers
Variable size records a problem
Backpointers using a 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
11.31 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Protection
11.32 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Protection
File owner/creator should be able to control:
what can be done
by whom
Types of access
Read
Write
Execute
Append
Delete
List
11.33 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Access Lists and Groups
Mode of access: read, write, execute
Three classes of users
RWX
a) owner access 7 1 1 1RWX
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.
owner group public
chmod 761 game
Attach a group to a file
chgrp G game
11.34 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Windows XP Access-control List Management
11.35 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
A Sample UNIX Directory Listing
11.36 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File System Structure
11.37 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File-System Structure
File structure
Logical storage unit
Collection of related information
File system resides on secondary storage (disks)
File system organized into layers
File control block – storage structure consisting of information
about a file
11.38 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Layered File System
11.39 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File System Implementation
11.40 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
OS File Control Structures
A boot control block (per volume) - contain information needed by
the system to boot an operating system from that volume
A volume control block (per volume) contains volume (or
partition) details, such as the number of blocks in the partition, size
of the blocks, freeblock count and free-block pointers
A directory structure per file system is used to organize the files.
In UFS, this includes file names and associated inode numbers. In
NTFS it is stored in the master file table.
A per-file FCB contains many details about the file, including file
permissions,ownership, size, and location of the data blocks. In
UFS, this is called the inode.
11.41 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
A Typical File Control Block
11.42 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
In-Memory File System Structures
The following figure illustrates the necessary file system structures
provided by the operating systems.
Figure 12-3(a) refers to opening a file.
Figure 12-3(b) refers to reading a file.
11.43 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
In-Memory File System Structures
11.44 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Virtual File Systems
Virtual File Systems (VFS) provide an object-oriented way of
implementing file systems.
VFS allows the same system call interface (the API) to be used for
different types of file systems.
The API is to the VFS interface, rather than any specific type of file
system.
11.45 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Schematic View of Virtual File System
11.46 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Directory Implementation
Linear list of file names with pointer to the data blocks.
simple to program
time-consuming to execute
Hash Table – linear list with hash data structure.
decreases directory search time
collisions – situations where two file names hash to the same
location
fixed size
11.47 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Alocation Methods
11.48 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Allocation Methods
An allocation method refers to how disk blocks are allocated for
files:
Contiguous allocation
Linked allocation
Indexed allocation
11.49 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk
Simple – only starting location (block #) and length (number
of blocks) are required
Random access
Wasteful of space (dynamic storage-allocation problem)
Files cannot grow
11.50 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Contiguous Allocation of Disk Space
IBM 360 Pros: Fast Sequential
Access, Easy Random access
Cons: External Fragmentation/Hard to grow files Free holes get
smaller and smaller
Could compact space, but that would be reallyexpensive
11.51 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Extent-Based Systems
Many newer file systems (I.e. Veritas File System) use a modified
contiguous allocation scheme
Extent-based file systems allocate disk blocks in extents
An extent is a contiguous block of disks
Extents are allocated for file allocation
A file consists of one or more extents.
11.52 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Linked Allocation
Each file is a linked list of disk blocks: blocks may be scattered
anywhere on the disk.
pointerblock =
11.53 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Linked Allocation (Cont.)
Simple – need only starting address
Free-space management system – no waste of space
No random access
File-allocation table (FAT) – disk-space allocation used by
MS-DOS and OS/2.
11.54 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Linked Allocation
Pros: Can grow files
dynamically, Free list
same as file
Cons: Bad Sequential
Access (seek between
each block),
Unreliable
(lose block, lose rest
of file)
Serious Con: Bad
random access!!!!
Technique originally
from Alto (First PC,
built at Xerox)
No attempt to
allocate contiguous
blocks
11.55 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
File-Allocation Table
MSDOS links pages together to create a file Links not in pages, but
in the File Allocation Table (FAT) FAT contains an
entry for each block on the disk
FAT Entries corresponding to blocks of file linked together
Access properties: Sequential access
expensive unless FAT cached in memory
Random access expensive always, but reallyexpensive if FAT not cached in memory
11.56 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Indexed Allocation
Brings all pointers together into the index block.
Logical view.
index table
11.57 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Example of Indexed Allocation
System Allocates file
header block to hold
array of pointers big
enough to point to all
blocks
User pre-declares
max file size;
Pros: Can easily
grow up to space
allocated for index
Random
access is fast
Cons: Clumsy to grow
file bigger than table
size
Still lots of
seeks: blocks may be
spread over disk
11.58 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Indexed Allocation (Cont.)
Need index table
Random access
Dynamic access without external fragmentation, but have overhead of index block.
11.59 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Indexed Allocation – Mapping (Cont.)
outer-index
index table file
11.60 Silberschatz, Galvin and Gagne ©2008Operating System Concepts
Combined Scheme: UNIX (4K bytes per block)
UNIX 4.1 Pros and cons
Pros:
Simple (more or less)
Files can easily expand (up to a point)
Small files particularly cheap and easy
Cons:
Lots of seeks
Very large files must read many indirect blocks (four I/Os per block
End of Course 11