In this assignment we enhance Assignment 1 so that information about the files in a directory can be transmitted to another process on the same machine.
In a later assignment this information will be transmitted over a network to a process on another machine.
Each time you start a new part of this assignment, create a new directory. When you are finished, you should have an assign3 directory with subdirectories part0, part1, part2, part3, part4 and part5. When creating one of these directories, start by copying into it the contents of the previous directory. Each time you write a main program, use lint and make sure you understand all of the warning messages.
Part 0:
Make sure you have Parts 2 and 3 of Assignment 1 working.
The serialize function should send only the information indicated. For example, if the path is abc/def, the size is 123 bytes and the modification time in seconds since the Epoch is 123456789, the output should be:
abc/def 123 123456789This is a total of 22 bytes that are sent including the three newline characters.
The serialize and deserialize functions should be in the file utility.c.
Part 1:
Write a main program called FIFO_server.c that takes two command
line arguments, the names of existing FIFOs.
It opens both FIFOs for read-write.
If an error occurs before this point, the program exits with an appropriate
error message. Otherwise the program does not exit
(unless it receives a signal).
The two command line arguments will be referred to as toServer and fromServer. The program reads lines from toServer (use readline from restart.c) and uses each line read as the last parameter (without the newline) to serialize. If serialize reports an error, do nothing. Otherwise, the information generated by serialize is sent over the pipe fromServer.
Part 2:
Write functions int isdirectory(char *path) and
int isregular(char *path) that return 1 if the corresponding
path is respectively a directory or a regular file. Otherwise these functions
return 0. Use the S_ISDIR and S_ISREG macros.
Put these functions in Utility.c. Example 5.10 from USP already
has an appropriate isdirectory function that you can use.
Part 3
Write a main program called FIFO_client that takes three command line
parameters, the names of two existing FIFOs, toServer and
fromServer, and a path. It opens both FIFOs for
read-write, sends and line containing the third command line parameter to
the toServer FIFO (remember to include the newline)
and reads 3 lines from the fromServer FIFO.
It displays (to standard output) the information received,
and looks for a local file with the name
it received form the fromServer FIFO (the first line).
It outputs one additional line (to standard output) based on the
comparison of the local file to the information it receives from the
fromServer FIFO as follows:
Part 4
Rewrite FIFO_server.c so that if the line read corresponds to
a directory, it sends information about each regular file in that directory.
If the line read does not correspond to a directory, it behaves as before.
In either case, after it has sent all of its information it sends an empty line.
An empty line just contains a newline character.
If serialize reports an error, just send the empty line.
Part 5
Modify the FIFO_client from Part 3 so that it keeps reading and processing
groups of 3 lines until an empty line is found.
Test your programs from Parts 4 and 5 together. Run the client and server
from different directories (but be sure they both use the same FIFOs).
Create directories for testing that contain files that satisfy all three of
the possibilities listed in Part 3. The directory from which the server is run
should also have some files that aren't regular files or directories.
Handing in your program:
Use this cover sheet. Consecutively number all of
the other pages you turn in. Each page that contains your work should have
a number on it. Turn this in at the beginning of lecture on the due date.
For the tests of Part 5, execute ls -l in each of the directories
that the client and server run in. Run the client with path parameter
".". Turn in the output from running the client along with the
two directory listings. Make sure everything is clearly labeled.
If you do not have Parts 4 and 5 working, you must submit to me additional information that indicates what progress you made on this assignment and what tests were run.