Chapter 2 - File System Management
Chapter 2 - File System Management
File System
A Answer the following (1 Mark Questions) :
Marks for these Questions may vary from 1 to 2.
50" Lwuvkh{<"›Pgyn{"etgcvgf"fktgevqt{"yknn"jcxg"vyq"gpvtkgu"cwvqocvkecnn{"kp"kvfiA"
" " "(April 2013)
Uqnwvkqp"
True, newly created directory will contain 2 entries as . and .. as parent and child directory entry.
" V0[0""R0K/Qrgtcvkpi"U{uvgou""♦
♦ "0:/3"" ♦""Hkng"U{uvgo" "
" "V0[0""R0K/Qrgtcvkpi"U{uvgou"♦
♦ "0:/4"" ♦"Hkng"U{uvgo" "
Each file occupy a set of contiguous blocks on the disk. Disk addresses are defined linearly. Here
assumption made is, only one job is accessing the disk. When job wants to access data, it access disk
contiguously, i.e., after reading block n, block n + 1 is accessed, so no head movement is required.
Whenever head movement from last sector of one cylinder to the first sector of the next cylinder, the
head need only move from one track to the next. In this approach of file allocation the number of
disk seeks required is minimal.
Contiguous allocation of a file is defined by the disk address and length of the first block. The
directory entry for each file indicates the address of starting block and the length of the blocks
allocated for this file. For example, if the file is n blocks long and starts at location b, then it
occupies blocks b, b + 1, b + 2… b + n – 1.
" "V0[0""R0K/Qrgtcvkpi"U{uvgou"♦
♦ "0:/5"" ♦"Hkng"U{uvgo" "
8 9 10 11
tr
12 13 14 15
16 17 18 19
mail
20 21 22 23
24 25 26 27
list
28 29 30 31
"
iii. Reading a file: To read from file, both the name of the file and buffer location (where the
block of file should be store). By using name, the directory is searched for associated entry.
System maintain read pointer to the location in the file where the next read is to for reading
and writing to file, each process maintain current file position pointer.
iv. Repositioning within file: The directory is searched for the appropriate entry and the current–
file position pointer is repositioned to a given value. This file operation is known as file seek.
v. Deleting a file: By using specified name, the directory is searched, if found system releases all
file space and erases the directory entry.
vi. Truncating a file: Keeping all attributes of the file, we can erase the content of the file. But if
the file length reset to zero then file space get released.
Rewind
Read or
write "
Above figure shows sequential access file. The file is associated with a read/write pointer. A read
operation (read next) reads the next block of the file and automatically advances a file pointer. A
write operation (write next) appends to the end of the file and pointer points to the new end of file.
Files can be reset to the beginning. Also pointer can be skipped ‘n’ records forward or backward.
find list
hex count
Tree has a root directory-Every file in the system has a unique path name. The path name is the
path from the root, through all the subdirectories to a specified file.
In normal use, each user has current directory with specified system call, one can change
directory by giving path to be directory path name can be absolute or relative.
70" Gzrnckp" Nkpmgf" cpf" Kpfgzgf" hkng" cnnqecvkqp" ogvjqfu" cnqpi" ykvj" ogtkvu" cpf""
fgogtkvu0""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""(April 2013) "
Uqnwvkqp" "
Linked file allocation: In linked allocation approach, each file is a linked list of disk blocks,
which may be scattered anywhere on the disk. The direction entry for the file contains a pointer to
the first and last block of the file. Each block contains a pointer to the next block. These pointer are
hidden from the user.
Figure shows linked allocation of disk space.
fktgevqt{
4 5 6 7
8 9 10 2 11
12 13 14 15
16 17 18 19
20 21 22 23
24 25 -1 26 27
28 29 30 31
"
In above figure, a file of five blocks might starts at block 9 and continue at block 16, then block
1, then block 10 and finally block 25.
If each block is 512 in size, and a disk address requires 4 bytes, then user sees block of 508 bytes
and 4 bytes are kept reserved for pointer.
Whenever new file is created, a new entry in directory is made. Each directory entry has a pointer
to the first block of file (initially it is nil as file size is set to 0). When information is written to file,
free block is allocated to file and this new block is linked to the end of the file.
Whenever a file is read, we simply read blocks by following the pointer from block to block
" "V0[0""R0K/Qrgtcvkpi"U{uvgou"♦
♦ "0:/8"" ♦"Hkng"U{uvgo" "
Merits
i. There is no external fragmentation with linked allocation.
ii. File can be grown as much as user desire in this approach.
iii. No size of a file is known in advanced to the creator of the file.
Demerits
i. Linked allocation can be used effectively only for sequential access files. It is inefficient to
support a direct access of files.
Consider that we want to access ith block of file. We must start at the beginning of that file and
follow the pointers until we get to the ith block. Thus we have to access file sequentially.
ii. Another disadvantage of this approach is the space required for the pointers.
If we consider that 4 bytes are required to store pointer, 0.78 percent of disk is utilised for
pointers. One solution to this is, instead of blocks, clusters are used.
iii. Reliability is another issue in linked allocation. File is stored in scattered blocks linked by
pointers. But if a pointer is lost or damaged, we may pick up a wrong pointer or no pointer is
available while accessing the file.
Indexed file allocation: In indexed allocation, all pointers are kept together into the index table
following is the logical view of index table.
Each file has its own index block. An index block is an array of disk block addresses. The 1st
entry in the index block points to the 1st block of the file, 2nd entry points to the 2nd block and so on
the ith entry in the index block points to the ith block of the file. The directory entry contains the address of
the index block.
Figure shows index allocation of file.
fktgevqt{
4 5 6 7
8 9 10 11
9
12 13 14 15 16
1
10
16 17 18 19 19
25
1
20 21 22 23 1
1
24 25 26 27
28 29 30 31
"
" "V0[0""R0K/Qrgtcvkpi"U{uvgou"♦
♦ "0:/9"" ♦"Hkng"U{uvgo" "
th th
To access i block of the file, we use the pointer in the i index block entry.
Whenever file is created, all pointers in the index block are initialized to nil. Whenever data is
written to the block, a free block is obtained and its address is put in the appropriate index block
entry.
Merits
i. Index allocation do not suffer from external fragmentation.
ii. It supports direct access.
iii. Memory required to store index block is more than that of in linked allocation. No matter how
many pointers are there with non-nil value, we have to allocate memory to index block.
80" Gzrnckp"Vtgg/uvtwevwtgf"fktgevqtkgu"cnqpi"ykvj"cfxcpvcigu"cpf"fkucfxcpvcigu0"
(October 2012)
Uqnwvkqp"
In this structure, each user has separate directory.
Two levels of directories are used system’s Master File Directory (MFD) and User File Directory
(UFD).
Each user has his own UFD. Each UFD lists only the files of a single user. When a user process
starts, the MFD is searched. The MFD has indexes to point each entry point to the UFD for that user.
Two level directory can be thought of tree with height 2. The root is MFD and its children are UFDs.
Ocuvgt"hkng
fktgevqt{ User 1 User 2 User 3 User 4
Wugt"hkng a a x
Text B Max Min Test B Data b
fktgevqtkgu
Hkngu "
Advantages
i. Particular file is searched in specific user’s UFD, who is referring it. Hence same file name
can be used by different users.
ii. To create and delete file, the operating system searches only that user’s UFD.
iii. This structure isolates one user from another.
Disadvantages
i. If user wants to share their file’s data to perform some task, system does not allow local user
file to be accessed by other user.
" "V0[0""R0K/Qrgtcvkpi"U{uvgou"♦
♦ "0:/:"" ♦"Hkng"U{uvgo" "
ii. If any user wants to execute these system files, he gives command and command interpreter
treat such a command as the name of a file to load and execute. This file name would be
searched for in the current UFD we may then need to copy the system files into each UFD.
But this would be waste an large amount of space.
90" Gzrnckp"fkhhgtgpv"ogvjqfu"hqt"jcpfnkpi"htgg/urceg"nkuv"kp"hkng"u{uvgo0""""""
" " "(April 2012)""""
Uqnwvkqp"
The system maintains a free-space list to keep track of free disk space.
The free-space list contains all free disk blocks, i.e., the blocks which are not allocated to some
file or directory.
Whenever a new file is created, first the free-space list is searched for required amount of space
and allocates that space to the new file. This space is then removed from the free-space list.
When a file is deleted, its disk space is added to the free-space list.
Implementation of free space list is done by
i. Bit vector: The free-space list is implemented as a bit map or bit vector. Each block is
represented by 1 bit. If block is free, the bit is 1. If block is allocated to any file or directory,
the bit is 0.
ii. Linked list: In this approach, all the free blocks are linked together. Pointer to the first free
block is kept in a special location on the disk and cached in memory. First block contains a
pointer to the 2nd free block; second free block contains a pointer to third and so on.
iii. Grouping: In this approach, the address of n free blocks are stored in the first free block. The
first n–1 of these blocks are free blocks. The last (nth) block contains the addresses of another
n free blocks and so on. In this approach, traversing a list is avoided. Large number of free
blocks can be found quickly.
iv. Counting: In this approach, the address of the first free block and the number n(count) of free
contiguous blocks that follow the first block are stored. Each entry in the free-space list then
consists of a disk address and a count, it requires more space but the list is shorter.
v. Space maps: The space map is a log of all block activity (i.e., allocation and freeing of
blocks) in time order, in counting format. When ZFS has to allocate or free space from a
metaslab, it loads the associated space map into memory.
To make this operation efficient, it uses balanced-tree structure, indexed by offset. It replays
the log into that structure. The in-memory space map becomes accurate representation of the
allocated and free space in the metaslabs. ZFS combine contiguous free block as much as
possible in single entry. The free-space list is updated on disk. If during the process of the
collection and sorting phase, block request occurs, then ZFS satisfies these requests from the
log. Thus, the log and the balanced tree is the free-list.