Operating Systems 2014F: Assignment 6

From Soma-notes
Revision as of 15:43, 10 December 2014 by Soma (talk | contribs)

Please submit the answers to the following questions via CULearn by midnight on Wednesday, November 12, 2014. There 20 points in 14 questions.

Submit your answers as a single text file named "<username>-comp3000-assign6.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Assignment 6", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.

No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit a zip file, MS Word, or OpenOffice file as your answers document!

Don't forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.

Part A

  1. [1] dd if=/dev/zero of=foo bs=8192 count=32K What is the logical size of the file? How much space does it consume on disk? (Hint: Look at the size option to ls.)
  2. [1] Run mkfs.ext4 foo. (Say "yes" to operating on a regular file.) Does foo consume any more space?
  3. [1] What command do you run to check the filesystem in foo for errors?
  4. [1] Run mount foo /mnt. How does this command change what files are accessible?
  5. [1] Run df. What device is mounted on /mnt? What is this device?
  6. [1] Run rsync -a -v /etc /mnt. What does this command do? Explain the arguments as well.
  7. [1] Run umount /mnt. What files can you still access, and what have gone away?
  8. [1] Run dd if=/dev/zero of=foo conv=notrunc count=10 bs=512. How does the "conv=notrunc" change dd's behavior (versus the command in question 1)?
  9. [1] Run sudo mount foo /mnt. What error do you get?
  10. [1] What command can you run to make foo mountable again? What characteristic of the file system enables this command to work?
  11. [1] Run the command truncate -s 1G bar. What is the logical size of bar, and how much space does it consume on disk? How does this compare with foo?
  12. [1] How does the logical size of bar change when you create an ext4 filesystem in it? What about the space consumed on disk?

Part B

  1. [4] Write your own version of the command line program stat, which simply calls the stat() system call on a given file or directory. Print out file size, number of blocks allocated, reference (link) count, and so forth. What is the link count of a directory, as the number of entries in the directory changes? Useful interfaces: stat()
  2. [4] Write a program that prints out the last few lines of a file. The program should be efficient, in that it seeks to near the end of the file, reads in a block of data, and then goes backwards until it finds the requested number of lines; at this point, it should print out those lines from beginning to the end of the file. To invoke the program, one should type: mytail -n file, where n is the number of lines at the end of the file to print. Useful interfaces: stat(), lseek(), open(), read(), close().

Solutions

Solutions for this assignment were discussed in Lecture 22.

  1. Logical size is 268435456 bytes (as reported by ls -l). Physical size is 262144 blocks (as reported by ls -ls). By default ls assumes blocks are 1K in size; thus the physical space taken up by the file is 262144 * 1024 = 268439552 bytes. In other words, the physical size is 4096 bytes larger than the logical size. Note ext4 by default uses 4K blocks.
  2. No - it consumes less space. The logical size stays the same, but now it only consumes 8798208 bytes. In other words the physical size is around 3.3% of the logical size! (Note mkfs.ext4 somehow inserted "holes" into the file.)
  3. fsck or fsck.ext4 (fsck calls fsck.ext4 when it figures out the filesystem is ext4)
  4. Anything previously in /mnt is now not available, and the files of the filesystem in foo are now available within /mnt.
  5. /dev/loop0. This is a loopback block device. It allows a file such as foo (associated with the device) to be accessed as if it were a block device.
  1. rsync -a -v /etc /mnt. Synchronize (in this case, copy) contents of /etc to /mnt. -a means archive (use recursion and grab almost everythin), -v is verbose.
  2. Any files that were previously in /mnt before the mount command is now accessible. Any files that were in /mnt (i.e, in the foo filesystem) are not accessible.
  3. conv=notrunc means that dd will not truncate the file after it is done writing - it leaves other data in the file intact.
  4. error is: mount: you must specify the filesystem type
  5. fsck?
  6. Logical size is 1G. Physical size is 0.
  7. The logical size stays the same. The physical size increases.