File Management
File Management
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 structure
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.
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:
It is a hardware file that reads or writes data character by character, like mouse,
printer, and more.
Ordinary files
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.
Functions of File
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.
Field:
This element stores a single value, which can be static or variable length.
DATABASE:
FILES:
RECORD:
A Record type is a complex data type that allows the programmer to create a
new data type with the desired column structure. Its groups one or more columns
to form a new data type. These columns will have their own names and data
type.
File access is a process that determines the way that files are accessed and read
into memory. Generally, a single access method is always supported by
operating systems. Though there are some operating system which also
supports multiple access methods.
Sequential access
Direct random access
Index sequential access
Sequential Access
Most of the operating systems access the file sequentially. In
other words, we can say that most of the files need to be
accessed sequentially by the operating system.
In sequential access, the OS read the file word by word. A
pointer is maintained which initially points to the base address of
the file. If the user wants to read first word of the file then the
pointer provides that word to the user and increases its value by
1 word. This process continues till the end of the file.
Modern word systems do provide the concept of direct access
and indexed access but the most used method is sequential
access due to the fact that most of the files such as text files,
audio files, video files, etc need to be sequentially accessed.
Direct Access
Indexed Access
Directory Structure
What is a directory?
Directory can be defined as the listing of the related files on the disk.
The directory may store some or the entire file attributes.
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.
A directory can be viewed as a file which contains the Meta data of the
bunch of files.
1. File Creation
2. Search for the file
3. File deletion
4. Renaming the file
5. Traversing Files
6. Listing of files
The simplest method is to have one big list of all the files on the
disk. The entire system will contain only one directory which is
supposed to mention all the files present in the file system. The
directory contains one entry per each file present on the file system.
Disadvantages
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.
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.
Permissions on the file and directory
There are various methods which can be used to allocate disk space to
the files. Selection of an appropriate allocation method will significantly
affect the performance and efficiency of the system. Allocation method
provides a way in which the disk will be utilized and the files will be
accessed.
1. Contiguous Allocation.
2. Extents
3. Linked Allocation
4. Clustering
5. FAT
6. Indexed Allocation
7. Linked Indexed Allocation
8. Multilevel Indexed Allocation
9. Inode
Contiguous Allocation
If the blocks are allocated to the file in such a way that all the logical
blocks of the file get the contiguous physical block in the hard disk
then such allocation scheme is known as contiguous allocation.
In the image shown below, there are three files in the directory. The
starting block and the length of each file are mentioned in the table.
We can check in the table that the contiguous blocks are assigned to
each file as per its need.
Advantages
1. It is simple to implement.
2. We will get Excellent read performance.
3. Supports Random Access into files.
Disadvantages
Disadvantages
Disadvantages
1. Bit Vector
If the block is empty then the bit is 1 otherwise it is 0. Initially all the
blocks are empty therefore each bit in the bit map vector contains 1.
LAs the space allocation proceeds, the file system starts allocating
blocks to the files and setting the respective bit to 0.
2. Linked List
It is another approach for free space management. This approach
suggests linking together all the free blocks and keeping a pointer in
the cache which points to the first free block.
Therefore, all the free blocks on the disks will be linked together with a
pointer. Whenever a block gets allocated, its previous free block will be
linked to its next free block.
Disk Scheduling
Seek Time
Seek time is the time taken in locating the disk arm to a specified
track where the read/write request will be satisfied.
Rotational Latency
Transfer Time
Disadvantages
Consider the following disk request sequence for a disk with 100 tracks
45, 21, 67, 90, 4, 50, 89, 52, 61, 87, 25
Solution
= (50-45)+(45-21)+(67-21)+(90-67)+(90-4)+(50-4)+(89-50)+(61-
52)+(87-61)+(87-25)
= 5 + 24 + 46 + 23 + 86 + 46 + 49 + 9 + 26 + 62
= 376
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.
It allows the head to move to the closest track in the service queue.
Disadvantages
Example
Consider the following disk request sequence for a disk with 100 tracks
Solution:
Number of cylinders = 5 + 7 + 9 + 6 + 20 + 2 + 1 + 65 + 4 + 17 =
136
Scan Algorithm
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Number of Cylinders = 40 + 14 + 65 + 13 + 20 + 24 + 11 + 4 + 46 =
237
C-SCAN algorithm
Example
Consider the following disk request sequence for a disk with 100 tracks
Look Scheduling
Example
Consider the following disk request sequence for a disk with 100 tracks
C Look Scheduling
Example
Consider the following disk request sequence for a disk with 100 tracks