For Assignment 3, you will be manipulating an Ext2 file system image. The next few exercises are intended to help you get started on the assignment by helping you understand the structure of the file system. Please start early to fully take advantage of the tutorial time to ask questions.
Please read the Assignment 3 handout. It has links to some resources that you will need to read to fully understand the ext2 structure, especially sections "Learning about the Filesystem" and "Mounting a filesystem".
You are given two files as starter code:
There are also a bunch of disk images available to you:
level1
and a file called afile
. level1
contains a directory called level2
, and level2
contains a file called bfile
.Note that readimage
uses mmap
to map
the disk image file into memory. The superblock is in the second
block on the disk starting at byte 1024, so we can interpret these
bytes as the super block struct.
You should also look at these bytes of the one of the images,
for example emptydisk.img by running xxd emptydisk.img > emptydisk.txt
and using an editor to view the contents of the file. Try the following:
Your task for this exercise is simple. Add to readimage
to print out the following fields from the block group descriptor.
For emptydisk.img
your output should look exactly
like the following. In other words, we should be able to use diff
to compare your output to this and see that it is identical.
Inodes: 32 Blocks: 128 Block group: block bitmap: 3 inode bitmap: 4 inode table: 5 free blocks: 105 free inodes: 21 used_dirs: 2
Using the same code you wrote, add the code to print out the inode and block bitmaps, and the inodes.
For emptydisk.img
your output should exactly
match the following. In other words, we should be able to use
diff
to compare your output to this and see that
it is identical.
Inodes: 32 Blocks: 128 Block group: block bitmap: 3 inode bitmap: 4 inode table: 5 free blocks: 105 free inodes: 21 used_dirs: 2 Block bitmap: 11111111 11111111 11111100 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 Inode bitmap: 11111111 11100000 00000000 00000000 Inodes: [2] type: d size: 1024 links: 3 blocks: 2 [2] Blocks: 9
For onefile.img
your output should match the following:
Inodes: 32 Blocks: 128 Block group: block bitmap: 3 inode bitmap: 4 inode table: 5 free blocks: 104 free inodes: 20 used_dirs: 2 Block bitmap: 11111111 11111111 11111100 00000000 00100000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 Inode bitmap: 11111111 11110000 00000000 00000000 Inodes: [2] type: d size: 1024 links: 3 blocks: 2 [2] Blocks: 9 [12] type: f size: 128 links: 1 blocks: 2 [12] Blocks: 35
Your final task in this series of exercises is to print the directory
block contents. While you are doing this, you should work out how the
directory structure creates a linked list of directory entries by using
rec_len
to show where the next directory entry begins.
Note that rec_len
in the last directory entry takes you
to the end of the block.
For emptydisk.img
your output should exactly
match the following. In other words, we should be able to use diff
to compare your output to this and see that it is identical.
Inodes: 32 Blocks: 128 Block group: block bitmap: 3 inode bitmap: 4 inode table: 5 free blocks: 105 free inodes: 21 used_dirs: 2 Block bitmap: 11111111 11111111 11111100 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 Inode bitmap: 11111111 11100000 00000000 00000000 Inodes: [2] type: d size: 1024 links: 3 blocks: 2 [2] Blocks: 9 Directory Blocks: DIR BLOCK NUM: 9 (for inode 2) Inode: 2 rec_len: 12 name_len: 1 type= d name=. Inode: 2 rec_len: 12 name_len: 2 type= d name=.. Inode: 11 rec_len: 1000 name_len: 10 type= d name=lost+found
For twolevel.img
your output should match the following:
Inodes: 128 Blocks: 128 Block group: block bitmap: 3 inode bitmap: 4 inode table: 5 free blocks: 91 free inodes: 113 used_dirs: 4 Block bitmap: 11111111 11111111 11111111 11111111 11100000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000011 Inode bitmap: 11111111 11111110 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 Inodes: [2] type: d size: 1024 links: 4 blocks: 2 [2] Blocks: 21 [12] type: d size: 1024 links: 3 blocks: 2 [12] Blocks: 127 [14] type: d size: 1024 links: 2 blocks: 2 [14] Blocks: 35 Directory Blocks: DIR BLOCK NUM: 21 (for inode 2) Inode: 2 rec_len: 12 name_len: 1 type= d name=. Inode: 2 rec_len: 12 name_len: 2 type= d name=.. Inode: 11 rec_len: 20 name_len: 10 type= d name=lost+found Inode: 12 rec_len: 16 name_len: 6 type= d name=level1 Inode: 13 rec_len: 964 name_len: 5 type= f name=afile DIR BLOCK NUM: 127 (for inode 12) Inode: 12 rec_len: 12 name_len: 1 type= d name=. Inode: 2 rec_len: 12 name_len: 2 type= d name=.. Inode: 14 rec_len: 1000 name_len: 6 type= d name=level2 DIR BLOCK NUM: 35 (for inode 14) Inode: 14 rec_len: 12 name_len: 1 type= d name=. Inode: 12 rec_len: 12 name_len: 2 type= d name=.. Inode: 15 rec_len: 1000 name_len: 5 type= f name=bfile