Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following code, but the code is not outputting what i wanted it to output. I need mainly focus on computeOverheadBlocks. the result

I have the following code, but the code is not outputting what i wanted it to output. I need mainly focus on computeOverheadBlocks. the result that the code should output will look like this. Mainly goal is to have the same expected and got value. please do not provide your answer unless you run the code and got the same value. Thank you.

Mismatch for 0 : Expected 0, got 1 Mismatch for 1 : Expected 0, got 1 Mismatch for 10 : Expected 0, got 1 Mismatch for 100 : Expected 1, got 2 Mismatch for 1000 : Expected 1, got 2 Mismatch for 10000 : Expected 1, got 2 Mismatch for 15000 : Expected 1, got 2 Mismatch for 16000 : Expected 1, got 2 Mismatch for 16400 : Expected 1, got 3 Mismatch for 16480 : Expected 1, got 3 Mismatch for 16500 : Expected 3, got 4 Mismatch for 17000 : Expected 3, got 4 Mismatch for 20000 : Expected 3, got 4 Mismatch for 30000 : Expected 3, got 4 Mismatch for 40000 : Expected 4, got 6 Mismatch for 100000 : Expected 8, got 14 Mismatch for 1000000 : Expected 63, got 125 Mismatch for 10000000 : Expected 612, got 1241 Mismatch for 30000000 : Expected 1833, got 3721 Mismatch for 33000000 : Expected 2016, got 4092 Mismatch for 33500000 : Expected 2046, got 4153 Mismatch for 33570000 : Expected 2050, got 4162 Mismatch for 33570900 : Expected 2050, got 4163 Mismatch for 33570910 : Expected 2050, got 4163 Mismatch for 33570912 : Expected 2050, got 4163 Mismatch for 33571000 : Expected 2053, got 4164 Mismatch for 33580000 : Expected 2053, got 4164 Mismatch for 33600000 : Expected 2054, got 4166 Mismatch for 34000000 : Expected 2079, got 4216 Mismatch for 40000000 : Expected 2445, got 4960 Mismatch for 50000000 : Expected 3055, got 6199 Mismatch for 100000000 : Expected 6108, got 12398 Mismatch for 1000000000 : Expected 61067, got 123979 Mismatch for 10000000000 : Expected 610652, got 1239777 Mismatch for 20000000000 : Expected 1221302, got 2479554 Mismatch for 30000000000 : Expected 1831951, got 3719330 Mismatch for 40000000000 : Expected 2442601, got 4959107 Mismatch for 50000000000 : Expected 3053250, got 6198883 Mismatch for 60000000000 : Expected 3663900, got 7438660 Mismatch for 68000000000 : Expected 4152419, got 8430481 Mismatch for 68700000000 : Expected 4195165, got 8517266 Mismatch for 68750000000 : Expected 4198217, got -1 Mismatch for 68752000000 : Expected 4198340, got -1 Mismatch for 68753000000 : Expected 4198401, got -1 Mismatch for 68753040000 : Expected 4198403, got -1 Mismatch for 68753047000 : Expected 4198403, got -1 Mismatch for 68753047600 : Expected 4198403, got -1 Mismatch for 68753047648 : Expected 4198403, got -1

//may be the last one #include #include #include #include #include #include #include

#define SIBLOCKS 2048L #define DIBLOCKS (2048L*2048L) #define TIBLOCKS (2048L*2048L*2048L) #define BLOCK_SIZE 8L*1024L

struct ext4_inode { int size; };

long computeOverheadBlocks(long diskblocks) { 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;//i use BLOCK_SIZE insted of 8; 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

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions