THINK FIRST·CODE LATER

← All labs

Inode calculator: file sizes and disk reads

Problem

Input: block size (bytes), pointer size (bytes), number of direct pointers; then byte offsets until the end of input. The inode also has one single, one double and one triple indirect pointer.

Print:

Pointers per block: 1024
Blocks reachable: direct 12, single 1024, double 1048576, triple 1073741824
Max file size: 4.00 TiB (4402345721856 bytes)

(the size with two decimals in the largest unit B/KiB/MiB/GiB/TiB/PiB where the value is ≥ 1). Then for each offset: offset 49152: block 12, single indirect, 2 disk reads — the number of disk reads to fetch the data block assuming the inode is in memory (direct 1, single 2, double 3, triple 4; singular 1 disk read) — or offset X: beyond maximum file size.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os11-2-data-1.txt

4096 4 12
0 49151 49152 4243455 4243456 5000000000
What your program must print for os11-2-data-1.txt
Pointers per block: 1024
Blocks reachable: direct 12, single 1024, double 1048576, triple 1073741824
Max file size: 4.00 TiB (4402345721856 bytes)
offset 0: block 0, direct, 1 disk read
offset 49151: block 11, direct, 1 disk read
offset 49152: block 12, single indirect, 2 disk reads
offset 4243455: block 1035, single indirect, 2 disk reads
offset 4243456: block 1036, double indirect, 3 disk reads
offset 5000000000: block 1220703, triple indirect, 4 disk reads

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os11-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os11-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.