OS ch 5
OS ch 5
1
Introduction
For example, files containing student information, files containing employee information,
Information in files could be program code ,or data in numeric, alphanumeric, alphabetic, or
if it is code. 2
Cont’d
We used several files to store information on your computer, as the information in them can later be
retrieved and used.
It is important that the files are managed properly, so that they can be located and accessed easily
To organize and manage the files and directories on your computer, OS uses an application called a
file manager.
A file manager enables you to create, delete, copy, move, rename and view files ,and create and
The way in which OS organizes, names, protects, accesses, and uses files is called a file management system.
Files are required for the following reasons.
To store data permanently (even after the termination of the process that creates
them).
To store large data that is beyond the size of a process's address space.
databases.
Part of the operating system that deals with files are known as the file system.
4
From the users' point of view, the most important issue is the interface (naming,
versus bit maps and the number of tracks per block has more importance.
5
Files and Directories – Interface
Name is used to identify a file with an abstract way. A file name consists of strings.
The maximum allowed length of a file and case sensitivity of names vary from one operating system to
the other.
Most operating systems have some characters, called file extensions, as part of the file name following a
period (.).
In some operating systems (such as Microsoft Windows), the file extension is used to associate the file
with a program.
6
Some characters, e.g. /, \ >, have special meaning in the file system so that they cannot be used as part of
File Access methods in operating system
File access methods define how data is read and written from files stored on a disk.
A file has a number of attributes. The available attributes of files differ from one
File size.
9
File Operations
In order to provide the basic store and retrieval operations of a file and other properties
of files outlined above, operating systems have some common file operations.
Some of them are: Create, delete, open, close, read, write, append, seek, get attributes,
10
Seek:
For random access file, a method is
Cont’d needed to specify from where to take the
data.
It repositions the pointer from the current
position to a specific place in the file.
Append:
This call is restricted form of Write. It 11
12
Single Level Directory Systems
There is only one directory (the root directory) in the system.
The advantage of this scheme is its implementation simplicity and ease of locating files.
The main disadvantage is the need to provide distinct name for each file.
This kind of directory organization was used in early operating systems.
Here f1, f2, f3, f4, f5 represent the five different files.
Practically it can be thought of as a structure where all the files are stored in the same
folder.
13
Two Level Directory Systems
If two different users wanted to create a file with the same name (say report.doc), it was
In a two-level directory structure, there is a master node that has a separate directory for
each user.
It can be practically thought of as a folder that contains many folders, each user can store
For every user, there is a separate directory. At the next level, every directory stores the
15
Hierarchical Directory Systems
The biggest disadvantage of a two-level directory was that one could not create sub-
directories in a directory.
The users can, however, create subdirectories inside their directory and also store the files.
16
Hierarchical Directory Systems
17
Directory Operations
The type of operations on directories varies from one operating system to the other.
The most common operations are: create, delete, opendir, closedir, and rename.
18
Files and Directories – Implementation
The most important issue in file implementation is to keep track of which disk blocks go
to which file.
There are several alternative ways of allocating disk space for files.
19
Contiguous Allocation
The block is allocated in such a manner that all the allocated blocks in the hard disk are
adjacent.
Assuming a file needs 'n' number of blocks in the disk and the file begins with a block at
Example: We have three different types of files that are stored in a contiguous manner
The file file1.txt requires 4 disk blocks, and its starting disk block address is 0, hence block 0,1,2,3 are
21
allocated.
Contiguous Allocation
Advantage:
Simple to implement: we need to keep track of first block of a file and file size to access
Fast Access: when accessing a file, the only delay is while searching the first block of the file.
Disadvantage: The file size must be specified at the time of file creation.
The disk would eventually have many holes (unused blocks) as files are deleted.so it may create
External Fragmentation: Over time, free spaces become scattered, making it hard to find a large
Fixed File Size Issue: If a file grows larger than expected, it may not fit in its allocated space.
Cont…
(A)Contiguous allocation of disk space for seven files (b) state of disk space after files 23D and
F have been removed.
Linked List Allocation
The block are allocated in such a way that every block contains a pointer to the next block
Advantage:
Dynamic File Growth: Files can expand easily by adding more blocks.
Cont..
Disadvantage:
low Access: Since blocks are scattered, accessing file data takes
longer
pointer.
become inaccessible. 25
Cont..
Example:- Here we have one file which is stored using Linked File Allocation .
26
Cont…
27
Figure 5.2 Implementation of two files (File A and File B) with linked list of disk blocks
Indexed File Allocation
The indexed file allocation is somewhat similar to linked file allocation as indexed file allocation
But the difference is here all the pointers are put together into one location which is called index
block.
That means we will get all the locations of blocks in one index file.
The blocks and pointers were spread over the memory in the Linked Allocation method, where
But, here in indexed allocation, it becomes easier with the index block to retrieve.
Cont.…
29
Comparison Table
Contiguous
Feature Linked Allocation Indexed Allocation
Allocation
31
QUIZ (5%)
1. List at least two main advantages of using file system in our computer system
2. List file Access methods and discuss what will be the advantages and disadvantages
of each access methods?(2 pts.)
3. List atleast 2 file allocation techniques of operating system?
32