Operating Systems 2014F: Assignment 6
Part A
- [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.)
- [1] Run mkfs.ext4 foo. (Say "yes" to operating on a regular file.) Does foo consume any more space?
- [1] What command do you run to check the filesystem in foo for errors?
- [1] Run mount foo /mnt. What does this command do?
- [1] Run df. What device is mounted on /mnt? What is this device?
- [1] Run rsync -a -v /etc /mnt. What does this command do? Explain the arguments as well.
- [1] Run umount /mnt. What files can you still access, and what have gone away?
- [1] Run dd if=/dev/zero of=foo conv=notrunc count=10 bs=512. What does this command do?
- [1] Run mount foo /mnt. What error do you get?
- [1] What command can you run to make foo mountable again? What characteristic of the file system enables this command to work?
- [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?
- [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
- [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()
- [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().