Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program to calculate the total size of the files in a directory and the sub-directories of the directory. Detailed Requirements: 1. Name

Write a C program to calculate the total size of the files in a directory and the sub-directories of the directory.

Detailed Requirements:

1. Name the program in the pattern hw3_1.c. The grader may use a script to find and test your programs. The script will not find your program if the program has a different name.

2. Note that the total size should include the sizes of sub-directories (directories are also files), but not the size of the top-level directory.

When your program is run against the following directory tree (files are not included in the diagram): image text in transcribed

your program needs to add the sizes of the files under directories dir1, dir2, ..., dir13, and the sizes of directories dir2, dir3, ..., dir13.

3. If a file is a symbolic link, the symbolic link should not be dereferenced. So the size of the symbolic link is added to the total size, not the size of the file pointed by the link.

4. The pathname of the directory is specified in the command line. The format of the command for running the program is as follows (Important! If you don't follow strictly, the script testing your program may not be able to run your program correctly, and you may get lower grades).

./your_program pathname_of_directory

5. To facilitate testing, your program should print out ONLY the total size in bytes, i.e., ONE number, nothing else.

6. Test your program on one of the afs servers (afsN.njit.edu, where N is an integer from 1 to 36). Compile your program with gcc. Run the executable file obtained. Compare the result printed out by your program with the result obtained with command

du -abc pathname_of_directory

(look at the number printed out by du on the last line)

Grading:

1. The executable file can be successfully generated with gcc ---- +10 points

2. The program can finish within 3 minute without crash when it is run with the following command: ---- +10 points

./your_program /usr/share/man

3. Your program can print out correct result for a directory containing only regular files and NO symbolic links: ---- +20 points

4. Your program can print out correct result for a directory containing symbolic links and regular files: ---- +10 points

dir 1 dir 2 dir 3 dir 9 dir 8 dir 11 dir 12 dir 13 dir 1 dir 2 dir 3 dir 9 dir 8 dir 11 dir 12 dir 13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions