Operatin
g
Systems
:
Internals Chapter 12
and File Management
Design Eighth Edition
Principle By William Stallings
s
Files
Data collections created by users
The File System is one of the most important parts of the
OS to a user
Desirable properties of files:
Long-term existence
• files are stored on disk or other secondary storage and do not disappear when a
user logs off
Sharable between
processes
• files have names and can have associated access permissions that permit
controlled sharing
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
Four terms are
commonly used
when discussing
files:
Field Record File Databas
e
Structure Terms
Field File
basic element of data collection of similar
records
contains a single value
treated as a single entity
fixed or variable length
may be referenced by
Database name
access control
collection of related
data Record
restrictions usually apply
at the file level
relationships among collection of related fields
elements of data are that can be treated as a
explicit unit by some application
designed for use by a program
number of different fixed or variable length
applications
File Management
System Objectives
Meet the data management needs of the user
Guarantee that the data in the file are valid
Optimize performance
Provide I/O support for a variety of storage device types
Minimize the potential for lost or destroyed data
Provide a standardized set of I/O interface routines to
user processes
Provide I/O support for multiple users in the case of
multiple-user systems
Minimal User
Requirements
Each user:
• should be able to create, delete, read, write and modify files
1
• may have controlled access to other users’ files
2
• may control what type of accesses are allowed to the files
3
• should be able to restructure the files in a form appropriate to the
4 problem
• should be able to move data between files
5
• should be able to back up and recover files in case of damage
6
• should be able to access his or her files by name rather than by
7 numeric identifier
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 purpose
users and record I/O
capability Maintains
applications basic data
to access about file
records
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
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, sequential
or hashed, file
file
Five of the
common file
organizations are:
The
The indexed
indexed sequential
file file
The Pile
Least complicated form
of file organization
Data are collected in
the order they arrive
Each record consists of
one burst of data
Purpose is simply to
accumulate the mass
of data and save it
Record access is by
exhaustive search
The
Sequential
File
Most common form of
file structure
A fixed format is used
for records
Key field uniquely
identifies the record
Typically used in batch
applications
Only organization that is
easily stored on tape as
well as disk
Indexed
Sequential File
Adds an index to the
file to support
random access
Adds an overflow file
Greatly reduces the
time required to
access a single record
Multiple levels of
indexing can be used
to provide greater
efficiency in access
Indexed File
Records are accessed only
through their indexes
Variable-length records can be
employed
Exhaustive index contains one
entry for every record in the
main file
Partial index contains entries to
records where the field of
interest exists
Used mostly in applications
where timeliness of information
is critical
Examples would be airline
reservation systems and
inventory control systems
Direct or Hashed File
Access directly any block of a known
address
Makes use of hashing on the key
value Examples are:
Often used where: • directories
very rapid access is required • pricing tables
fixed-length records are used • schedules
records are always accessed • name lists
one at a time
Table 12.1
Information
Elements of
a File
Directory
(Table can be found on page 537 in textbook)
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:
List Update
Create Delete
Search director director
files files
y y
Two-Level Scheme
Master directory
has an entry for
There is one each user Each user
directory for directory directory is a
each user and a providing address simple list of the
master directory and access files of that user
control
information
Names must be
File system can
unique only within
easily enforce
the collection of
access restriction
files of a single
on directories
user
File Sharing
Two issues arise
when allowing
files to be
shared among a
number of users:
management
of
access rights
simultaneous
access
Access
Rights
None Appending
the user would not be allowed
to read the user directory that
the user can add data to the
includes the file file but cannot modify or
delete any of the file’s
Knowledge contents
the user can determine that
the file exists and who its
Updating
owner is and can then petition the user can modify, delete,
the owner for additional access and add to the file’s data
rights
Execution
Changing protection
the user can load and execute the user can change the
a program but cannot copy it access rights granted to
Reading
other users
the user can read the file for Deletion
any purpose, including copying
and execution
the user can delete the file
from the file system
User Access Rights
Specifi User
Owner c Group All
usually the Users s
initial all users
creator of who have
the file access to
individual a set of
this system
users who users who
has full
are are not
rights
designated individually
by user ID defined
may grant these are
rights to public files
others
Access Matrix
(user,filename,rights)
Access Control List
(user,rights)
Capability Lists
(filename,rights)
Record Blocking
1) Fixed-Length Blocking –
Blocks are the unit of fixed-length records are used,
I/O with secondary and an integral number of
records are stored in a block
storage
for I/O to be Internal fragmentation –
performed records unused space at the end of
each block
must be organized
as blocks 2) Variable-Length Spanned
Blocking – variable-length
records are used and are packed
into blocks with no unused space
3) Variable-Length Unspanned
Given the size of a Blocking – variable-length
block, three methods of records are used, but spanning
blocking can be used: is not employed
File Allocation
On secondary storage, a file consists of a collection of
blocks
The operating system or file management system is
responsible for allocating blocks to files
The approach taken for file allocation may influence the
approach taken for free space management
Space is allocated to a file as one or more portions
(contiguous set of allocated blocks)
File allocation table (FAT)
data structure used to keep track of the portions assigned
to a file
Preallocation vs
Dynamic Allocation
A preallocation policy requires that the maximum size of a
file be declared at the time of the file creation request
For many applications it is difficult to estimate reliably the
maximum potential size of the file
tends to be wasteful because users and application
programmers tend to overestimate size
Dynamic allocation allocates space to a file in portions as
needed
Alternatives
Two major alternatives:
Variable, large Blocks
contiguous • small fixed portions
portions provide greater flexibility
• provides better • they may require large
performance tables or complex
• the variable size avoids structures for their
allocation
waste • contiguity has been
• the file allocation tables
abandoned as a primary
are small goal
• blocks are allocated as
needed
Table 12.2
File Allocation Methods
CONTIGUOUS FILE
ALLOCATION
Advantages:
Both the Sequential and Direct Accesses are supported
by this.
Extremely fast since the number of seeks are minimal
because of contiguous allocation of file blocks.
Disadvantages
Internal and external fragmentation. This makes it
inefficient in terms of memory utilization.
Increasing file size is difficult because it depends on the
availability of contiguous memory at a particular
instance.
LINKED FILE
ALLOCATION
Advantages:
flexible in terms of file size. File size can be increased easily since the
system does not have to look for a contiguous chunk of memory.
Does not suffer from external fragmentation.
Disadvantages:
The file blocks are distributed randomly on the disk, a large number of seeks
are needed to access every block individually. This makes linked allocation
slower.
It does not support random or direct access. We can not directly access the
blocks of a file. A block k of a file can be accessed by traversing k blocks
sequentially (sequential access ) from the starting block of the file via block
pointers.
Pointers required in the linked allocation incur some extra overhead.
INDEXED FILE
ALLOCATION
Advantages
Supports direct access to the blocks occupied by the file and
therefore provides fast access to the file blocks.
It overcomes the problem of external fragmentation
Disadvantages
The pointer overhead for indexed allocation is greater than linked
allocation.
For very small files, e.g. files that expand only 2-3 blocks, the
indexed allocation would keep one entire block (index block) for the
pointers which is inefficient in terms of memory utilization. However,
in linked allocation we lose the space of only 1 pointer per block.
Summary
File structure Secondary storage
File management systems management
File organization and access File allocation
The pile
The sequential file
The indexed sequential file
The indexed file
The direct or hashed file
File directories
Contents
Structure
Naming
File sharing
Access rights
Simultaneous access
Exercises
What is file allocation method used?
Provide ONE (1) advantage of the method specified.
Provide ONE(1) disadvantage of the method specified.
Exercise
Access matrix is a general model of access control as
exercised by a file or database management system .
Explain the term: access rights based on the Fig. above.
Exercises
Provide ONE (1) advantage and ONE(1) disadvantage of
Contiguous file allocation
Linked file allocation
Indexed File allocation