Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 3 : Directory Space Usage [ 4 0 points ] In this question, you have to write a program ( myDU . c )

Task 3: Directory Space Usage [40 points]
In this question, you have to write a program (myDU.c) that finds the space used by a directory (including its files, sub-directories, files in sub-directories, sub-sub directories etc.). Lets call this directory as
the Root directory.
Syntax
$./myDU
Example
Figure 3: Example to illustrate the use of directory space usage finding utility
Figure 3 shows the structure of a directory called Documents which is the designated Root directory
in this example. This directory contains files such as Bill_Payment.pdf, Experiment_Results.txt and
a sub-directory called Office. The Sub-directory 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
4
to print the total size of the contents of the passed root directory in bytes (For eg: 20284). Note that,
this is inclusive of directory sizes.
Output
Only print the size of the Root directory in bytes (Refer to Figure 3)
Detailed instructions
To make the calculation process more efficient, we propose a method where different sub-directories
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 sub-directories under the Root directory. For each immediate
child sub-directory under the provided Root directory, your program must create a new process
Pi (i will range from 1 to the total number of immediate sub-directories under Root). Each child
process Pi should find the size of the i
th child sub-directory (including all files and directories
under it and the size of the sub-directory 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 4: Sample directory structure
For example: In Figure 4, there are two immediate sub-directories (HTML, CSS) under the Root
directory (Tutorials). In this case, the parent process should create two child processes, say,
P1 and P2. P1 should calculate the size of the sub-directory (HTML) which is a sum of sizes
of all files and directories under HTML including the size of HTML itself. Similarly, P2 should
calculate size of the directory CSS. Both P1 and P2 should return the result back to the parent
using pipes. Finally, the parent process would find the size of the files immediately under it
(Payment_receipt.pdf, Description.txt) and the size of the Tutorials directory to report the
final result.
5
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 5: 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 file/directory pointed by a symbolic link instead of reporting the size of
the symbolic link file (Refer figure 5). It can be assumed that a symbolic link will never point to
itself recursively. For example, in Figure 5, Taxes22_23 directory will not contain a symbolic link
that points to the Taxes23_24 directory or directly to the Sym_link_to_Taxes22_23 symbolic file
in the Taxes23_24 directory.
It is the responsibility of the parent process to find the size of the file/directory pointed by a
symbolic link which is present immediately under Root directory. For example, in Figure 5 parent
process will not create any child process. However, if a symbolic link is present in a sub-directory,
it should be processed by the child process handling the sub-directory.
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 4096
characters.
You can assume that the total size of the Root directory will fit in a 8-byte integer type (i.e.,
unsigned long on 64-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
6
- pipe - stat
- opendir - lstat
- readdir - readlink
- closedir - strlen
- read - open
- write - close
- strcpy - strcat
- strcmp - strto* family
- ato* family - wait/waitpid
- printf family - exit
- dup - dup2
Testing
Refer to README document

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago