File System-1
File System-1
Contents
What is a File?
File Structure
File Type
Operations of Files
File attributes
File Management System (FMS)
File accessing methods
o Sequential access
o Direct/Random access
o Indexed sequential access
File directories
Operations on file Directory
File Directory System
o Single-Level Directory System
o Two-Level Directory System
o Tree-Structured /Hierarchical Directories
o General graph directory structure
FILE Allocation Method (Space Allocation)
o Contiguous Allocation
o Linked Allocation
o Indexed Allocation(Group Allocation)
Free-Space Management (Disk space Management)
o Bit Vector
o Chain Free points (Linked Free space list)
o Index block list
Record Blocking
o Fixed blocking
o Variable Length spanned blocking
o Variable length un spanned blocking
File Management System
File concept
A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks.
From user’s perspective file is the smallest allotment of logical secondary storage. Data cannot be
written to secondary storage unless they are within a file.
The physical storage is converted into a logical storage unit by the operating system. The logical
unit is said to be the ‘FILE’.
In general, a file is a sequence of bits, bytes, lines or records whose meaning is defined by the files
creator and user.
Many different types of information may be stored in a file such as source program, object
program, executable program, numeric data, text, payroll records, graphic images, sound recording
and so on.
File Structure
File structure is a structure, which is according to a required format that operating system can
understand. A file has a certain defined structure according to its type.
A text file structure is a sequence of characters organized into lines.
A source file structure is a sequence of procedures and functions.
An object file structure is a sequence of bytes organized into blocks that are understandable by the
machine.
File Types
File type refers to the ability of the operating system to distinguish different types of file.
Operating system implements file type as a part of file name. The name of the file is split into two
parts a name and an extension.
The system uses the extension to indicate the type of a file.
Many operating systems support many types of files. Some types of files are:
Ordinary files
These are the files that contain user information.
These may have text, databases or executable program.
The user can apply various operations on such files like add, modify, delete or even remove the
entire file.
Directory files
These files contain list of file names and other information related to these files.
Special files:
These files are also known as device files.
These files represent physical device like disks, terminals, printers, networks, tape drive etc.
File type Extension Purpose/function
Executable .exe, .com, .bin Ready to run
Source code .c, .cpp, .pas, .java Source code in various
language
Batch .bat, .sh Command to the command
interpreter
Library .lib, .a, Libraries of routines
Text .txt, .doc, Textual data documents
Multimedia .mpeg, .mov, .rm Audio/video information
Operations of Files
The OS provides system calls to do operations on programmable file.The six basic file operations are:
1. Creating a file: There are two steps to create a file. First check weather space is available for the
file and secondly the entry for new file must be made in a directory. Directory entry include name
of the file, location of the file etc..
2. Writing a file: Two steps to write a file. Make a system call specifying the name of the file. Given
the name of the file, system searches the directory to find the location and then if the file is found
then secondly system must keep a pointer to the location in the file where the next write is to take
place.
3. Reading a file: To read file first to search the directories if found the system need to keep a read
pointer to the location in the file
4. Repositioning within a file: This file operation is also known as File Seek. That is resetting the
current file position to a given value.
6. Truncating a file: Remove the file contents only, but the attributes remains.
Other common operations include Appending new information and Renaming an existing file.
File attributes:
Attributes of a File are :
1. Name – A file is named for user convenience and is referred by its name. File name is the only
information kept in human-readable form.
2. Type – Files are many types, the type is depending on the extension of the file. Type is needed
for systems that support different types
3. Location – pointer to file location on device
4. Size – current file size (in bytes or blocks)
5. Protection – It specifies access control, controls who can do reading, writing, executing and so
on
6. Time, date– it specifies the time and date a file is created or last accessed.
7. User identification- This is the information for protection, security, and usage monitoring.
Information about files is kept in the directory structure, which is maintained on the disk.
The File Manager (or File Management System) is the manager in the Operating System that
creates the logical form of files that are stored in computer memory.
FMS is a collection of system software programs that provides File services to the users.
The file manager ALLOCATES a file by reading it from the hard disk and loading it into memory
while updating its record of who is using what file.
The file manager DEALLOCATES a file by updating the file tables and rewriting the file (if
changed) to the hard disk.
(1)Sequential access
A sequential access is that in which the records are accessed and processed in order, one record
after the other.
o Example: If a file consists of 100 records the current position of read/write head is 45th
record and want to read the 75th record then it access sequentially by traversing from 45
to 75
This access method is the simplest and the most primitive one.
Sequential access is based on a tape model of a file.
Used by editors and compliers.
Work well on sequential access devices such as batch systems.
(2)Direct/Random access
Random access file organization provides, accessing the records directly.
Direct access is also called relative access.
A direct-access file allows arbitrary blocks to be read or written, Jump to any record and read
that record.
Each record has its own address on the file with by the help of which it can be directly
accessed for reading or writing.
The records need not be in any sequence within the file and they need not be in adjacent
locations on the storage medium.
The direct access method is based on a disk model of a file which allows random access to any
file block.
(3)Indexed sequential access
This mechanism is built on top of direct access method.
This method requires the construction of an index for the file. Index is a small table stored in
memory
Index created for each file contains pointers to various blocks.
To find an entry in the file, the index is searched first and the pointer is then used to access the
file directly
The master index divide the total records into blocks each block consist of a pointer to
secondary index which consists of a pointer to its original location.
Index is searched sequentially and its pointer is used to access the file directly.
FILE DIRECTORIES
Directory contains information about the files, including attributes, locations and ownership.
Directories also consist of sub directories.
A directory structure provides a mechanism for organizing many files in the system.
(1)Contiguous Allocation
Each file occupy a contiguous address space on disk, a set of contiguous blocks on the disk..
Assigned disk address is in linear order.
This method make use of FAT (File allocation table ) which contains an entry for each file. It
shows the file name, starting block of the file and size of the file.
This method is best suited for sequential files
Easy to implement.
Drawback: It is difficult to find the contiguous free blocks in the disk and also external
fragmentation means some free blocks could happen between two files.
(2)Linked Allocation
In this method the FAT contains a single entry for each file which contains the address of
index blocks of files.
The entry consists of one index block having all the pointers to the other blocks which were
occupied by the particular file
Each file has its own index block which stores the addresses of disk space occupied by the file.
Provides solutions to problems of contiguous and linked allocation.
FREE-SPACE MANAGEMENT
If we want to allocate the space for the files we have to know what blocks on the disk are available.
For that a disk allocation table is used.
To keep track of free disk space the system maintains a free space list. The free space list records all
the disk blocks which are free
To create a file first search the free space list for the required amount of space and allocate it to
the new file.
When a file is deleted its disk space is added to the free space list.
The following are the various techniques to maintain free list:
For example consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27 are
free, and the rest of the blocks are allocated. The free-space bit map would be
01111001111110001100000011100000 …..
The main advantage of this approach is that it is relatively simple and efficient to find the first free
block or n consecutive free blocks on the disk.
Another approach is to link together all the free disk blocks, keeping a pointer to the first free
block .That is free blocks are chained together, each holding a pointer to the next one free
This first block contains a pointer to the next free disk block, and so on.
o For example we could keep a pointer to Block 2 as the first free block and 2 would contain a
pointer to block 3, which would point to block 4, which would point to block 5, which
would point to block 8, and so on.
Usually, the operating system simply needs a free block so that it can allocate that block to a file,
so the first block in the free list is used.
(3) Grouping (indexed block list)
A modification compared to the previous is to store the addresses of n free blocks in the first free
block. The first n-1 of these blocks is actually free.
The last block contains address of another n free block and so.
The importance of this implementation is that the addresses of a large number of free blocks can be
found quickly, unlike in the standard linked-list approach.
Index block
Block 2 3,4,5
Block 5 8,9,10,11,12,13
Block 13 17,18
Block18 25,26,27
RECORD BLOCKING
Records are the logical unit of access of a structured file. But blocks are the unit for I/O with
secondary storage.
For I/O to be performed on file, records must be organized as blocks.
Disk and tape devices recognize blocks of data, which consist of one or more records.
A blank space, known as an interblock gap (IBG), separates one block from another.
o For example the disk may specify a blocking factor, such as three records per block, In
this format, the system writes or reads an entire block length of three records.
Blocking records makes better use of disk and tape storage.
Given the size of a block(no: of records per block), there are three methods of blocking can be
used:
(1) Fixed-Length Blocking
In this method records length are fixed and a prescribed number of records (or bytes) are stored in
a block.
May waste space at the end of the block
For example: The block capacity is 5 records but the number of records in the block is 3
then the wasted space is an internal fragmentation
Pointer
Block1 Block2
IMG R1 R2 R3 R4 IMG R4 R5 R6 IMG
Block1 Block2