Question: Functional requirements In this assignment you will create a program capable of archiving the contents of a directory into a single file, much like tar
Functional requirements
In this assignment you will create a program capable of archiving the contents of a directory into a single file, much like tar does. You will write a makefile that compiles your program into an executable named arch, which has usage
arch
| action | -c to create a new archive file -e to expand an existing archive file |
| source | Specifies the path-name of a directory that contains the files to be archived (-c) or of the archive file (-e) being expanded. |
| target | Specifies the path-name of the archive file that is to be created (-e) or of the directory to be created to hold the contents of the archive file. |
Based on the command line arguments does one of the following:
Create: Create a new archive file (target) that, for each file in the directory specified by source, contains the data required to restore the file's name and data. The source directory is unchanged.
Expand: Create a new directory (target), which will contain all of the files and directories in the archive file, in their directory structure
Recurse the entire sub-tree rooted by (source) on create or expand
Proper care (error reporting / program termination) when opening and creating files and directories is required.
Sample Runs:
% ./arch -c . my_archive
archiving .
Done my_archive as been created
% ./arch -e ./expand_test my_archive
expanding to ./expand_test
Done my_archive as been expanded
Non-functional requirements
You must use basic POSIX I/O to implement both create and expand. You may not use the system() system call. You must implement functions for create and expand--it probably makes most sense to have one recursive function and one function that actually writes to the file for each command. These functions should have their own .c and .c files, while the application should be in main.c.
Archive file format
Each file will be saved in consecutive bytes in the archive file as
pathname size: a 4 byte unsigned integer
data size: a 4 byte unsigned integer
pathname: ASCII string containing the relative path from the source directory to the file; it is not null terminated
data: the contents of the file
Files may be stored in any order.
So when expanding a file you will need to repeatedly:
Read the first 4 bytes, treat it as an unsigned int, this is the pathname size
Read the next 4 bytes as an unsigned int; this is the data size
Read the pathname into a buffer of exactly the right size
Using the pathname, open a file for writing; you may need to create directories first
Repeatedly read from the archive into a buffer and write the data to the new file
Empty directories
The scheme described above does not allow for empty directories, as only files are stored. A special file entry is used to force the creation of an empty directory. If a file's pathname begins with a "!", no file is created. Instead the archiver simply ensures all of the directories in the path (ignoring the leading !) have been created. When creating an archive, the archiver writes one such entry for each empty directory.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
