Question: This is a very difficult question to answer but it will be really appreciated if anyone can give the solution. I will offer the basic

This is a very difficult question to answer but it will be really appreciated if anyone can give the solution. I will offer the basic code.

See the startup program disk blocks.c in ~veerasam/linux7/a5 We learned about the # of storage blocks and overhead blocks required to store files using this inode structore diagram as the guidance. Now, challenge yourself and develop an algorithm and implement it to compute # of storage blocks and overhead blocks required to store a file of any size. Input will be specified in KBs. Output will have 2 numbers: # of storage blocks and # of overhead blocks. Start early and try to do with minimal help! Here are a sample run (to store a file of size 100KB, we need 13 blocks for storage and 1 overhead block). Note that the input is specified as a command line argument. diskblocks 100 13 1 It is a good idea to use long instead of int, as shown in my startup program. When the input file size is too large to accommodate in the filesystem, output -1 for overhead blocks. Once you complete your program, you can test it with this command (make sure you have Makefile in your directory): testfsb

#include #include #include #include #include #include #include #define SIBLOCKS 2048L #define DIBLOCKS (2048L*2048L) #define TIBLOCKS (2048L*2048L*2048L) #define BLOCK_SIZE 8L*1024L long computeOverheadBlocks(long diskblocks) { // Compute the size of the superblock, group descriptor table, and inode table long sb_size = BLOCK_SIZE; long gdt_size = (diskblocks / 8) / 256 * BLOCK_SIZE; long it_size = (diskblocks / 8) / 4 * sizeof(struct ext4_inode); // Compute the number of indirect blocks required for the given number of disk blocks long nindirect = 0; long nblocks = diskblocks; while (nblocks > 12) { nindirect++; nblocks -= BLOCK_SIZE / sizeof(int); } // Compute the size of the indirect block table long ibt_size = nindirect * BLOCK_SIZE; // Compute the total number of overhead blocks required long overhead_blocks = (sb_size + gdt_size + it_size + ibt_size) / BLOCK_SIZE; // Return the number of overhead blocks return overhead_blocks; } int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: diskblocks "); return -1; } long filesize = atol(argv[1]); long diskblocks = filesize / BLOCK_SIZE; if (filesize % BLOCK_SIZE) diskblocks++;// Check if the file size is too large to fit in the file system if (diskblocks > TIBLOCKS) { printf("-1 "); return -1; } printf("%ld %ld ", diskblocks, computeOverheadBlocks(diskblocks)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!