Answered step by step
Verified Expert Solution
Link Copied!

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 fd= open (?homeealtierihello.txt,ORDONLY);
The desired file is hello.txt, while its path is /home/ealtieri/hello.txt.
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 ext2_dir_entry_2 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 2.
Directory entries in the inode table require special attention. To test if an inode refers to a directory file we can use the SISDIR (mode) macro:
if (S_ISDIR(inode.i_mode))...
In the case of directory entries, the data blocks pointed by i_blockl] 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 s_blocks_per_group. Using mkfs.ext2, we can see that this value is 8192 on a floppy disk. Because there are 1440 blocks on a floppy, there can only be one group.
question Q1. What is the difference in terms of internal fragmentation and average file size between using a small block size (1024) and a big block size (e.g.8192)? question Q2. What is the size in bytes of a block if s_log_block_size =3 in the super-block?
The superblock is located at offset 1024 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 (EXT2_SUPER_MAGIC) to see if we are reading from an Ext2 filesystem. For simplicity, error checking has been omitted.
Limiting the size of a bitmap to one block also limits the size of a block-group, because a bitmap always refers to the blocks/inodes in the group it belongs to. Consider the blocks bitmap: given a block size of 1024 bytes, and knowing that each byte is made of 8 bits, we can calculate the maximum number of blocks that the blocks bitmap can represent: 8**1024=8192 blocks. Therefore, 8192 blocks is the size of a block-group using a 1024-byte block size, as we also see from the output of mkfs.ext2 in the first section.
question Q3. Calculate the number of blocks in a block-group given a block size of 4096 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 mkfs.ext 2 that we have 184 inodes per group and a block size of 1024 bytes. The size of an inode is 128 bytes, therefore the inode table will take 1841024128=23 blocks.
question Q4. Assume a block size of 2048 bytes. What is the offset of the inode table if bg_inode_table=5 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 Q5. Calculate the offset of inode 93 on disk. Assume a block size of 1024 bytes bg-inode_table =5. To which block does the inode belong to?(The size of an inode structure is bytes)
Inodes are numbered starting from 1. An inode is defined as a struct ext2_inode, in ext2_fs.h. most important fields of this structure have been reported below:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

Students also viewed these Databases questions

Question

1. Give them prompts, cues, and time to answer.

Answered: 1 week ago