National Institute of Science & Technology
File-System
Interface &
Implementation
(Chap- 11 & 12)
Operating System Concept Ranjit Kumar Behera
11.0
Topics
File concept
National Institute of Science & Technology
File Attributes
File Operations
File Types
Access Methods
Directory Structure
Directory Implementation
Allocation Methods
Recovery
Operating System Concept Ranjit Kumar Behera
11.1
File Concept
File is the most visible aspect of operating system.
National Institute of Science & Technology
It provides the mechanism for on-line storage of and access to
both data and programs of the OS and all the users.
The O.S abstracts from the physical properties of its storage
devices to define a logical storage unit called file.
Files are mapped by the O.S onto the physical devices.
A file is a named collection of related information that is
recorded on secondary storage.
Data cannot be written to secondary storage unless they are
written with in a file.
File represent programs (both source and object form) and
data.
In general, a file is a sequence of bits, bytes, lines or records,
the meaning of which is defined by the file’s creator and user
Operating System Concept Ranjit Kumar Behera
11.2
File Attributes
A file has certain attributes, which vary from one O.S to another.
National Institute of Science & Technology
Name – only information kept in human-readable form. When a file is
named it becomes independent of the process, the user, and even the
system that created it.
Identifier – unique tag (number) identifies file within file system. It is
the non-human-readable name for the file.
Type – needed for systems that support different types
Location – is a pointer to a device and to the location of the file on
that device.
Size – current file size (in bytes, words, or blocks).
Protection – Access 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 Concept Ranjit Kumar Behera
11.3
File Operations
Create:- 1st , find the space. 2nd , an entry for the new file
National Institute of Science & Technology
must be made in the directory. The directory entry records
the name of the file and location in the file system.
Write: the system must keep a write pointer to the location in
the file where the next write is to take place.
Read: use a system call that specifies the name of the file
and where the next block of the file should be put. A read
pointer is used to locate from where the next read is to take
place.
Reposition within file: also known as a file seek.
Delete: search the directory for the named file.
Truncate: erase the contents but kept the attributes.
Other common operations are: append, rename, copy etc.
Operating System Concept Ranjit Kumar Behera
11.4
Open Files
To reduce the searching time O.S keeps the information about all open
National Institute of Science & Technology
files in a table called open-file table.
When a file operation requested, the file is specified via an index into
this table, so no searching is required.
When the file is no longer actively used, it is closed by the process
and the operating system removes its entry in the open-file system.
Several pieces of data are needed to manage open files:
File pointer: pointer to last read/write location as a current-file-
position pointer.
File-open count: counter of number of times a file is open and close–
to allow removal of data from open-file table.
Disk location of the file: most file operations require the system to
modify data within the file. The information needed to locate the file on
disk is kept in memory to avoid having to read it from disk for each
operation.
Access rights: per-process access mode information.
Operating System Concept Ranjit Kumar Behera
11.5
File Types – Name, Extension
National Institute of Science & Technology
The name is split
into two parts:- a
name and an
extension, usually
separated by a
period operator.
Operating System Concept Ranjit Kumar Behera
11.6
Access Methods
National Institute of Science & Technology
Sequential Access:
Information in the file is processed in order, one record
after another.
Editors and compilers usually access files in this method.
Direct Access:
There is no restrictions on the order of reading or writing
for a direct access file.
The file is viewed as a numbered sequence of blocks of
records.
Direct access are of great use for immediate access to large
amounts of information particularly in database system.
Operating System Concept Ranjit Kumar Behera
11.7
Sequential-access File
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.8
Simulation of Sequential Access on a Direct-access File
Not all the operating system support both sequential and
National Institute of Science & Technology
direct access for files.
It is easy to simulate sequential access on a direct-access
file which is shown below, but the reverse is very tough and
quite inefficient.
Operating System Concept Ranjit Kumar Behera
11.9
Directory Structure
The organization of millions of data is done in two ways:
National Institute of Science & Technology
1. Disks are split into one or more partitions (minidisks)
2. Each partition contains information
about files within it. Directory
Each disk on a system contains at least
one partition, which is a low-level structure Files F1 F1
in which files and directories reside. F1
Sometimes, partitions are used to
provide several separate areas within one
disk.
Note: Both the directory structure and the files reside on disk.
Operating System Concept Ranjit Kumar Behera
11.10
Directory Structure (cont.)
Information in a Device Directory
National Institute of Science & Technology
Name
Type
Address
Current length
Maximum length
Date last accessed (for archival)
Date last updated (for dump)
Owner ID (who pays)
Protection information
Operating System Concept Ranjit Kumar Behera
11.11
Directory Structure (cont.)
Operations Performed on Directory
National Institute of Science & Technology
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
Operating System Concept Ranjit Kumar Behera
11.12
Single-Level Directory
National Institute of Science & Technology
A single directory for all users.
Disadvantages:
1. Naming problem
2. Grouping problem
Operating System Concept Ranjit Kumar Behera
11.13
Two-Level Directory
Separate directory for each user.
National Institute of Science & Technology
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
Operating System Concept Ranjit Kumar Behera
11.14
Tree-Structured Directories
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.15
Tree-Structured Directories (Cont.)
The tree has one root directory and have many subdirectories.
National Institute of Science & Technology
All directories have the same internal format.
One bit in each directory entry defines the entry as :
0 - file and
1 - subdirectory.
Creating a new file is done in current directory.
Path names can be of two types : (1) Absolute or (2) relative
An absolute path name begins at the root and follows a path
down to the specified file, giving the directory names on the path.
A relative path name defines a path from the current directory.
Advantages:
Efficient searching
Grouping Capability
Operating System Concept Ranjit Kumar Behera
11.16
Acyclic-Graph Directories
Have shared subdirectories and files.
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.17
General Graph Directory
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.18
Directory Implementation
The selection of directory-allocation and directory-
management algorithms has a large effect on the efficiency,
National Institute of Science & Technology
performance, and reliability of the file system.
Linear list:
Linear list of file names with pointer to the data blocks.
simple to program.
Require a linear search to find a particular entry.
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
Difficulty is that the hash tables are fixed size and
dependence of hash function on that size.
Operating System Concept Ranjit Kumar Behera
11.19
Allocation Methods
National Institute of Science & Technology
Many files can be stored on the same disk.
The main problem is how to allocate free space to these
files effectively and files can be accesses quickly .
Three types of allocation methods are commonly used:
Contiguous allocation
Linked allocation
Indexed allocation
Operating System Concept Ranjit Kumar Behera
11.20
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk.
National Institute of Science & Technology
Simple – only starting location (block #) and length (number
of blocks) are required.
If the file is n blocks long and starts at location b, then it
occupies blocks b, b+1, b+2, …, b+n-1.
Accessing is very easy( both sequential &Random access).
Problems:
How to find space for a new file?
Similar to dynamic storage-allocation problem.
Files cannot grow.
Suffers from external fragmentation.
Operating System Concept Ranjit Kumar Behera
11.21
Contiguous Allocation of Disk Space
Example:
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.22
Linked Allocation
Each file is a linked list of disk blocks: blocks may be
National Institute of Science & Technology
scattered anywhere on the disk.
The directory contains a pointer to the first and last blocks of
the file.
block = pointer
Advantages:
Simple – need only starting address
Free-space management system – no waste of space
It can be used for effectively for sequential access
Disadvantages:
It is very inefficient to use for random access.
Space required for pointers.
Operating System Concept Ranjit Kumar Behera
11.23
Linked Allocation
Example:
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.24
File-Allocation Table
National Institute of Science & Technology
Used in MS-DOS
and OS/2
Operating System Concept Ranjit Kumar Behera
11.25
Indexed Allocation
Brings all pointers together into the index block.
National Institute of Science & Technology
Logical view.
index table
Need index table
Random access
Dynamic access without external fragmentation, but
have overhead of index block.
Mapping from logical to physical in a file of maximum
size of 256K words and block size of 512 words. We
need only 1 block for index table.
Operating System Concept Ranjit Kumar Behera
11.26
Example of Indexed Allocation
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.27
UNIX (4K bytes per block)
National Institute of Science & Technology
Operating System Concept Ranjit Kumar Behera
11.28
Recovery
National Institute of Science & Technology
Consistency checking – compares data in directory
structure with data blocks on disk, and tries to fix
inconsistencies.
Backup and Restore
Use system programs to back up data from disk to
another storage device (floppy disk, magnetic tape).
Recover lost file or disk by restoring data from backup.
Operating System Concept Ranjit Kumar Behera
11.29
National Institute of Science & Technology
Thank You
Operating System Concept Ranjit Kumar Behera
11.30