0% found this document useful (0 votes)
44 views

Tutorial

The document discusses the internal representation of file systems in operating systems. It describes algorithms like iget(), iput(), bmap(), namei(), ialloc(), and ifree() that are used for file handling operations like allocating inodes, releasing inodes, converting byte offsets to block numbers, and converting path names to inodes. It also explains data structures like inodes, directories, superblocks, and linked lists that track free disk blocks and how they are used to manage disk space allocation and freeing for files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Tutorial

The document discusses the internal representation of file systems in operating systems. It describes algorithms like iget(), iput(), bmap(), namei(), ialloc(), and ifree() that are used for file handling operations like allocating inodes, releasing inodes, converting byte offsets to block numbers, and converting path names to inodes. It also explains data structures like inodes, directories, superblocks, and linked lists that track free disk blocks and how they are used to manage disk space allocation and freeing for files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

BITS Pilani

Tutorial session 5: Internal


Representation of File system
(Continued)
Review of last tutorial
• Free list, lock information, reference count
• iget() algorithm
• Releasing nodes
• Structure of a regular file
• Allocation of disk space for a file in non-contiguous spaces
• Inode structure of table of contents
 Single indirect block
 Double indirect block
 Triple indirect block
• Maximum file size referenced by the table
• Accessing given file’s byte offset and computing the block
number using table structure of system V Unix system

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 2


Algorithms used in File handling
internally by the operating system
• iget(): allocation for in-core inodes
• iput(): releasing an inode
• bmap(): conversion of byte offset to block
number in file system
• namei(): conversion of a path name to an
inode.
• ialloc(): for assigning new nodes
• ifree(): for freeing inode
• alloc(): allocating disk block

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 3


Directories
• Directories are the files that give the file
system its hierarchical structure.
• Its data is a sequence of entries, each
consisting of an inode number and the name
of a file contained in the directory.
• The last component of the path may be a non-
directory file.
• UNIX system V restricts the components name
to a maximum of 14 characters (2 bytes for
inode number)
September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 4
Directory layout for /etc

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 5


Directories
• Directories are maintained by the kernel in the same
way it maintains the files
• Each directory has an associated inode.
• Processes read the directories in the same way as they
read an ordinary file
• A process must have permission to search the contents
of the directory
• A directory’s data is the information about other sub-
directories and files.
• The inode corresponding to the directory name has
information about other sub-directories in its data
block table.

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 6


Conversion of a path name to an
inode
• The kernel uses an algorithm namei() for converting
the path name to a inode
• Example path name is ../etc/subdir1/subdir2/file
The path has components separated by /
• The algorithm parses the components one by one and
converts each component to an inode based on its
name and directory
• Processes can change their directory using chdir
command
• Namei() uses intermediate inodes as it parses a path
name
• The intermediate inodes are called as working inodes

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 7


Working inodes
• The root .. Is the first working inode.
• The byte offsets of the subdirectories are
placed in the data blocks of the parent
directory.
• The search for the working inode terminates
after the leaf node of the path in the file’s
hierarchical structure
• The namei() algorithm uses bmap() algorithm
to reach the block containing data of working
inode iteratively for each component.
September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 8
Superblock
The record structure of the superblock is
• Size of file system
• Number of free blocks in the file system
• List of free blocks available on the file system
• Index of the next free block in the free block list
• The size of the inode list
• The number of free inodes in the file system
• A list of free inodes in the file system
• The index of the next free inode in the free inode list
• Lock fields for the free block and free inode lists
• The flag indicating the the super block has been modified

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 9


Inode assignment to a new file
• For given path name, the kernel uses namei()
algorithm to convert this into corresponding
inode.
• If the inode is previously determined, the kernel
uses iget() algorithm to allocate the inode to the
file.
• If the file is newly created, then the algorithm
ialloc() assigns a disk inode to the file.
• The superblock free inode information is
accessed by the kernel for getting the free inode.

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 10


Inode assignment to a new file
• The kernel first verifies that no other processes have
locked access to the super block free inode list
• If the list of inode numbers in the superblock is not
empty,
 the kernel assigns the next inode number to the new file
 Allocates a free in-core inode for the newly assigned disk
inode using iget()
 Copies the disk inode to the in-core copy
 Initializes the fields in the inode
 And returns the locked inode (to indicate that the inode is
in use)

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 11


Assigning free inode from middle
of list

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 12


When the list of inodes is empty
• If the list of inode numbers in the superblock is empty
 The kernel searches the disk
 Places as many free inode numbers as possible into the
superblock
 The kernel reads the inode list on disk, block by block, and
fills the superblock list of inode numbers to the full
capacity
 It remembers the highest numbered inode that it finds and
calls that “remembered node”
 The remembered node is the last one saved in the
superblock
 Next time when kernel needs to search the free list on
disk, it starts its search from the remembered inode

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 13


Assigning free inode when
superblock list is empty

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 14


ialloc()
algorithm

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 15


Allocation of disk blocks
• When a process writes data to a file, the kernel
allocates disk blocks from the file system for direct and
indirect data blocks.
• File system super block contains an arraythat is used to
cache the numbers of free disk blocks in the file
system.
• The utility program mkfs (make file system) organizes
the data blocks of a file system in a linked list.
• The linked list has address of the next block containing
free disk block numbers
• The first entry of the block can be the address of the
next block containing the addresses of free blocks

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 16


Linked list of free
Disk Block
Numbers

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 17


Alloc()
algorithm

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 18


Original configuration

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 19


When a block is freed, its number is added to
the free list of disk blocks

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 20


An other block is needed, then
taken from the super block list

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 21


When the super block list is
empty

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 22


Freeing a disk block
• It is the reverse of allocating a block for an
inode
• When a block is freed, its number is written in
the super block list
 If the super block list is not full, then the block
number of the freed block is written onto the
super block list
 If the super block list is full, then the newly freed
block becomes a link block. Later all free blocks
numbers are further written in this block

September 25, 2020 OS Tutorial 5 (Sections 3 and 4) 23

You might also like