Chapter 12 File Management
Chapter 12 File Management
Chapter 12 File Management
Systems:
Internals
and
Design Chapter 12
Principles File Management
Seventh Edition
By William Stallings
Operating Systems:
Internals and Design Principles
If there is one singular characteristic that makes squirrels unique
among small mammals it is their natural instinct to hoard food.
Squirrels have developed sophisticated capabilities in their hoarding.
Different types of food are stored in different ways to maintain quality.
Mushrooms, for instance, are usually dried before storing. This is done
by impaling them on branches or leaving them in the forks of trees for
later retrieval. Pine cones, on the other hand, are often harvested while
green and cached in damp conditions that keep seeds from ripening.
Gray squirrels usually strip outer husks from walnuts before storing.
Structure
• files can be organized into hierarchical or more complex structure to reflect the relationships among
files
File Systems
Provide a means to store data organized as files as well as a collection of
functions that can be performed on files
Maintain a set of attributes associated with the file
Typical operations include:
Create
Delete
Open
Close
Read
Write
File Structure
• should be able to access his or her files by name rather than by numeric identifier
7
Typical Software Organization
Device Drivers
Lowest level
Communicates directly with peripheral devices
Responsible for starting I/O operations on a device
Processes the completion of an I/O request
Considered to be part of the operating system
Basic File System
Also referred to as the physical I/O level
Primary interface with the environment outside the computer system
Deals with blocks of data that are exchanged with disk or tape systems
Concerned with the placement of blocks on the secondary storage
device
Concerned with buffering blocks in main memory
Considered part of the operating system
Basic I/O Supervisor
Responsible for all file I/O initiation and termination
Control structures that deal with device I/O, scheduling, and file status
are maintained
Selects the device on which I/O is to be performed
Concerned with scheduling disk and tape accesses to optimize
performance
I/O buffers are assigned and secondary memory is allocated at this level
Part of the operating system
Logical I/O
Provides
general-
Enables users purpose record
and I/O capability Maintains
applications to basic data
access records about file
Access Method
Level of the file system closest to the user
Provides a standard interface between applications and the file
systems and devices that hold the data
Different access methods reflect different file structures and different
ways of accessing and processing the data
Elements of File Management
File Organization and Access
File organization is the logical structuring of the records as determined
by the way in which they are accessed
In choosing a file organization, several criteria are important:
short access time
ease of update
economy of storage
simple maintenance
reliability
Priority of criteria depends on the application that will use the file
File Organization Types
The pile
The
The direct, or sequential
hashed, file file
File
Directory
Information
Operations Performed
on a Directory
To understand the requirements for a file structure, it is helpful to
consider the types of operations that may be performed on the directory:
Tree-Structured
Directory
Master directory
with user
directories
underneath it
Each user
directory may
have
subdirectories and
files as entries
Figure 12.7
Example of
Tree-Structured
Directory
File Sharing
management of
access rights simultaneous
access
Access Rights
None Appending
the user would not be allowed to
read the user directory that includes the user can add data to the file
the file but cannot modify or delete any
of the file’s contents
Knowledge
the user can determine that the file Updating
exists and who its owner is and can
then petition the owner for
the user can modify, delete, and
additional access rights add to the file’s data
Execution Changing protection
the user can load and execute a the user can change the access
program but cannot copy it rights granted to other users
Reading
Deletion
the user can read the file for any
purpose, including copying and the user can delete the file from
execution the file system
User Access Rights
Specific User
Owner All
Users Groups
usually the
initial creator of all users who
the file have access to
this system
individual a set of users
users who are who are not
has full rights
designated by individually
user ID defined
these are public
may grant files
rights to others
Record Blocking
1) Fixed-Length Blocking – fixed-
Blocks are the unit of I/O length records are used, and an
with secondary storage integral number of records are
for I/O to be stored in a block
performed records Internal fragmentation – unused
must be organized as space at the end of each block
blocks
2) Variable-Length Spanned Blocking
– variable-length records are used and
are packed into blocks with no unused
space
The approach taken for file allocation may influence the approach taken
for free space management
Preallocation
strategy using
variable-size
portions
12.12
Indexed Allocation with Block
Portions
12.13
Indexed Allocation with
Variable Length Portions
12.14
Free Space Management
Just as allocated space must be managed, so must the unallocated space
To perform file allocation, it is necessary to know which blocks are
available
A disk allocation table is needed in addition to a file allocation table
Bit Tables
This method uses a vector containing one bit for each block on the disk
Each entry of a 0 corresponds to a free block, and each 1 corresponds to
a block in use
Advantages:
• works well with any file
allocation method
• it is as small as possible
Chained Free Portions
The free portions may be chained together by using a pointer and length
value in each free portion
Negligible space overhead because there is no need for a disk allocation
table
Suited to all file allocation methods
Disadvantages:
• leads to fragmentation
• every time you allocate a block you need to read the
block first to recover the pointer to the new first
free block before writing data to that block
Indexing
Treats free space as a file and uses an index table as it would for file
allocation
For efficiency, the index should be on the basis of variable-size
portions rather than blocks
This approach provides efficient support for all of the file allocation
methods
Free Block List
Depending on the size of the There are two effective
Each block is assigned a disk, either 24 or 32 bits will techniques for storing a small
number sequentially be needed to store a single part of the free block list in
block number main memory:
Directory
• contains a list of file names plus pointers to associated inodes
Special
• contains no data but provides a mechanism to map physical devices to file names
Named pipes
• an interprocess communications facility
Links
• an alternative file name for an existing file
Symbolic links
• a data file that contains the name of the file it is linked to
Inodes
All types of UNIX files are administered by the OS by means of inodes
An inode (index node) is a control structure that contains the key
information needed by the operating system for a particular file
Several file names may be associated with a single inode
an active inode is associated with exactly one file
each file is controlled by exactly one inode
FreeBSD Inode and File Structure
File Allocation
File allocation is done on a block basis
Allocation is dynamic, as needed, rather than using preallocation
An indexed method is used to keep track of each file, with part of the
index stored in the inode for the file
In all UNIX implementations the inode includes a number of direct
pointers and three indirect pointers (single, double, triple)
Capacity of a FreeBSD File with 4
Kbyte Block Size
Table 12.4
UNIX Directories
and Inodes
Directories are
structured in a
hierarchical tree
A directory that is
inside another
directory is referred to
as a subdirectory Figure 12.17
Volume Structure
A UNIX file
system resides Boot block Superblock Inode table Data blocks
on a single
logical disk or
disk partition
and is laid out contains
contains
with the code
attributes and
collection storage space
required to of inodes available for
information
following boot the
about the file
for each data files and
operating file subdirectories
elements: system
system
UNIX File Access Control
Access Control Lists
in UNIX
FreeBSD allows the administrator to assign a list of UNIX user IDs and
groups to a file
Any number of users and groups can be associated with a file, each with
three protection bits (read, write, execute)
A file may be protected solely by the traditional UNIX file access
mechanism
FreeBSD files include an additional protection bit that
indicates whether the file has an
extended ACL
Summary
A file management system:
is a set of system software that provides services to users and applications in the use of files
is typically viewed as a system service that is served by the operating system
Files:
consist of a collection of records
if a file is primarily to be processed as a whole, a sequential file organization is the simplest
and most appropriate
if sequential access is needed but random access to individual file is also desired, an indexed
sequential file may give the best performance
if access to the file is principally at random, then an indexed file or hashed file may be the
most appropriate
directory service allows files to be organized in a hierarchical fashion
Some sort of blocking strategy is needed
Key function of file management scheme is the management of disk space
strategy for allocating disk blocks to a file
maintaining a disk allocation table indicating which blocks are free