Chapter 5-OS-FileSystems
Chapter 5-OS-FileSystems
File Systems
Files
⮚ Processes (threads), address spaces, files are the most
important concepts in OS
⮚ Every File has a logical location where they are located for
storage and retrieval.
File system
• File descriptor
1. Sequential Access
•Data is accessed one record right after another is an order.
•Read command cause a pointer to be moved ahead by one.
•Write command allocate space for the record and move the
pointer to the new End Of File.
•Such a method is reasonable for tape.
File Access Methods contd..
2. Direct Access
⮚This method is useful for disks.
⮚The file is viewed as a numbered sequence of blocks or
records.
⮚There are no restrictions on which blocks are read/written, it
can be done in any order.
⮚User now says "read n" rather than "read next".
⮚"n" is a number relative to the beginning of file, not relative to
an absolute physical disk location.
File Access Methods contd..
• Create • Append
• Delete • Seek
• Open • Get Attributes
• Close • Set Attributes
• Read • Rename
• Write
What is a directory?
• Create • Readdir
• Delete • Rename
• Opendir • Link
• Closedir • Unlink
Permissions on the file and directory
The permissions are R W X which are regarding reading, writing and the execution of the
files or directory. The permissions are assigned to three types of users: owner, group and
others.
File Group Everyone
Owner Owner Else
• Users:
– How files are named, what operations are allowed on them,
what the directory tree looks like
• Implementors
– How files and directories are stored, how disk space is
managed and how to make every thing work efficiently and
reliably
Master Boot Record (MBR)
⮚ Master boot record is the information present in the first sector of any
hard disk. It contains the information regarding how and where the
Operating system is located in the hard disk so that it can be booted in
the RAM.
⮚ MBR is sometimes called master partition table because it includes a
partition table which locates every partition in the hard disk.
⮚ Master boot record (MBR) also includes a program which reads the
boot sector record of the partition that contains operating system.
File System Layout
⮚ Due to the fact that the main memory is volatile, when we turn on our
computer, CPU
⮚ cannot access the main memory directly. However, there is a special
program called as BIOS stored in ROM is accessed for the first time by
the CPU.
⮚ BIOS contains the code, by executing which, the CPU access the very
first partition of hard disk that is MBR. It contains a partition table for all
the partitions of the hard disk.
⮚ Since, MBR contains the information about where the operating system
is being stored and it also contains a program which can read the boot
sector record of the partition, hence the CPU fetches all this information
and load the operating system into the main memory.
File System Layout
Superblock: contains all the key parameters about a file
system; read into memory the booted or the FS is used
⮚ When a new file is created, then the entire list is checked whether
the new file name is matching to a existing file name or not.
⮚ A key-value pair for each file in the directory gets generated and
stored in the hash table. The key can be determined by applying
the hash function on the file name while the key points to the
corresponding file stored in the directory.
2. Hash Table contd..
⮚ Now, searching becomes efficient due to the fact that now, entire list will not be
searched on every operating. Only hash table entries are checked using the key
and if an entry found then the corresponding file will be fetched using the value.
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.
Linked List Allocation
⮚ Each file is considered as the linked list of disk blocks.
⮚ However, the disks blocks allocated to a particular file need not to be contiguous
on the disk.
⮚ Each disk block allocated to a file contains a pointer which points to the next disk
block allocated to the same file.
File Allocation Table
⮚ The main disadvantage of linked list allocation is that the
Random access to a particular block is not provided. In order to
access a block, we need to access all its previous blocks.
Advantages
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
An example i-node.
Free Space Management
A file system is responsible to allocate the free blocks to the file therefore it
has to keep track of all the free blocks present in the disk.
There are mainly two approaches by using which, the free blocks in the disk
are managed.
1. Bit Vector
⮚In this approach, the free space list is implemented as a bit map vector. It
contains the number of bits where each bit represents each block.
⮚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.
Free Space Management
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.
Contiguous Allocation