Project 3 -- POSIX Files, Directories, and Permissions

Due Thursday, November 8

(Note that the due date is the same as originally listed in the class schedule. I do not intend to move the due date off any, as you will need time to work on Project 4 after you complete Project 3. This means that if you have conflicts with other courses, such as exams or assignments for those courses, you should get an early start on Project 3 and have it done early, rather than hoping to get an extension.)

NOTE: This assignment, like the other projects in this class, is due at the beginning of the class period. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.

Have you ever wished that you had the latest versions of your files available and hated having to search around for which ones were newer? Have you ever needed to "synchronize" the data on your palmtop with that on your laptop, or the data on your laptop with that on your desktop machine?

For this assignment, you will create a file and directory synchronization utility. It won't work between different machines using different file systems, because we haven't covered how to do interprocess communication between machines using different file systems yet, but it will work between different directories on the same file system. Further, you will expand your program to make it possible for different users, working together in a team, to synchronize their files and directories.



The Assignment

For this assignment, you will create two file system synchronization utility programs. The first will be called fssync for "file system synchronization." It will be used to synchronize files and directories belonging to a single user. The second will be called teamsync. It will be used to synchronize files and directories belonging to a different users who are members of the same team.

fssync

The fssync utility will work as follows:

teamsync

The teamsync utility will work like the fssync utility, with one important difference. Whereas fssync will only work for files and directories that its user can access (read, write, or execute as necessary), teamsync will work for files that either the user or the user's teammates can access. This will work as follows:

flags

Both fssync and teamsync will take the following flags from the command line and interpret them as follows.

-q
Quietly run so as not to print any of the messages specified above.


-r
Recursively descend the file tree from the starting directories, synchronizing all directories and files below. (This flag has no effect if two files are specified, rather than two directories.)


-c
Confirm before overwriting an existing file. With this flag set, fssync and teamsync will prompt the user with the message "<pathname> exists, overwrite? (y/n/x)" (where <pathname> is the path name of the file to be overwritten). If the user answers "y" (or "Y"), then the file will be overwritten and the program will proceed as normal. If the user answers "n" (or "N"), then the file will not be overwritten and the program will proceed as normal. If the user answers "x" (or "X"), then the file will not be overwritten and the program will exit.


-i
Interactively verify prior to copying any file, regardless of whether that action will overwrite an existing file or create a new file. With this flag set, fssync and teamsync will prompt the user as above for the -c flag for overwriting or with the message "Create <pathname>? (y/n/x)" for creating a new file (where <pathname> is the name that the file will be copied to). If the user answers "y" (or "Y"), then the file will be copied and the program will proceed as normal. If the user answers "n" (or "N"), then the file will not be copied and the program will proceed as normal. If the user answers "x" (or "X"), then the file will not be copied and the program will exit.
These flags can be combined in a single command line. For example, as user could type
    % fssync -r -q -c -i /home/name4567/dir1 /home/name4567/dir2
which would quitely, recursively, and interactively invoke fssync. (Note that specifying both -c and -i is redundant, as -i encompasses all of the behavior of -c and then some.)

Notes on this assignment

All copying of files in this assignment will use the POSIX system calls open, close, read, write. You will not be using the link system call in this assignment.

All messages printed by fssync and teamsync will be printed to the standard out.

Both fssync and teamsync will ignore (neither copy nor follow) symbolic links.

If fssync or teamsync are improperly invoked (with too few command line arguments, one directory and one file, unknown flags, etc.), the program should print an error message and exit.

What to turn in.

You will turn in both a hard copy and an electronic copy of your assignment. You will be given instructions on how to send electronic copies. Do not send them to me though email.

Both the hard copy and the electronic copy will contain a write-up and all source code for both fssync and teamsync. The electronic copy will also contain the executable of both fssync and teamsync. The electronic copy of your write-up should not be in a proprietary format (such as MS Word); it should be either in plain ASCII text or in a portable format (such as Postscript or PDF). Your source code should either be in a single file for each program, called fssync.c and teamsync.c, respectively, or in several files that can be compiled and linked using make. In the latter case, fssync.c and teamsync.c (or fssync.cxx and teamsync.cxx) will contain the function main() and you will include your makefile and it will be named makefile. The executables generated by your makefile should be called fssync and teamsync.

Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).

Your write-up will contain 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)

Your write-up will also contain a "man page" entry for fssync and teamsync. This will not be a real manual page entry that can be displayed using the "man" command but will be a text file that roughly follows the format of a man page and describes these utilities.



Other

You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original, which are changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.

As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.