Unix Project
Project: File system utilities
Description: In this individual project, you’ll write four different programs based on various UNIX utilities.
Requirements:
1. mystat.c: 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, file permissions, and file inode.
Useful interfaces: stat()
2. myls.c: Write a program that lists files in the given directory, à la ls. When called without any arguments, the program should just print the file names. When invoked with the -l flag, the program should print out information about each file, such as the owner, group, permissions, and other information obtained from the stat() system call. The program should take one additional argument, which is the directory to read, e.g., myls -l directory. If no directory is given, the program should just use the current working directory.
Useful interfaces: stat(), opendir(), readdir(), getcwd().
3. mytail.c: Write a program that prints out the last few lines of a file, à la tail. 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().
4. mytree.c: Write a recursive program that prints out the names of each file and directory in the file system tree, starting at a given point in the tree. For example, when run without arguments, the program should start with the current working directory and print its contents, as well as the contents of any sub-directories, etc., until the entire tree, root at the CWD, is printed. If given a single argument (of a directory name), use that as the root of the tree instead. Please make the output look like the example below.
Useful interfaces: you figure it out.
Example:
$ tar xvf p4-devjet.tar $ ls
makefile myls.c mystat.c mytail.c mytree.c $ make
gcc -o myls myls.c
gcc -o mystat mystat.c gcc -o mytail mytail.c gcc -o mytree mytree.c $ ls
makefile myls myls.c mystat mystat.c mytail mytail.c mytree mytree.c
$ ./mysearch /some-dir /some-dir
├── file1 ├── dir1
│ │ └──file2
· └──file3
├── dir3 [error opening dir] ├── dir4
├── file4
IMPORTANT NOTICE: You are expected to write your own code. Copying from the
Internet is not allowed. All programs will be checked for plagiarism. Submitting code that is not your own will result in a FF grade on the course.
Grading Rubric:
Each utility will be tested using automated scripts and by manual inspection. Therefore, it is important that tar file name and contents match structure described above and a makefile for easy compilation. Each program is worth 24% of the grade, and will be graded according to the following metrics.
|
Percentage(%) |
Rubric Comment |
|
2% |
General requirements (file names, tar file, directory structure) |
|
2% |
Compilation and execution (Makefile is present, code compiles and |
|
|
runs without errors). |
|
|
Makefile should contain clean scripts also. |
|
24% for each of |
[10%] I/O works as expected (e.g. stat must print file size, number |
|
stat, ls, tail and tree |
of blocks allocated, etc) |
|
|
[10%] Correct implementation (e.g.: use of APIs such as stat, |
|
|
opendir, lseek, etc) |
|
|
[4%] Programming style (code is organized and well-commented) |