Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Locating the data blocks belonging to a file implies locating its inode in the inode table first. The inode of the desired file is generally
Locating the data blocks belonging to a file implies locating its inode in the inode table first. The inode of the desired file is generally not known at the time the open operation is issued. What we know is the path of the file. For example:
int open altierello.DONLY;
The desired file is hello.txt while its path is homeealtierihellotxt
To find out the inode belonging to the file we first need to descend through its path, starting from the root directory, until we reach the file's parent directory. At this point we can locate the extdirentry entry corresponding to hello.txt and then its inode number.
Once the inode of the file is known, the data blocks belonging to the hello.txt are specified by the inode.blockl array.
The root directory is always located at inode
Directory entries in the inode table require special attention. To test if an inode refers to a directory file we can use the SDIR mode macro:
if SISDIRinodeimode
In the case of directory entries, the data blocks pointed by iblockl contain a list of the files in the directory and their respective inode numbers.
The super block also tells us the number of blocks per group with sblockspergroup. Using mkfsext we can see that this value is on a floppy disk. Because there are blocks on a floppy, there can only be one group.
question Q What is the difference in terms of internal fragmentation and average file size between using a small block size and a big block size eg question Q What is the size in bytes of a block if slogblocksize in the superblock?
The superblock is located at offset of a floppy. The code to read the superblock from a floppy is shown below. This code also checks the magic number of the super block EXTSUPERMAGIC to see if we are reading from an Ext filesystem. For simplicity, error checking has been omitted.
Limiting the size of a bitmap to one block also limits the size of a blockgroup, because a bitmap always refers to the blocksinodes in the group it belongs to Consider the blocks bitmap: given a block size of bytes, and knowing that each byte is made of bits, we can calculate the maximum number of blocks that the blocks bitmap can represent: blocks. Therefore, blocks is the size of a blockgroup using a byte block size, as we also see from the output of mkfsext in the first section.
question Q Calculate the number of blocks in a blockgroup given a block size of bytes. The following code fragment reads the block bitmap from disk:
In the case of our floppy disk, we can see from the output of mkfsext that we have inodes per group and a block size of bytes. The size of an inode is bytes, therefore the inode table will take blocks.
question Q Assume a block size of bytes. What is the offset of the inode table if bginodetable in the group descritor?
The inode table contains everything the operating system needs to know about a file, including the type of file, permissions, owner, and, most important, where its data blocks are located on disk. It is no surprise therefore that this table needs to be accessed very frequently and its read access time should be minimized as much as possible. Reading an inode from disk every time it is needed is usually a very bad idea. However, in this context we will adopt this method to keep the example code as simple as possible. We provide a general function to read an inode from the inode table:
The offset of the inode to read is calculated by adding together the absolute offset of the inode table the distance of the desired inode from the beginning of the inode table.
question Q Calculate the offset of inode on disk. Assume a block size of bytes inodetable To which block does the inode belong toThe size of an inode structure is bytes
Inodes are numbered starting from An inode is defined as a struct extinode, in extfsh most important fields of this structure have been reported below:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started