北美代写,美国作业代写,网课代修,Assignment代写-100%原创In addition to your code, you will submit a short response to a question about hard links. Please scroll down to the section about hard links for details.
Your program, fcopy, will copy the directory tree specified by the first command line argument to the destination specified by the second command line argument. For example, assume the following file tree:
===== . (755) ===== ===== dest (755) ===== fcopy (700) ===== test (755) ===== ===== subdir (755) ===== README (644)
The diagram above uses the format for displaying a file tree from the previous assignment. To reiterate, it represents a file tree starting in your current directory (.) The current directory contains a directory “dest”, an executable file “fcopy”, and a directory “test”. “test” contains a directory “subdir”. “subdir” contains a file “README”. “dest” is initially empty. After you execute fcopy test dest on the command line, you would get the following file tree:
===== . (755) ===== ===== dest (755) ===== ===== test (755) ===== ===== subdir (755) ===== README (644) fcopy (700) ===== test (755) ===== ===== subdir (755) ===== README (644)
As shown above, “test” and all of the files in its file tree have been copied to the destination “dest”. Furthermore, the contents of the files and the permissions on files and directories match.
In the example above, the destination is empty. What should occur if the destination is not empty? For example, what if we are dealing with this situation:
===== . (755) ===== ===== dest (755) ===== ===== test (755) ===== ===== subdir (755) ===== README (644) fcopy (700) ===== test (755) ===== ===== subdir (755) ===== README (640) ===== subdir2 (700) =====
In this case, if we were to execute fcopy test dest, the “dest” contains a number of the files we are attempting to copy. In this situation, your program should create any directories and files that are not present in the destination file tree, and it should overwrite any files that are present but that differ from the file in the source file tree. The resulting file tree would be:
===== . (755) ===== ===== dest (755) ===== ===== test (755) ===== ===== subdir (755) ===== README (640) ===== subdir2 (700) ===== fcopy (700) ===== test (755) ===== ===== subdir (755) ===== README (640) ===== subdir2 (700) =====
In particular, note that “subdir2” has been created in the correct place in the destination and that the permissions on the “README” file have been updated to match the permissions in the source. Furthermore, if the contents of “README” files were different, then the contents from the file in the source directory would be copied to the destination directory, overwriting the original file in the destination directory.
Files to Omit
Not all files should be copied. Since symbolic (soft) links often contain relative paths, they should not be copied. When a symbolic link is encountered, it should simply be skipped. Similarly, files beginning with a “.” should be skipped, as they were in assignment 2.
Copying files is an expensive operation, so we want to avoid copying files whenever possible. Instead of always overwriting normal files, your program should first check the size of the source and destination files. If the size differs, then a copy should be performed. If the sizes match, then a hash北美代写,美国作业代写,网课代修,Assignment代写-100%原创 should be computed on both the source and destination. If the hashes do not match, then the file should be copied. If they do match, then no copy should occur.
At this point, you should object: we’ve just replaced one expensive file operation with another. Instead of just copying the file, we’re reading both files (to compute the hash)! You’re correct that, for this program, nothing is gained. However, in the next assignment, you’ll be transferring files over the network, and we’ll want to avoid unnecessary file transfers. This feature is in preparation for that assignment.
Your program should use multiple processes to perform the file copy in parallel to (hopefully) speed up the task. Recall that in assignment 2, we used recursion to build the file tree structure; a recursive call was performed to build each individual tree node. In this assignment, you’ll fork a new process where you would have made a recursive call in assignment 2.
However, creating processes is expensive, so we don’t actually want to create a process for every file encountered. Instead, the current process should handle copying of regular files. A new process should be created only when you encounter a child directory. The new process will execute the recursive call that will create the child directory and copy any files in it.
For example, if we return to our original example:
===== . (755) ===== ===== dest (755) ===== fcopy (700) ===== test (755) ===== ===== subdir (755) ===== README (644)
Two processes would be used to perform the copy. The first process is the original one created when fcopy test dest is executed. It copies the directory “test”. The second process is created (using fork) to handle the copy of “subdir”. That second process also copies the contents of “subdir” — the file “README”. Here’s another example:
===== . (755) ===== ===== dest (755) ===== fcopy (700) ===== test (755) ===== output.log (644) ===== subdir (755) ===== README (644) ===== subsubdir(755) ===== ===== subdir2 (700) ===== temp.txt
北美代写,美国作业代写,网课代修,Assignment代写-100%原创In the example above, four total processes should be used to perform the copy (which means that your program will call fork three times). The original process will call fork twice (for “subdir” and “subdir2”), and it will also copy two regular files (“output.log” and “temp.txt”). It’s first child will call fork once and will copy a single regular file. The other two processes called will create the directories they are called on but have no additional work to perform.
Parent processes should wait for their children. We wait because we want to make sure that the copy is complete before returning control to the command line prompt. We also want to report on the number of processes used. When a child exits, the magnitude of its status code should reflect the number of processes required to perform the work. For example, if a child process does not execute a fork but successfully completes the copy, its exit status should be “1”. On the other hand, if a child process created three children of its own to complete the copy, its exit status should be “4”.
Error Checking and Reporting
北美代写,美国作业代写,网课代修,Assignment代写-100%原创While the magnitude of the status code (and the return value from the copy_ftree function) reflects the number of processes used to complete the copy, its sign indicates whether an error was encountered. If the copy was completed successfully, the process should return a positive number. If an error was encountered (by the process or any of its children), its status code should be negative.
As in assignment 2, you should check all of your system calls and use perror to emit an appropriate message if one fails. You may choose whether to terminate the process when an error is encountered or whether to attempt to continue. (For example, if chmod fails, you won’t be able to fully complete the copy, but you could choose to attempt to copy other files in the directory.) Regardless, the error should be reported.
北美代写,美国作业代写,网课代修,Assignment代写-100%原创There is one other situation which will cause an error. You may encounter a “mismatch” between the source and destination trees:
===== . (755) ===== ===== dest (755) ===== ===== test (755) ===== ===== subdir (755) ===== README (644) fcopy (700) test(644)
In this situation, if we were to execute fcopy test dest, we’d be attempting to copy a regular file into a destination where the name is already taken up by a directory. In this case (or the reverse, where a directory would be overwriting a regular file), the copy should not be attempted, and an error should be reported.
This assignment includes fairly minimal starter code. It consists of 4 files, which you need to download: The first is a . The second is the file , which provides the main function, and the other two are header files with function prototypes: and . You will need to add two source files of your own: hash_functions.c, which should contain a hash function, and ftree.c, which should contain your copy_ftree function. You may define other helper functions in these files, but the only required functions are the ones with prototypes in the provided header files.You should be able to reuse your hash function from assignment 2 without modification. You may also want to keep a copy of your generate_ftree function open as you code, as there may be snippets (like the code to get the permissions from a file) that you can reuse.Useful Syscalls
This assignment will require that you use some basic IO syscalls (fopen, fread, and fwrite, for example) to read and copy files. (Please use IO operations, rather than calling exec or a system command, to copy files.) You will also need to use some familiar file system syscalls like lstat, opendir, and readdir. You may also wish to use , , and . And, of course, you’ll need and .
So far, we’ve made no mention of hard links. Symbolic (soft) links are to be skipped, but can we detect hard links and , instead of creating duplicate files? The answer is “not easily.” Write a single paragraph (no more than 100 words) that explains why this design, which uses different processes to copy the contents of different directories, cannot easily detect hard links.
北美代写,美国作业代写,网课代修,Assignment代写-100%原创Place this response in the file README.txt. Your answer will be marked for correctness and clarity (including grammatical correctness and adherence to a formal — professional — style).
Submission and Marking
For this assignment you are allowed to work in teams of two students and a new repository will be created for each team. We have added A3 on Markus and configured it to allow you to form teams. If you log in to Markus and click on A3, you should see on the right side a window labelled “Group information” and under it a field “Form your own group”. You can choose to work alone (by clicking the corresponding tab) or click on “Create Group”, which will allow you to invite one other student to join your group. The person you invited needs to log in to Markus and accept your invite. After that Markus will create a new team repository and you should be able to see its URL when you log in to Markus. As for past exercises, it might take a little while before Markus creates the new repository. So give it a bit of time before searching for the URL.
Your submission should be committed to your svn repository by the due date. As before, we are using automated grading tools to provide functional feedback, so it’s important that your submission be in the correct location in your repository (under a3/), have the correct filenames (add ftree.c, hash_functions.c, and README.txt and don’t change other names), be fully submitted (remember to add files, and commit), compile cleanly, and produce output in exactly the format requested.
Your program must compile on the lab machines, so please test it there before submission. We will be using gcc to compile your program with the flags -Wall and -std=gnu99, as demonstrated in the Makefile. Your program should not produce any error or warning messages when compiled. As in assignments 1 and 2, programs that do not compile will receive a 0. Programs that produce warning messages will be penalized.