Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 3 : Directory Space Usage [ 4 0 points ] In this question, you have to write a program ( myDU . c )
Task : Directory Space Usage points
In this question, you have to write a program myDUc that finds the space used by a directory including its files, subdirectories, files in subdirectories, subsub directories etc. Lets call this directory as
the Root directory.
Syntax
$myDU
Example
Figure : Example to illustrate the use of directory space usage finding utility
Figure shows the structure of a directory called Documents which is the designated Root directory
in this example. This directory contains files such as BillPayment.pdf ExperimentResults.txt and
a subdirectory called Office. The Subdirectory Office contains a file named Deals.ppt To find the
size of the Documents directory, its name is passed as $myDU Documents. Your utility is expected
to print the total size of the contents of the passed root directory in bytes For eg: Note that,
this is inclusive of directory sizes.
Output
Only print the size of the Root directory in bytes Refer to Figure
Detailed instructions
To make the calculation process more efficient, we propose a method where different subdirectories
under the Root directory will be processed by different processes. The exact working is detailed in the
following points.
Assume that there are N immediate subdirectories under the Root directory. For each immediate
child subdirectory under the provided Root directory, your program must create a new process
Pi i will range from to the total number of immediate subdirectories under Root Each child
process Pi should find the size of the i
th child subdirectory including all files and directories
under it and the size of the subdirectory itself and pass this information back to the parent
process. Parent process should find the size of the files immediately under it along with the Root
directory size. Finally, parent process will find the sum of all sizes and print the final output.
Figure : Sample directory structure
For example: In Figure there are two immediate subdirectories HTML CSS under the Root
directory Tutorials In this case, the parent process should create two child processes, say,
P and P P should calculate the size of the subdirectory HTML which is a sum of sizes
of all files and directories under HTML including the size of HTML itself. Similarly, P should
calculate size of the directory CSS Both P and P should return the result back to the parent
using pipes. Finally, the parent process would find the size of the files immediately under it
Paymentreceipt.pdf Description.txt and the size of the Tutorials directory to report the
final result.
Your program should only use pipes pipe system call to communicate between parent process
and the child processes. There is no restriction on the number of pipes to be used.
Figure : Example to illustrate the handling of symbolic links by myDU utility
A symbolic link is a special type of file in Linux that points to another file or directory. Symbolic
links can be present anywhere in the Root directory tree. You should resolve the symbolic links
and find the size of the filedirectory pointed by a symbolic link instead of reporting the size of
the symbolic link file Refer figure It can be assumed that a symbolic link will never point to
itself recursively. For example, in Figure Taxes directory will not contain a symbolic link
that points to the Taxes directory or directly to the SymlinktoTaxes symbolic file
in the Taxes directory.
It is the responsibility of the parent process to find the size of the filedirectory pointed by a
symbolic link which is present immediately under Root directory. For example, in Figure parent
process will not create any child process. However, if a symbolic link is present in a subdirectory,
it should be processed by the child process handling the subdirectory.
During testing, only relative path of the Root directory will be passed to the myDU utility. It
can be assumed that the size of the directory path generated during testing will not exceed
characters.
You can assume that the total size of the Root directory will fit in a byte integer type ie
unsigned long on bit machines
Error handling
In case of any error, print Unable to execute as output.
System calls and library functions allowed
fork malloc
exec family free
pipe stat
opendir lstat
readdir readlink
closedir strlen
read open
write close
strcpy strcat
strcmp strto family
ato family waitwaitpid
printf family exit
dup dup
Testing
Refer to README document
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started