Os Unit - V 2023
Os Unit - V 2023
• Commonly, files represent programs (both source and object forms) and data.
• A text file is a sequence of characters organized into lines (and possibly pages).
• An executable file is a series of code sections that the loader can bring into
memory and execute
– Writing a file. To write a file, we make a system call specifying both the name of the file and
the information to be written to the file.
• Given the name of the file, the system searches the directory to find the file’s location.
• The system must keep a write pointer to the location in the file where the next write is to take
place.
• The write pointer must be updated whenever a write occurs.
Unit 5: File System 6
•Reading a file. To read from a file, we use a system call that specifies the name of the
file and where (in memory) the next block of the file should be put.
–Again, the directory is searched for the associated entry, and the system needs to keep a
read pointer to the location in the file where the next read is to take place.
– Once the read has taken place, the read pointer is updated.
–Both the read and write operations use this same pointer, saving space and reducing
system complexity.
• Repositioning within a file. The directory is searched for the appropriate entry,
and the current-file-position pointer is repositioned to a given value.
–Repositioning within a file need not involve any actual I/O.
• Truncating a file. The user may want to erase the contents of a file but keep
its attributes.
– Rather than forcing the user to delete the file and then recreate it, this function allows all
attributes to remain unchanged—except for file length—but lets the file be reset to length zero
and its file space released.
• When it is used, this information must be accessed and read into computer
memory.
• Some systems provide only one access method for files. while others support
many access methods, and choosing the right one for a particular application
is a major design problem.
– Information in the file is processed in order, one record after the other.
– for example, editors and compilers usually access files in this fashion.
– A read operation—read next()—reads the next portion of the file and automatically
advances a file pointer, which tracks the I/O location.
– Similarly, the write operation—write next()—appends to the end of the file and
advances to the end of the newly written material (the new end of file).
– Such a file can be reset to the beginning, and on some systems, a program may be able
to skip forward or backward n records for some integer n—perhaps only for n = 1
– Sequential access is based on tape model of a file and which is depicted in Figure 11.4
• For direct access, the file is viewed as a numbered sequence of blocks or records.
• we may read block 14, then read block 53, and then write block 7.
• There are no restrictions on the order of reading or writing for a direct-access file
Unit 5: File System 12
Simulation of Sequential Access on a Direct–Access File
• Afile system can be created on each of these parts of the disk. Any entity containing a
file system is generally known as a volume.
• Each volume can be thought of as a virtual disk. Volumes can also store multiple
operating systems, allowing a system to boot and run more than one operating system.
• Each volume that contains a file system must also contain information about the files in
the system. This information is kept in entries in a device directory or volume table of
contents.
• The device directory (more commonly known simply as the directory) records
information—such as name, location, size, and type—for all files on that volume. Figure
11.7 shows a typical file-system organization.
Unit 5: File System 15
A Typical File–System Organization
• Computer systems may have zero or more file systems, and the file systems
maybe of varying types.
• For example, a typical Solaris system may have dozens of file systems of a
dozen different types, as shown in the file system list in Figure 11.8.
• Search for a file. We need to be able to search a directory structure to find the entry for
a particular file.
• Create a file. New files need to be created and added to the directory.
• Delete a file. When a file is no longer needed, we want to be able to remove it from the
directory.
• List a directory. We need to be able to list the files in a directory and the contents of
the directory entry for each file in the list.
• Rename a file. Because the name of a file represents its contents to its users, we must
be able to change the name when the contents or use of the file changes.
Unit 5: File System 19
• Traverse the file system. We may wish to access every directory and every file within
Single-Level Directory
• A single directory for all users
• The simplest directory structure is the single-level directory.
• All files are contained in the same directory, which is easy to support and
understand
• Tree structured directory system overcomes the drawbacks of two level directory
system.
• Each user has its own directory and it cannot enter in the other user's directory.
• However, the user has the permission to read the root's data but he cannot write
or modify this.
• Only administrator of the system has the complete access of root directory.
• The tree structured directory system doesn't allow the same file to exist in
multiple directories therefore sharing is major concern in tree structured
directory system.
• In this system, two or more directory entry can point to the same file or sub
directory.
• That file or sub directory is shared between the two directory entries.
• The allocation methods define how the files are stored in the disk blocks.
There are three main disk space or file allocation methods.
Contiguous allocation
Linked allocation
Indexed allocation
• For example, if a file requires n blocks and is given a block b as the starting location,
then the blocks assigned to the file will be: b, b+1, b+2,……b+n-1.
• This means that given the starting block address and the length of the file (in terms of
blocks required), we can determine the blocks occupied by the file.
• The directory entry for a file with contiguous allocation contains
Address of starting block
• The directory entry contains a pointer to the starting and the ending file block. Each
block contains a pointer to the next block occupied by the file.
block = pointer
Disadvantages:
•Because the file blocks are distributed randomly on the disk, a large number of seeks
are needed to access every block individually. This makes linked allocation slower.
•It does not support random or direct access. We can not directly access the blocks of a
file. A block k of a file can be accessed by traversing k blocks sequentially (sequential
access ) from the starting block of the file via block pointers.
•Pointers required in the linked allocation incur some extra overhead.
• In this scheme, a special block known as the Index block contains the pointers to all
the blocks occupied by a file.
• Each file has its own index block. The ith entry in the index block contains the disk
address of the ith file block. The directory entry contains the address of the index
block as shown in the image:
index table
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
•The first few of these pointers in Inode point to the direct blocks i.e the pointers contain the
• The next few pointers point to indirect blocks. Indirect blocks may be single indirect, double
•Single Indirect block is the disk block that does not contain the file data but the disk address
•Similarly, double indirect blocks do not contain the file data but the disk address of the
– Seek time is the time for the disk are to move the heads to the cylinder
containing the desired sector.
– Rotational latency is the additional time waiting for the disk to rotate the
desired sector to the disk head.
• Minimize seek time
• Disk bandwidth is the total number of bytes transferred, divided by the total
time between the first request for service and the completion of the last transfer.
42
Moving Head Disk Mechanism
Unit 5: File System 43
Disk Scheduling – Example 1
1. Suppose that a disk drive has 200 cylinders, numbered 0 to 199. The drive
current position of Read/Write head is: 50. The queue of pending requests in
FIFO order is 82,170,43,140,24,16,190 . Starting from the current head
position, what is the total distance (in cylinders) that the disk arm moves to
satisfy all the pending requests, for each of the following disk scheduling
algorithms?
a. FCFS
b. SSTF
c. SCAN
d. C–SCAN
e. LOOK
f. C–LOOK
Advantages:
Every request gets a fair chance
No indefinite postponement
Disadvantages:
Does not try to optimize seek time
May not provide the best possible service
So, total overhead movement (total distance covered by the disk arm) :
=(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16)
=642
example.
Advantages:
Average Response Time decreases
Throughput increases
Disadvantages:
Overhead to calculate seek time in advance
Can cause Starvation for a request if it has a higher
seek time as compared to incoming requests
So, total overhead movement (total distance covered by
High variance of response time as SSTF favors only
the disk arm)
some request
=(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-
140)+(190-170)
=208
Unit 5: File System 46
• 3. SCAN: In SCAN algorithm the disk arm moves in a particular direction and services
the requests coming in its path and after reaching the end of the disk, it reverses its
direction and again services the request arriving in its path. So, this algorithm works as an
elevator and is hence also known as an elevator algorithm. As a result, the requests at the
midrange are serviced more and those arriving behind the disk arm will have to wait.
Advantages:
High throughput
Low variance of response time
Average response time
Disadvantages:
Long waiting time for requests for
Therefore, the total overhead movement (total locations just visited by disk arm
distance covered by the disk arm) is calculated as:
=(199-50)+(199-16) =332
Unit 5: File System 47
• 4.CSCAN: These situations are avoided in CSCAN algorithm in which the disk arm
instead of reversing its direction goes to the other end of the disk and starts servicing the
requests from there. So, the disk arm moves in a circular fashion and this algorithm is also
similar to SCAN algorithm and hence it is known as C-SCAN (Circular SCAN)
Advantages:
Provides more uniform wait time
compared to SCAN
• Any File System that allows Access to Files from Multiple Hosts Sharing via a
Computer Network.
• Makes it Possible for Multiple Users on Multiple Machines to Share Files and
Storage Resources.
• Client Nodes do not have Direct Access to the underlying Block Storage but
interact over the Network using a Protocol.
• Makes it possible to Restrict Access to the File System Depending on Access
lists or Capabilities on both the Servers and the Clients, Depending on How
the Protocol is Designed.
• Include facilities for Transparent replication and Fault tolerance.
• When a limited no. of Nodes in a File System go offline, the System
Continues to Work without Any Data loss.
Unit 5: File System 59
DFS / NFS
Requirements
• Heterogeneity
• Replication
• Transparency
• Consistency
• Concurrency
• Fault tolerance
• Security
• Efficiency
(a) The remote access model (b) The upload / download model
Unit 5: File System 60
Exam Questions
1. Describe the various attributes of files.