Chapter 10: File-System Interface
Operating System Concepts with Java 8th Edition
10.1
Silberschatz, Galvin and Gagne 2009
Chapter 10: File-System Interface
File Concept
Access Methods
Directory Structure
File-System Mounting
Operating System Concepts with Java 8th Edition
10.2
Silberschatz, Galvin and Gagne 2009
File Concept
A file is a named collection of related
information that is recorded on
secondary storage.
Data can NOT be written to secondary
storage unless they are within a file.
Operating System Concepts with Java 8th Edition
10.3
Silberschatz, Galvin and Gagne 2009
File Structure
A file has a certain defined structure which depends
on its types:
A text file is a sequence of characters organized
into lines.
A source file is a sequence of subroutines and
function.
An object file is a sequence of bytes organized into
blocks understandable by the systems linker.
An executable file is a series of code sections that
the loader can bring into memory and execute.
Operating System Concepts with Java 8th Edition
10.4
Silberschatz, Galvin and Gagne 2009
File Systems
We need a mechanism that provides longterm information storage with following
characteristics:
1. Possible to store large amount of INFO
2. INFO survives after termination of any
process
3. Multiple processes can access INFO
concurrently
The file system is the component of O.S. that
manipulate the INFO as files and directories
The file systems is the appearance of INFO
from the users standpoint that involved two
main structures :Files and directories
Operating System Concepts with Java 8th Edition
10.5
Silberschatz, Galvin and Gagne 2009
Files
INFO stored in the files must be persistent,
that is, not be affected by process creation
and termination
A file is a logical storage unit defined by the
O.S. providing the user a mechanism to store
INFO on a physical storage devices such as
disk , tape , CD and etc.
user
Physical
Logical View
Operating System Concepts with Java 8th Edition
----------
O.S.
view
10.6
Silberschatz, Galvin and Gagne 2009
Operating System Concepts with Java 8th Edition
10.7
Silberschatz, Galvin and Gagne 2009
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
Operating System Concepts with Java 8th Edition
10.8
Silberschatz, Galvin and Gagne 2009
File Attributes
Deals with:
Location: where the file is physically located
Size: how big is the file
Type : what kind of file it is
Protection: who can access the file
Time & Date: when was the last access or
modification
User: who created the file
and other information. Some of the attributes
are shown in the next slide
Operating System Concepts with Java 8th Edition
10.9
Silberschatz, Galvin and Gagne 2009
Operating System Concepts with Java 8th Edition
10.10
Silberschatz, Galvin and Gagne 2009
File Operations
File is an abstract data type
Create
Write
Read
Reposition within file
Delete
Truncate
Open(Fi) search the directory structure on disk for
entry Fi, and move the content of entry to memory
Close (Fi) move the content of entry Fi in memory to
directory structure on disk
Operating System Concepts with Java 8th Edition
10.11
Silberschatz, Galvin and Gagne 2009
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: the counter tracks the number of
opens and closes, and reaches zero on the last
close. The system can then remove the entry.
Disk location of the file: the info needed to locate
the file on disk.
Access rights: per-process access mode
information so OS can allow or deny subsequent
I/O request
Operating System Concepts with Java 8th Edition
10.12
Silberschatz, Galvin and Gagne 2009
File Types Name, Extension
Operating System Concepts with Java 8th Edition
10.13
Silberschatz, Galvin and Gagne 2009
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
Operating System Concepts with Java 8th Edition
10.14
Silberschatz, Galvin and Gagne 2009
Sequential-access File
Information in the file is processed in order, one after the other.
Operating System Concepts with Java 8th Edition
10.15
Silberschatz, Galvin and Gagne 2009
Simulation of Sequential Access on Direct-access File
cp: current position
Operating System Concepts with Java 8th Edition
10.16
Silberschatz, Galvin and Gagne 2009
Example of Index and Relative Files
The index contains pointers to the various blocks. To find a
record in the file, we first search the index and then use the
pointer to access the file directly and to find the desired record.
Operating System Concepts with Java 8th Edition
10.17
Silberschatz, Galvin and Gagne 2009
Disk Structure
Disk can be subdivided into partitions
Disks or partitions can be redundant arrays of
independent disks (RAID) protected against failure
Disk or partition can be used raw without a file
system, or formatted with a file system
Partitions also known as minidisks, slices
Entity containing file system known as a volume
Each volume containing file system also tracks that file
systems info in device directory or volume table of
contents
Operating System Concepts with Java 8th Edition
10.18
Silberschatz, Galvin and Gagne 2009
A Typical File-system Organization
Each volume that contains a file system must also contain
information about the files in the system. This information is
kept in entries in a device directory which records name,
location, size and type.
Operating System Concepts with Java 8th Edition
10.19
Silberschatz, Galvin and Gagne 2009
Operations Performed on Directory
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
Operating System Concepts with Java 8th Edition
10.20
Silberschatz, Galvin and Gagne 2009
DIRECTORY STRUCTURE
ONE LEVEL DIRECTORY STRUCTURE
TWO LEVEL DIRECTORY STRUCTURE
TREE DIRECTORY STRUCTURE
ACYCLIC GRAPH DIRECTORY STRUCTURE
Operating System Concepts with Java 8th Edition
10.21
Silberschatz, Galvin and Gagne 2009
Directories
Directories are the mechanism provided by O.S. to keep track of files.
A directory records info a bout the files in the particular partition.
Directory typically contains one entry per file. It may contain Name,
Attributes and Location or
It may contain Name and pointer to Attribute information
Operating System Concepts with Java 8th Edition
10.22
Silberschatz, Galvin and Gagne 2009
Single-Level Directory
A single directory for all users
Naming problem
Grouping problem
Operating System Concepts with Java 8th Edition
10.23
Silberschatz, Galvin and Gagne 2009
Two-Level Directory
Separate directory for each user
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
Operating System Concepts with Java 8th Edition
10.24
Silberschatz, Galvin and Gagne 2009
Tree-Structured Directories
Operating System Concepts with Java 8th Edition
10.25
Silberschatz, Galvin and Gagne 2009
Tree-Structured Directories (Cont)
Efficient searching
Grouping Capability
Current directory (working directory)
cd /spell/mail/prog
type list
Operating System Concepts with Java 8th Edition
10.26
Silberschatz, Galvin and Gagne 2009
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
mail
prog copy prt exp count
Deleting mail deleting the entire subtree rooted by
mail
Operating System Concepts with Java 8th Edition
10.27
Silberschatz, Galvin and Gagne 2009
Acyclic-Graph Directories
Have shared subdirectories and files
Operating System Concepts with Java 8th Edition
10.28
Silberschatz, Galvin and Gagne 2009
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
Operating System Concepts with Java 8th Edition
10.29
Silberschatz, Galvin and Gagne 2009
Directory Structure
Single level directory system
No owner, problem is the files with the same names
created by two different owners
Note that in the following Figures the files are shown
by the owner names. For example the files named
A created by the same owner.
Operating System Concepts with Java 8th Edition
10.30
Silberschatz, Galvin and Gagne 2009
Directory Structure
Two-level directory system
Search in directories is based on user name.
Problem is the user with the large number of files
Operating System Concepts with Java 8th Edition
10.31
Silberschatz, Galvin and Gagne 2009
Directory Structure
Hierarchical directory system
Operating System Concepts with Java 8th Edition
10.32
Silberschatz, Galvin and Gagne 2009
Path Names
Absolute path name: /usr/ast/mailbox. Always starts with /
(i.e.,separator)
Relative Path Name: mailbox
Current directory or working directory determines the relative path
name
In Unix . is current directory and
.. refers to parent
For example: cp ../lib/abdy.doc .
Operating System Concepts with Java 8th Edition
10.33
Silberschatz, Galvin and Gagne 2009
Tree-Structured Directories
Absolute path: begins at the root and follows a path down to the
specified file. root/spell/mail/prt/first
Relative path: defines a path from the current directory. prt/first
given root/spell/mail as current path.
Operating System Concepts with Java 8th Edition
10.34
Silberschatz, Galvin and Gagne 2009
Tree-Structured Directories (Cont)
Efficient searching
Grouping Capability
Current directory (working directory)
pwd
cd
/spell/mail/prog
Operating System Concepts with Java 8th Edition
10.35
Silberschatz, Galvin and Gagne 2009
Tree-Structured Directories (Cont)
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
mail
prog
copy prt exp count
Deleting mail deleting the entire subtree rooted by mail
Option1: do not delete a directory unless it is empty, such as MS-DOS
Option2: delete all files in that directory, such as UNIX rm command
with r option
Operating System Concepts with Java 8th Edition
10.36
Silberschatz, Galvin and Gagne 2009
Acyclic-Graph Directories
Have shared subdirectories and files
Only one file exists. Any changes made by one person are
immediately visible to the other.
Operating System Concepts with Java 8th Edition
10.37
Silberschatz, Galvin and Gagne 2009
Acyclic-Graph Directories (Cont.)
New directory entry type
Link another name (pointer) to an existing file
Resolve the link follow pointer to locate the file
Operating System Concepts with Java 8th Edition
10.38
Silberschatz, Galvin and Gagne 2009
File System Mounting
A file system must be mounted before it can
be accessed
A unmounted file systemis mounted at a
mount point, the location within the file
structure where the file system is to be
attached. An empty directory.
Operating System Concepts with Java 8th Edition
10.39
Silberschatz, Galvin and Gagne 2009
(a) Existing. (b) Unmounted Partition
Operating System Concepts with Java 8th Edition
10.40
Silberschatz, Galvin and Gagne 2009
Mount Point
Operating System Concepts with Java 8th Edition
10.41
Silberschatz, Galvin and Gagne 2009
Chapter 11: File System Implementation
Operating System Concepts with Java 8th Edition
10.42
Silberschatz, Galvin and Gagne 2009
Chapter 11: File System Implementation
File-System Structure
File-System Implementation
Directory Implementation
Allocation Methods
Free-Space Management
Operating System Concepts with Java 8th Edition
10.43
Silberschatz, Galvin and Gagne 2009
File-System Structure
File structure
Logical storage unit
Collection of related information
File system organized into layers
File system resides on secondary storage (disks)
Provides efficient and convenient access to disk by
allowing data to be stored, located retrieved easily
File control block storage structure consisting of
information about a file
Device driver controls the physical device
Operating System Concepts with Java 8th Edition
10.44
Silberschatz, Galvin and Gagne 2009
Layered File System
Operating System Concepts with Java 8th Edition
10.45
Silberschatz, Galvin and Gagne 2009
File-System Implementation
Boot control block contains info needed by
system to boot OS from that volume
Volume control block contains volume details
Directory structure organizes the files
Per-file File Control Block (FCB) contains
many details about the file
Operating System Concepts with Java 8th Edition
10.46
Silberschatz, Galvin and Gagne 2009
File System Implementation
Generally, several on-disk and in-memory structures are used to implement a file
system.
Sector is the smallest user-accessible portion of the disk, usually it is 512 bytes
for magnetic disks and 2048 bytes for optical disks. The term block was used
earlier for sector. Nowadays, sector has become a common name. A file block
usually consists of several (power of 2) contiguous disk blocks. Usually file block
size is a configuration parameter that can be set.
On-disk structures
Boot control block: contains information needed by the system to boot an
operating system from that partition.
Volume control block: contains volume (partition) details such as number of
blocks in the partition, free block counts, free block pointers, and free FCB
count and FCB pointers. In Unix File systems, it is called superblock; In NT
File Systems, it is called Master File Table.
Directory structure: used to organize files.
A FCB contains the files details such as owner, permissions, location of data
blocks, etc. In UFS, it is called inode.
Operating System Concepts with Java 8th Edition
10.47
Silberschatz, Galvin and Gagne 2009
File System Implementation
In-memory information used for file system management as well as
performance improvement
Mount table: contains information about each mounted partition
Directory structure: holds directory information of recently
accessed directories.
System-wide open file table: contains a copy of the FCB of each
open file, as well as other information.
Per-process open-file table: contains a pointer to the appropriate
entry in the system-wide open-file table.
Operating System Concepts with Java 8th Edition
10.48
Silberschatz, Galvin and Gagne 2009
FILE SYSTEM
In computing, a file system (or filesystem) is a type of data
store which can be used to store, retrieve and update a set of files. The
term refers to either the abstract data structures used to define files, or
the actual software or firmware components that implement the
abstract ideas.
Some file systems are used on local data storage devices; others
provide file access via a network protocol (e.g. NFS, SMB,
or 9Pclients). Some file systems are "virtual", in that the "files" supplied
are computed on request (e.g. procfs) or are merely a mapping into a
different file system used as a backing store. The file system manages
access to both the content of files and the metadata about those files.
It is responsible for arranging storage space; reliability, efficiency, and
tuning with regard to the physical storage medium are important design
considerations.
Operating System Concepts with Java 8th Edition
10.49
Silberschatz, Galvin and Gagne 2009
TYPES OF FILE SYSTEM
Disk File System
Optical Discs
Flash File System
Tape File System
Database File System
Transactional File System
Network File System
Shared Disk File System
Special File System
Device File System
Other Special File System
Virtual File System
(Details refer http://en.wikipedia.org/wiki/File_system)
Operating System Concepts with Java 8th Edition
10.50
Silberschatz, Galvin and Gagne 2009
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, called inode in UNIX/Linux
Operating System Concepts with Java 8th Edition
10.51
Silberschatz, Galvin and Gagne 2009
A Typical File Control Block
Operating System Concepts with Java 8th Edition
10.52
Silberschatz, Galvin and Gagne 2009
Layered File System
Operating System Concepts with Java 8th Edition
10.53
Silberschatz, Galvin and Gagne 2009
File System Layers
Application programs
Logical file system
Manages metadata information which includes all of the information about the file
system structure
It manages the directory structure to provide the file-organization module with the
information its needs, given a symbolic name.
It maintains file structure via File Control Blocks (FCB).
It is also responsible for protection and security
File organization module
Knows about the files and their logical and physical blocks
Can translate logical block address to physical block address for the basic file
system to transfer
It also includes a free-space manager which keeps track of unallocated blocks
Basic file system
This needs only issue generic commands to the appropriate device drivers to read
and write physical blocks on the disk
Each physical block is identified by its disk address (e.g., drive 3, cylinder 10, track
2, sector 20)
I/O control
Contains the device drivers and interrupt handlers to transfer information between
main memory and the disk.
Operating System Concepts with Java 8th Edition
10.54
Silberschatz, Galvin and Gagne 2009
Moving-head Disk Machanism
Operating System Concepts with Java 8th Edition
10.55
Silberschatz, Galvin and Gagne 2009
File System Implementation
To illustrate the use of these structures, let us look at how create and open work
Creating a file: application program calls the logical file system to create a
file. The logical file system allocates a new FCB, reads the appropriate
directory into memory, and updates it with the new file name and FCB and
writes back to disk
Opening a file: The open call passes a file name to the file system.
The file systems searches the directory structure for the given file
name, and the FCB of the file is copied into a system-wide open-file
table in memory.
An entry is also made in the per-process open file table, with a pointer
to the entry in the system-wide open-file table and some other fields.
The other fields can include a pointer to the current location in the file
and access mode in which the file is open.
Operating System Concepts with Java 8th Edition
10.56
Silberschatz, Galvin and Gagne 2009
In-Memory File System Structures
The following figure illustrates the necessary file system structures
provided by the operating systems.
Figure (a) refers to opening a file.
Figure (b) refers to reading a file.
Operating System Concepts with Java 8th Edition
10.57
Silberschatz, Galvin and Gagne 2009
In-Memory File System Structures
Operating System Concepts with Java 8th Edition
10.58
Silberschatz, Galvin and Gagne 2009
Partitions and Mounting
A disk can be sliced into multiple partitions
A partition can span multiple disks
A partition can be
raw, containing no file system
UNIX swap space can use raw partition because it uses its own format
and does not use a file system
cooked, containing a file system
Boot information can be stored in a separate partition
This has its own format, because at boot time the system does not have
file-system device drivers loaded and therefore cannot interpret file-system
format.
For example, for PCs that can be dual-booted, a boot loader that
understands multiple operating systems can occupy the boot space.
The root partition that contains the operating system kernel and other
system files is mounted at boot time.
Operating System Concepts with Java 8th Edition
10.59
Silberschatz, Galvin and Gagne 2009
Virtual File Systems
Virtual File Systems (VFS) is a technique for integrating multiple types
of file systems into a directory structure.
It separates file-systems-generic operations from their
implementation by defining a clean VFS interface.
It provides a mechanism for uniquely representing a file
throughout a network. VFS is based on a file-representation
structure, called vnode which contains a networkwide unique
numerical designator for each file.
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.
Operating System Concepts with Java 8th Edition
10.60
Silberschatz, Galvin and Gagne 2009
Schematic View of Virtual File System
Operating System Concepts with Java 8th Edition
10.61
Silberschatz, Galvin and Gagne 2009
Directory Implementation methods
Linear list of file names with pointer to the data blocks.
simple to program
time-consuming to execute
for example, to create a file in a directory the entire list has to
be searched to check if there is a file with the same name
To delete a file, the entire directory needs to be searched as
well
Hash Table linear list with hash data structure.
decreases directory search time
collisions situations where two file names hash to the same
location
A chained-overflow hash table can be used to overcome the fixed
size, but it might require stepping through a linked list of colliding
hash table entries.
Operating System Concepts with Java 8th Edition
10.62
Silberschatz, Galvin and Gagne 2009
A Typical File Control Block
Operating System Concepts with Java 8th Edition
10.63
Silberschatz, Galvin and Gagne 2009
In-Memory File System Structures
the necessary file system structures provided by the OS
refers to opening a file
refers to reading a file
Operating System Concepts with Java 8th Edition
10.64
Silberschatz, Galvin and Gagne 2009
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
Operating System Concepts with Java 8th Edition
10.65
Silberschatz, Galvin and Gagne 2009
Allocation Methods
An allocation method refers to how disk
blocks are allocated for files:
Contiguous allocation
Linked allocation
Indexed allocation
Operating System Concepts with Java 8th Edition
10.66
Silberschatz, Galvin and Gagne 2009
Contiguous Allocation of Disk Space
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 storageallocation problem)
Files cannot grow
Operating System Concepts with Java 8th Edition
10.67
Silberschatz, Galvin and Gagne 2009
Linked Allocation
Each file is a linked list of disk blocks: blocks may be
scattered anywhere on the disk.
block
Operating System Concepts with Java 8th Edition
pointer
10.68
Silberschatz, Galvin and Gagne 2009
Linked Allocation
Simple need only
starting address
Free-space management
system no waste of space
No random access
Operating System Concepts with Java 8th Edition
10.69
Silberschatz, Galvin and Gagne 2009
File-Allocation Table
File-allocation table (FAT)
disk-space allocation used
by MS-DOS and OS/2.
Each block is indexed by block
number.
Operating System Concepts with Java 8th Edition
10.70
Silberschatz, Galvin and Gagne 2009
Indexed Allocation
Brings all pointers together into the index block
Logical view
index table
Operating System Concepts with Java 8th Edition
10.71
Silberschatz, Galvin and Gagne 2009
Example of Indexed Allocation
Need index table
Random access
Dynamic access
without external
fragmentation, but
have overhead of
index block
Operating System Concepts with Java 8th Edition
10.72
Silberschatz, Galvin and Gagne 2009
Indexed Allocation Mapping (Cont.)
outer-index
index table
Operating System Concepts with Java 8th Edition
10.73
file
Silberschatz, Galvin and Gagne 2009
Combined Scheme: UNIX UFS (4K bytes per block)
Operating System Concepts with Java 8th Edition
10.74
Silberschatz, Galvin and Gagne 2009
Free-Space Management
Bit vector (n blocks)
0 1
n-1
bit[i] =
0 block[i] free
1 block[i] occupied
Block number calculation
(number of bits per word) *
(number of 0-value words) +
offset of first 1 bit
Operating System Concepts with Java 8th Edition
10.75
Silberschatz, Galvin and Gagne 2009
Free-Space Management (Cont.)
Bit map requires extra space
Example:
block size = 212 bytes
disk size = 230 bytes (1 gigabyte)
n = 230/212 = 218 bits (or 32K bytes)
Easy to get contiguous files
Linked list (free list)
Cannot get contiguous space easily
No waste of space
Operating System Concepts with Java 8th Edition
10.76
Silberschatz, Galvin and Gagne 2009
Free-Space Management (Cont.)
Need to protect:
Pointer to free list
Bit map
Must be kept on disk
Copy in memory and disk may differ
Cannot allow for block[i] to have a situation where bit[i] =
1 in memory and bit[i] = 0 on disk
Solution:
Set bit[i] = 1 in disk
Allocate block[i]
Set bit[i] = 1 in memory
Operating System Concepts with Java 8th Edition
10.77
Silberschatz, Galvin and Gagne 2009
Linked Free Space List on Disk
Operating System Concepts with Java 8th Edition
10.78
Silberschatz, Galvin and Gagne 2009
End of Chapter 11
Operating System Concepts with Java 8th Edition
10.79
Silberschatz, Galvin and Gagne 2009