Description
In this project, you are required
to write a Unix/C program myfind to find a file (find_file)
under a directory (search_dir ). The syntax of myfind is
myfind search_dir find_file
Note that the find_file itself cound be a directory. The exact location of search_file can be generalized as "search_dir/dir1/dir2/....../dirn/find_file", where n is an non-negative integer. If more than one find_files exist, myfind should return the one with a lowest n.
If find_file exists, the standard output of your program should give the detailed information of this file, with the following format:
location
file
modes
file size
link
count
search_dir/dir1/dir2/....../dirn/find_file drwx------
4096 1
and a subsequent "echo $?" after executing myfind should return 0.
If the file does not exist, there should be no output and a subsequent "echo $?" after executing myfind should return 1.
If the permission of search_dir, diri, or find_file does not allow the command to complete, there should be no output and a subsequent "echo $?" after executing myfind should return 2. And the program should print out "permission denied: search_dir/dir1/dir2/....../diri[/find_file]" on the standard error output, where diri or find_file is the first blocking node along the search.
Furthermore, in this project, a directory of search_dir or diri (i=1, 2, ... n-1) along the search path is defined to be an ambiguous node if it has more than one child directories. If so, no matter whether find_file exists or not, there should be no standard output and a subsequent "echo $?" after executing myfind should return 3. And the program should print out "ambiguous: search_dir/dir1/dir2/....../diri" on the standard error output, where diri is the first ambiguous node along the search. That is, the program stops searching when it encounters a "subdirectory fork".
Submission
Grading
Test Script
p4_a --- 1 --- 2 --- 3 --- 4
|
file
p4_b --- 1 --- 2 (unreadable)
p4_c --- 1 --- 2 --- 3 --- 4.1
| |
file2
4.2