Department of computer science and engineering
2010-04-21
Chalmers
Unix internals
ST/AD
Laboratory assignment 3 - Filesystem
Purpose
To investigate a filesystem.
Local filsystem
This exercise must be done on a computer with a local file system.
Assignment:
- Investigate with the mount
command what the file system on your computer looks like. How is the
tree of different mounted filesystems put together? Which parts
are local and which parts are fetched over the network. Which special
purpose filesystems exist?
- Write a C program that duplicates some of the functions
of the Linux stat(1) command.
The program should take the name of a file as parameter and do stat(2) or lstat(2) on this file. The results
should be written to the terminal in a suitable formate (hexadecimal is
probabely best) for analyzing the file status. Use this program on
simple files, directories, special files and symbolic links to find out
the differences between them.
- Write a C program that creates a file and writes 100 bytes with
known content (not binary zero), seeks to position 40000 and writes
another 100 bytes of nonzero data. After this the file is closed and
the program terminated. This program creates a file with a "hole" in
it. Create such a file in the local filesystem. Use the command od to list the content of the file.
Run ls -l and take note of
the length of the file. Use the program from step 2 to check the
lenght of the file and how many blocks the file use. Do the results
agree with the theory? Write a simple copying program that copies the
file by reading and writing one character in a loop until end-of-file.
Copy the file with the "hole" to new file with your copying program. Do
the same checks as previously on the copied file. What have happened?
Copy the file with the "hole" to a new file using the cp command. Do the same checks
again. What have happened?
- Write a C program that searches the local filesystem tree and
gathers information about all the files. The information is used to
calculate the wasted space as a function of block size and to recreate
table 8.12 (page 367) from the course book. To calculate data waste for
different block sizes, the calculation must be done for every file as
the filesystem is searched and summed up for each block size. The
filesystem on the lab machines (Reiserfs) is different from the BSD
file system. This do not matter if only the size of each file is used
to calculate the waste for every block size. Assume that every file and
directory requires one inode and that the size of the inode is 128
bytes. You must avoid searching NFS filesystems because there are too
many files there and it would generate to high load at the file server.
There are also some other special filesystems that should be avoided.
Only "normal" file systems should be searched. One way to avoid the
unwanted filesystems is to make a list of the beginning path name
component of these filesystems that the program use to avoid them.
Also, you should not follow symbolic links! Because it is difficult to
get everything correct from the beginning, the program should use two
arguments to limit the search. The first argument gives the total
number of files to search and the second argument indicates how often
information about the current file name should be written to the
terminal. For example <program_name
100 1> means that 100 files are processed and
information is written for every file. <program_name 1000 50>
means that 1000 files are processed and information is written for
every 50:th file. When everything works both values are set high for
the final run. Check that your results are reasonable and try to
explain any differences between your values and the values from the
book.
Reporting:
Written documentation of your results
including commented program listings. Exercises 3 and 4 should be
demonstrated for a course assistant. The documentation of exercise 4
should include a table like table 8.12 in the course book,
showing your results and a short evaluation of your results.