Professional Documents
Culture Documents
OS - Unhsgeit IV
OS - Unhsgeit IV
OS - Unhsgeit IV
A file is a collection of related information that is recorded on secondary storage. Or file is a collection of
logically related entities. File management is one of the basic and important features of operating system.
Operating system is used to manage files of computer system. All the files with different extensions are
managed by operating system. File management is defined as the process of manipulating files in computer
system, it management includes the process of creating, modifying and deleting the files.
The following are some of the tasks performed by file management of operating system of any computer
system:
1. It helps to create new files in computer system and placing them at the specific locations.
2. It helps in easily and quickly locating these files in computer system.
3. It makes the process of sharing of the files among different users very easy and user friendly.
4. It helps to stores the files in separate folders known as directories. These directories help users to
search file quickly or to manage the files according to their types or uses.
5. It helps the user to modify the data of files or to modify the name of the file in the directories.
Properties of a File System
• Files are stored on disk or other storage and do not disappear when a user logs off.
• Files have names and are associated with access permission that permits controlled sharing.
• Files could be arranged or more complex structures to reflect the relationship between them.
File Attributes
A file has a name and data. Moreover, it also stores meta information like file creation date and time, current
size, last modified date, etc. All this information is called the attributes of a file system.
Here, are some important File attributes used in OS:
• Name: It is the only information stored in a human-readable form.
• Identifier: Every file is identified by a unique tag number within a file system known as an identifier.
• Location: Points to file location on device.
• Type: This attribute is required for systems that support various types of files.
• Size. Attribute used to display the current file size.
• Protection. This attribute assigns and controls the access rights of reading, writing, and executing the
file.
• Time, date and security: It is used for protection, security, and also used for monitoring
File Type
It refers to the ability of the operating system to differentiate various types of files like text files, binary, and
source files. However, Operating systems like MS_DOS and UNIX has the following type of files:
Character Special File
It is a hardware file that reads or writes data character by character, like mouse, printer, and more.
Ordinary files
• These types of files stores user information.
• It may be text, executable programs, and databases.
• It allows the user to perform operations like add, delete, and modify.
Directory Files
• Directory contains files and other related information about those files. Its basically a folder to hold
and organize multiple files. Special Files
• These files are also called device files. It represents physical devices like printers, disks, networks,
flash drive, etc.
Word
Processor wp, tex, rrf, doc Various word processor formats
Operations of File : Create, Open, Read, Write, Append, Truncate, Delete, Close
• Create file, find space on disk, and make an entry in the directory.
• Write to file, requires positioning within the file • Read from file involves positioning within the file
• Delete directory entry, regain disk space.
• Reposition: move read/write position.
Disadvantage
• External fragmentation will occur, making
it difficult to find contiguous blocks of space of
sufficient length. Compaction algorithm will be
necessary to free up additional space on disk.
• Also, with pre-allocation, it is necessary to
declare the size of the file at the time of creation.
3. Indexed Allocation:
It addresses many of the problems of contiguous and
chained allocation. In this case, the file allocation table
contains a separate one-level index for each file: The index
has one entry for each block allocated to the file. Allocation
may be on the basis of fixed-size blocks or variable-sized
blocks. Allocation by blocks eliminates external
fragmentation, whereas allocation by variable-size blocks
improves locality. This allocation technique supports both
sequential and direct access to the file and thus is the most
popular form of file allocation.
Disadvantages:
• The pointer overhead for indexed allocation is greater than linked allocation.
• For very small files, say 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.
File-System Layout
File Systems are stored on disks. The above figure depicts
a possible File-System Layout.
• MBR: Master Boot Record is used to boot the computer
• Partition Table: Partition table is present at the end of
MBR. This table gives the starting and ending addresses of
each partition.
• Boot Block: When the computer is booted, the BIOS
reads in and executes the MBR. The first thing the MBR
program does is locate the active partition, read in its first
block, which is called the boot block, and execute it. The
program in the boot block loads the operating system
contained in that partition. Every partition contains a boot
block at the beginning though it does not contain a
bootable operating system.
• Super Block: It contains all the key parameters about the file system
and is read into memory when the computer is booted or the file
system is first touched.
• Directory structure organizes the files
• Per-file File Control Block (FCB) contains many details about the file.
(Ref. Figure)
LAYERED FILE STRUCTURE
File systems organize storage on disk drives, and can be viewed as a layered design: o At the lowest
layer are the physical devices, consisting of the magnetic media, motors &
controls, and the electronics connected to them and controlling them. Modern
disk put more and more of the electronic controls directly on the disk drive itself,
leaving relatively little work for the disk controller card to perform. o I/O Control
consists of device drivers, special software programs (often written in assembly
) which communicate with the devices by reading and writing special codes
directly to and from memory addresses corresponding to the controller card's
registers. Each controller card ( device ) on a system has a different set of
addresses ( registers, a.k.a. ports ) that it listens to, and a unique set of command
codes and results codes that it understands. o The basic file system level works
directly with the device drivers in terms of retrieving and storing raw blocks of
data, without any consideration for what is in each block. Depending on the
system, blocks may be referred to with a single block number, ( e.g. block #
234234 ), or with head-sector-cylinder combinations. o The file organization
module knows about files and their logical blocks, and
how they map to physical blocks on the disk. In addition to translating from logical to physical
blocks, the file organization module also maintains the list of free blocks, and allocates free
blocks to files as needed.
o The logical file system deals with all of the meta data associated with a file ( UID, GID, mode,
dates, etc ), i.e. everything about the file except the data itself. This level manages the
directory structure and the mapping of file names to file control blocks, FCBs, which contain
all of the meta data as well as block number information for finding the data on the disk.
• The layered approach to file systems means that much of the code can be used uniformly for a wide
variety of different file systems, and only certain layers need to be filesystem specific.
File Directories
Collection of files is a file directory. A single directory may or may not contain multiple files. The directory
contains information about the files, including attributes, location and ownership. Much of this information,
especially that is concerned with storage, is managed by the operating system. The directory is itself a file,
accessible by various file management routines. It can also have sub-directories inside the main directory. In
Windows OS, it is called folders.
Single-Level Directory
Two-Level Directory
Tree-Structured Directory :
Disk partitioning:
It is a process of dividing a hard drive into several partitions. It is one step of disk formatting. It is the process
of dividing a disk into one or more regions, the
so called partitions. If a partition is created, the
disk will store the information about the
location and size of partitions in partition table
that is usually located in the first sector of a
disk. With the partition table, each partition
can appear to the operating system as a logical
disk and users can read and write data on disk.
And each partition can be managed separately.
Partitions are categorized as primary partition
and extended partition. A MBR disk can be at
most divided into 4 primary partitions or 3 primary partitions plus 1 extended partition. And the extended
partition can be divided into a number of logical partitions.
Purpose of Partitioning a Hard Drive
1. Use of New Hard Disk
2. Ease of Windows Reinstallation
3. Better Organization
4. Easier Backup
5. Simpler Data Recovery Disk formatting
It is the process of preparing a hard disk drive or flexible disk medium for data storage. In some cases, the
formatting operation may also create one or more new file systems. The formatting process that performs
basic medium preparation is often referred to as “low-level formatting.” The term “high-level formatting”
most often refers to the process of generating a new file system. In certain operation systems (e.g., Microsoft
Windows), the two processes are combined and the term “format” is understood to mean an operation in
which a new disk medium is fully prepared to store files. Formatting a disk for use by an operating system
and its applications involves three different steps.
• Partitioning creates data structures needed by the operating system. This level of formatting often
includes checking for defective tracks or defective sectors.
• Low-level formatting (i.e., closest to the hardware) marks the surfaces of the disks with markers indicating
the start of a recording block (typically today called sector markers) and other information like block CRC
to be used later, in normal operations, by the disk controller to read or write data. This is intended to be
the permanent foundation of the disk, and is often completed at the factory.
• High-level formatting creates the file system format within the structure of the intermediate-level
formatting. This formatting includes the data structures used by the OS to identify the logical drive or
partition’s contents). This may occur during operating system installation, or when adding a new disk. Disk
and distributed file system may specify an optional boot block, and/or various volume and directory
information for the operating system.
Disk Free Space Management
Just as the space that is allocated to files must be managed ,so the space that is not currently allocated to
any file must be managed. To perform any of the file allocation techniques,it is necessary to know what
blocks on the disk are available. Thus we need a disk allocation table in addition to a file allocation table.The
following are the approaches used for free space management.
1. Bitmap
This technique is used to implement the free space management. When the free space is implemented as
the bitmap or bit vector then each block of the disk is represented by a bit. When the block is free its bit is
set to 1 and when the block is allocated the
bit is set to 0. The main advantage of the
bitmap is it is relatively simple and efficient
in finding the first free block and also the
consecutive free block in the disk. Many
computers provide the bit manipulation
instruction which is used by the users.
The calculation of the block number is done by the formula:
(number of bits per words) X (number of 0-value word) + Offset of first 1 bit Advantages:
• This technique is relatively simple.
• This technique is very efficient to find the free space on the disk.
Disadvantages:
• This technique requires a special hardware support to find the first 1 in a word it is not 0.
• This technique is not useful for the larger disks.
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 bitmap would be:
001111001111110001100000011100000
2. Linked list
This is another technique for free space management. In this linked list of all the free block is maintained. In
this, there is a head pointer
which points the first free block
of the list which is kept in a
special location on the disk. This
block contains the pointer to the next block and the next block contain the pointer of another next and this
process is repeated. By using this disk it is not easy to search the free list. This technique is not sufficient to
traverse the list because we have to read each disk block that requires I/O time. So traversing in the free
list is not a frequent action.
In our earlier example, we see that keep block 2 is the first free block which points to another block which
contains the pointer of the 3 blocks and 3 blocks contain the pointer to the 4 blocks and this contains the
pointer to the 5 block then 5 block contains the pointer to the next block and this process is repeated at the
last .
3. Grouping
This is also the technique of free space management. In this,
there is a modification of the free-list approach which stores
the address of the n free blocks. In this the first n-1 blocks are
free but the last block contains the address of the n blocks.
When we use the standard linked list approach the addresses
of a large number of blocks can be found very quickly. In this
approach, we cannot keep a list of n free disk addresses but
we keep the address of the first free block.
4. Counting
Counting is another approach for free space management. Generally, some contiguous blocks are allocated
but some are free simultaneously. When the free space is allocated to a process according to the contiguous
allocation algorithm or clustering. So we cannot keep the list of n free block address but we can keep the
address of the first free block and then the numbers of n free contiguous block which follows the first block.
When there is an entry in the free space list it consists the address of the disk and a count variable. This
method of free space management is similar to the method of allocating blocks. We can store these entries
in the B-tree in place of the linked list. So the operations like lookup, deletion, insertion are efficient.
DISK STRUCTURE:
A hard disk is a memory storage device which looks like
this:
The disk is divided into tracks. Each track is further
divided into sectors. The point to be noted here is that
outer tracks are bigger in size than the inner tracks but
they contain the same number of sectors and have
equal storage capacity. This is because the storage
density is high in sectors of the inner tracks where as
the bits are sparsely arranged in sectors of the outer
tracks. Some space of every sector is used for
formatting. So, the actual capacity of a sector is less
than the given capacity.
Read-Write(R-W) head moves over the rotating hard disk. It is this Read-Write head that performs all the
read and write operations on the disk and hence, position of the R-W head is a major concern. To perform a
read or write operation on a memory location, we need to place the R-W head over that position. Some
important terms must be noted here:
• Seek time – The time taken by the R-W head to reach the desired track from it’s current position. Seek
time is the time taken to locate the disk arm to a specified track where the data is to be read or write. So
the disk scheduling algorithm that gives minimum average seek time is better.
• Rotational latency – Rotational Latency is the time taken by the desired sector of disk to rotate into a
position so that it can access the read/write heads. So the disk scheduling algorithm that gives minimum
rotational latency is better. Hence it is Time taken by the sector to come under the R-W head.
• Data transfer time – It is the Time taken to transfer the required amount of data. It depends upon the
rotational speed.
• Disk Access Time: Disk Access Time is:
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
• Disk Response Time: Response Time is the average of time spent by a request waiting to perform its I/O
operation. Average Response time is the response time of the all requests. Variance Response Time is
measure of how individual request are serviced with respect to average response time. So the disk
scheduling algorithm that gives minimum variance response time is better.