Module 5
Module 5
com/c/EDULINEFORCSE
STUDENTS
MODULE 5
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. In general, a file is a sequence of bits, bytes, lines or
records whose meaning is defined by the files creator and user.
• A file can be defined as a data structure which stores the sequence
of records. Files are stored in a file system, which may exist on a
disk or in the main memory. Files can be simple (plain text) or
complex (specially-formatted).
• The collection of files is known as Directory. The collection of
directories at the different levels, is known as File System.
FILE ATTRIBUTES
• Name : Every file carries a name by which the file is recognized in
the file system. One directory cannot have two files with the same
name.
• Identifier : Along with the name, Each File has its own extension
which identifies the type of the file. For example, a text file has the
extension .txt, A video file can have the extension .mp4
• Type : In a File System, the Files are classified in different types
such as video files, audio files, text files, executable files, etc.
• Location : In the File System, there are several locations on which,
the files can be stored. Each file carries its location as its attribute.
• Size: The Size of the File is one of its most important attribute. By
size of the file, we mean the number of bytes acquired by the file
in the memory.
• Protection : The Admin of the computer may want the different
protections for the different files. Therefore each file carries its
own set of permissions to the different group of Users.
• Time and Date : Every file carries a time stamp which contains the
time and date on which the file is last modified.
FILE OPERATIONS
• A file is a collection of logically related data that is recorded on the
secondary storage in the form of sequence of operations.
• The content of the files are defined by its creator who is creating
the file.
• The various operations which can be implemented on a file such as
read, write, open and close etc. are called file operations.
• These operations are performed by the user by using the
commands provided by the operating system.
• Some common operations are as follows:
Delete operation: Deleting the file will not only delete all the data
stored inside the file it is also used so that disk space occupied by it
is freed. In order to delete the specified file the directory is
searched. When the directory entry is located, all the associated
file space and the directory entry is released.
Truncate operation: Truncating is simply deleting the file except
deleting attributes. The file is not completely deleted although the
information stored inside the file gets replaced.
Close operation: When the processing of the file is complete, it
should be closed so that all the changes made permanent and all
the resources occupied should be released.
Append operation: This operation adds data to the end of the file.
Rename operation: This operation is used to rename the existing
file.
FILE TYPES
• There are numerous file types that an operating system uses
internally and are not generally used or required by the system
user.
• These files could be application software files, kernel files,
configuration files, metadata files, etc. Windows supports the
following file types:
Regular Files : Regular files consist of information related to the
user. The files are usually either ASCII or binary. ASCII files contain
lines of text. The major benefit of an ASCII file is that it can be
displayed or printed as it is, and it can be edited using a text editor.
Regular files are supported by both Windows as well as UNIX-based
operating systems.
Functions of a File
• They are used for storing data in a computer.
• They enable the separation of data according to some criteria.
• They enable efficient, simple, organized access to data.
• They help in isolating sensitive or important data from the rest of
the data.
• They enable locating particular data items in the storage medium.
Advantages
• There is no external fragmentation with linked allocation.
• Any free block can be utilized in order to satisfy the file block
requests.
• File can continue to grow as long as the free blocks are available.
• Directory entry will only contain the starting block address.
Disadvantages
• Random Access is not provided.
• Pointers require some space in the disk blocks.
• Any of the pointers in the linked list must not be broken otherwise
the file will get corrupted.
• Need to traverse each block.
Prepared By Mr. EBIN PM, AP EDULINE 16
• It simply accesses the file allocation table, read the desired block
entry from there and access that block. This is the way by which the
random access is accomplished by using FAT. It is used by MS-DOS
and pre-NT Windows versions.
Advantages
• Uses the whole disk block for data.
• A bad disk block doesn't cause all successive blocks lost.
• Random access is provided although its not too fast.
• Only FAT needs to be traversed in each file operation.
Disadvantages
• Each Disk block needs a FAT entry.
• FAT size may be very big depending upon the number of FAT entries.
• Number of FAT entries can be reduced by increasing the block size
but it will also increase Internal Fragmentation.
4. Indexed Allocation
• File allocation table tries to solve as many problems as possible but
leads to a drawback.
• The more the number of blocks, the more will be the size of FAT.
Here we need a new technology which can solve such problems.
• Therefore, we need to allocate more space to a file allocation table.
Since, file allocation table needs to be cached therefore it is
impossible to have as many space in cache.
• Instead of maintaining a file allocation table of all the disk pointers,
Indexed allocation scheme stores all the disk pointers in one of the
blocks called as indexed block.
• Indexed block doesn't hold the file data, but it holds the pointers to
all the disk blocks allocated to that particular file.
• Directory entry will only contain the index block address.
SDSFV
FGDJ
FGDJ
Indexed Access
• If a file can be sorted on any place, then an index can be assigned
to a group of certain records. However, A particular record can be
accessed by its index. The index is nothing but the address of a
record in the file.
• In index accessing, searching in a large database became very quick
and easy but we need to have some extra space in the memory to
store the index value.
• Single Level index
• Multi Level index
DIRECTORY STRUCTURE
• Directory can be defined as the listing of the related files on the
disk. The directory may store some or the entire file attributes.
• To get the benefit of different file systems on the different
operating systems, A hard disk can be divided into the number of
partitions of different sizes. The partitions are also called volumes
or mini disks.
• Each partition must have at least one directory in which, all the
files of the partition can be listed.
• A directory entry is maintained for each file in the directory which
stores all the information related to that file.
File Creation
Search for the file
File deletion
Renaming the file
Traversing Files
Listing of files
Advantages
• Implementation is very simple.
• If the sizes of the files are very small then the searching becomes
faster.
• File creation, searching, deletion is very simple since we have only
one directory.
Disadvantages
• We cannot have two files with the same name.
• The directory may be very big therefore searching for a file may
take so much time.
• Protection cannot be implemented for multiple users.
• There are no ways to group same kind of files.
Prepared By Mr. EBIN PM, AP EDULINE 36
gg
• Absolute path is the path of the file with respect to the root
directory of the system while relative path is the path with
respect to the current working directory of the system. In tree
structured directory systems, the user is given the privilege to
create the files as well as directories.
DISK SCHEDULING
• A process needs two type of time, CPU time and IO time.
• For I/O, it requests the Operating system to access the disk.
• However, the operating system must be fare enough to satisfy each
request and at the same time, operating system must maintain the
efficiency and speed of process execution.
• The technique that operating system uses to determine the request
which is to be satisfied next is called disk scheduling.
SSTF SCHEDULING
• Shortest seek time first (SSTF) algorithm selects the disk I/O
request which requires the least disk arm movement from its
current position regardless of the direction. It reduces the total
seek time as compared to FCFS.
Disadvantages
• It may cause starvation for some requests.
• Switching direction on the frequent basis slows the working of
algorithm.
• It is not the most optimal algorithm
SCAN SCHEDULING
• It is also called as Elevator Algorithm.
• In this algorithm, the disk arm moves into a particular direction till
the end, satisfying all the requests coming in its path, and then it
turns back and moves in the reverse direction satisfying requests
coming in its path.
• It works in the way an elevator works, elevator moves in a direction
completely till the last floor of that direction and then turns back.
• Eg: queue = 98,183,37,122,14,124,65,67. Head starts at 53.
Assume that the disk arm is moving towards left(to zero)
C – SCAN SCHEDULING
• In C-SCAN algorithm, the arm of the disk moves in a particular
direction servicing requests until it reaches the last cylinder, then it
jumps to the last cylinder of the opposite direction without
servicing any request then it turns back and start moving in that
direction servicing the remaining requests.
LOOK SCHEDULING
• It is like SCAN scheduling Algorithm to some extant except the
difference that, in this scheduling algorithm, the arm of the disk
stops moving inwards (or outwards) when no more request in that
direction exists.
• This algorithm tries to overcome the overhead of SCAN algorithm
which forces disk arm to move in one direction till the end
regardless of knowing if any request exists in the direction or not.
Eg: Consider the following disk request sequence for a disk with 100
tracks 98, 137, 122, 183, 14, 133, 65, 78 Head pointer starting at 54
and moving in left direction. Find the number of head movements in
cylinders using LOOK scheduling.
C Look Scheduling
• C Look Algorithm is similar to C-SCAN algorithm to some extent.
• In this algorithm, the arm of the disk moves outwards servicing
requests until it reaches the highest request cylinder, then it jumps
to the lowest request cylinder without servicing any request then it
again start moving outwards servicing the remaining requests.
• It is different from C SCAN algorithm in the sense that, C SCAN
force the disk arm to move till the last cylinder regardless of
knowing whether any request is to be serviced on that cylinder or
not.
Eg: Consider the following disk request sequence for a disk with 100
tracks 98, 137, 122, 183, 14, 133, 65, 78 . Head pointer starting at
54 and moving in left direction. Find the number of head
movements in cylinders using C LOOK scheduling.