Professional Documents
Culture Documents
File Systems
File Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Systems
• File Naming
• File Structure
• Directories
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Naming
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Naming
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Suffix Examples
.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Structure
● Byte sequences
● Record sequences
● Tree
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Structure
Byte sequences:
Record sequences:
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Structure
Tree:
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Structure
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Regular Files
Regular files are the most common files. Another name for
regular files is ordinary files. Regular files contain data.
• ASCII
• Binary
ASCII:
● Contain information readable by the user.
● User can display and print
● Can be edited with any text editor
● Each line is terminated by a carriage return character. In
some system the line feed character is used.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Regular Files
Binary File:
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Binary File Types (Early Unix)
(b)An archive-library
procedures compiled but
not linked
● Sequential access
● Random access
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Attributes (hypothetical OS)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Operations
● Create
● Delete
● Open
● Close
● Read
● Write
● Append
● Seek
● Get Attributes
● Set Attributes
● Rename
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Directories
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Single Level Directory Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Hierarchical Directory Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Path names
• Absolute /usr/carl/cs310/miderm/answers
• Relative cs310/midterm/answers
• . Refers to current (working) directory
• .. Refers to parent of current directory
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Path Names
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Directory Operations
•Create
•Delete
•Opendir
•Closedir
•Readdir
•Rename
•Link
•Unlink
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Directory Operations
System calls for managing directories
(from Unix)
• Readdir-reads next entry in open directory
• Rename
• Link-links file to path. File can appear in multiple
directories!
• Unlink-what it sounds like. Only unlinks from
pathname specified in call
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Implementation
File System Layout
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Implementation
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
A Possible File System Layout
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Allocating Blocks to files
Implementing File
• Contiguous allocation
• Linked list allocation
• Linked list using table
• I-nodes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Contiguous Allocation
The good
• Easy to implement
• Read performance is great. Only need one seek to
locate the first block in the file. The rest is easy.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Linked List Allocation
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Linked Lists
The good
• Gets rid of fragmentation
• Only store the disk address of the first block.
The bad
• Random access is slow. Need to chase pointers to get to
a block
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Linked lists using a table in memory
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Solution-Linked List Allocation Using a
Table in Memory
Advantage:
● Random access is much easier without making any disk
reference.
Disadvantage:
● Entire table must be in memory all the time to make it
work.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I-nodes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I-nodes
• How big is N?
• Solution: Last entry in table points to disk block which
contains pointers to other disk blocks
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I-nodes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Directories
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Directories
(a) fixed-size entries with the disk addresses and attributes (DOS)
(b) each entry refers to an i-node. Directory entry contains
attributes. (Unix)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Directories
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Directories
Alternative Approaches:
● In line
● In a Heap
In line Disadvantage:
● Removing a file introduced a variable-sized gap
● Reading a file causing page fault
In a Heap Disadvantage:
● Heap must be managed and page faults can still occur
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Directories
Two ways of handling long file names in a directory. (a) In-line. (b)
In a heap.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Page Fault
P1 1 KB
P2
P1 1 KB
P3
P2
P4
CPU P3 P5
P6
P4
P7
P7
P5
P8
Not present in
main memory so
page fault
Main Memory
Secondary Memory
Implementing Directories
Searching in Directories:
● Linear Search
● Hash table
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Hash Table
o Various way of making hash function
o Table size=n
name is hashed between (0 to n-1)
name/n = remainder
Advantage:
Disadvantage:
20 0
1 1
8 2
3
12 4
25 5
4 6 6
6 7
18 8
3 9
Shared Files
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I-node problem
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I node problem and solution
(a) Situation prior to linking. (b) After the link is created. (c) After
the original owner removes the file.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Symbolic links
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Log Structured File System
CPU’s faster, disks and memories bigger (much) but
disk seek time has not decreased
• Caches bigger-can do reads from cache
• Want to optimize writes because disk needs to be updated
• Structure disk as a log-collect writes and periodically send
them to a segment in the disk. Writes tend to be very small
• Segment has summary of contents (i-nodes, directories….).
• Keep i-node map on disk and cache it in memory to locate i-
nodes
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Log Structured File System
• Cleaner thread compacts log. Scans segment for current
i-nodes, discarding ones not in use and sending current
ones to memory.
• Writer thread writes current ones out into new segment.
• Works well in Unix. Not compatible with most file systems
• Not used
• Free space management in 2 ways: (Threading,Copying)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Journaling File Systems
Want to guard against lost files when there are
crashes. Consider what happens when a file has
to be removed.
• Remove the file from its directory.
• Release the i-node to the pool of free i-nodes.
• Return all the disk blocks to the pool of free disk blocks
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Journaling File Systems
o Keep a journal (i,.e. list) of actions before you take them,
write journal to disk, then perform actions. Can recover
from a crash!
o Need to make operations idempotent. Must arrange data
structures to do so.
o Mark block n as free is an idempotent operation.
o Adding freed blocks to the end of a list is not
idempotent
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual File Systems
o Have multiple fs on same machine
o Windows specifies fs (drives)
o Unix integrates into VFS
o Vfs calls from user
o Lower calls to actual fs
o Supports Network File System-file can be on a remote
machine
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual File Systems (1)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
VFS-how it works
o File system registers with VFS (e.g. at boot time)
o At registration time, fs provides list of addresses of
function calls the vfs wants
o Vfs gets info from the new fs i-node and puts it in a v-node
o Makes entry in fd table for process
o When process issues a call (e.g. read), function pointers
point to concrete function calls
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Virtual File Systems
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Disk Space Management
o Disk space management-use fixed size blocks which don’t
have to be adjacent
o If stored as consecutive bytes and file grows it will
have to be moved
o What is optimum (good) block size? Need information on
file size distribution.
o Don’t have it when building fs.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Disk Space Management Block Size (1)
Figure 4-21. The solid curve (left-hand scale) gives the data rate
of a disk. The dashed curve (right-hand scale) gives the disk
space efficiency. All files are 4 KB.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Disk Space Management
o Bigger block size results in better space utilization, but
worse transfer utilization
o If allocation unit is too large- waste space
o If allocation unit is too small- waste time
o trade-off is space vs data rate
o There is no good answer (Nature wins this time)
o Might as well use large (64 KB) block size as disks are
getting much bigger and stop thinking about it
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Keeping Track of Free Blocks (1)
Figure 4-22. (a) Storing the free list on a linked list. (b) A bitmap.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
How to keep track of free blocks
o Links-need ~1.9 million blocks
o Bit-map~need 60,000 blocks
o If free blocks come in runs, could keep track of beginning
and block and run length. Need nature to cooperate for
this to work.
o Only need one block of pointers in main memory at a time.
Fills up=>go get another
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Keeping Track of Free Blocks (2)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Disk Quotas
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
Entire file system should backup/ part of it-
o Can get binaries from manufacturer’s CD’s
o Temporary files don’t need to be backed up
o Special files (I/O) don’t need it
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
● No need to backup files that have not changed
since the previous backup - Incremental dumps.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
● Problem-want to compress data before dumping
it, but if part of the tape is bad…..
● It is difficult to perform a backup on an active file
system. Snapshot algorithms are available.
● Introduces non technical problems for a
organization.
● Backup tapes should be kept off-site, but that also
have more security issue.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
Two strategies can be used for dumping a disk to
tape:
● Physical dump
● Logical dump
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Dumping strategies
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Logical Dumps
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Logical Dumps
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Backups
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Consistency
o Crash before blocks written out results in an
inconsistent state=>
o Need utility program to check for consistency
in blocks and files
(fsck in Unix, scandisk in Windows)(blocks/files)
o For block uses two tables
o How many times is block present in a file
o How many times block is present in free
list
o Device then reads all of the i-nodes,
increments counters
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File System Consistency
Figure 4-27. File system states. (a) Consistent. (b) Missing block.
(c) Duplicate block in free list. (d) Duplicate data block.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Solutions
o Missing block (b)-put on free list
o Block occurs twice on free list (c)-re-build free
list
o Block occurs twice on blocks in use (d)- notify
user. (If one file is removed, then block
appears on both lists)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
File Consistency
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639