Operating Systems 2014F: Assignment 6

From Soma-notes
Revision as of 17:57, 5 November 2014 by Soma (talk | contribs)
Jump to navigation Jump to search

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. What does this command do?
  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. What does this command do?
  9. [1] Run 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 foo, and how much space does it consume on disk? How does this compare with foo?
  12. [1] How does the logical size of foo 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().