Grading scheme for this homework: This homework, to be completed on CONSIDER, will be worth 15 points. Your individual score will be determined as follows: a. Completing the initial submission and the other activities by the respective deadlines: 2 points. b. Effectiveness of participation in the two "discussion" rounds: 3 pts c. Correctness of your (individual) final answer: 5 pts d. Quality of your (individual) summary of the discussion in your group: 5 pts ============== Here is the problem: As we saw in class, C and Unix have a very uniform view of files and directories. In fact, in initial versions of C/Unix, the same commands/functions were used to manipulate "regular" files and directories. This is a 2-part question: a. It turns out that while adopting a uniform view of files and directories was a good idea, using the same functions to manipulate both kinds of files was *not* a good idea. Briefly explain why. b. Hence new functions such as opendir(), readdir(), and closedir() were introduced. But no function, such as writedir(), analogous to the write() function for normal files, was introduced. Why not? Briefly explain why. Fun (extra) activity: Read and (try to!) understand this page: http://docstore.mik.ua/orelly/linux/run/ch06_03.htm ============== Answers: a. First, adopting a uniform view of files and directories was sensible because the information that needed to be in a directory could all be stored as plain text although carefully structured, hence the struct definitions in Section 8.6 of the book. At the same time, using the same functions to manipulate directories as the ones intended for manipulating arbitrary files is asking for trouble because if there is (deliberate or accidental) misuse, then the information in the directory could be seriously compromised since a directory contains information about *all* the files (*and*, recursively, all the directories) in the directory including information about *where* the file is! So any improper change in the directory could, e.g., make it impossible to access those files. b. Because a directory should be modified when changes are made to the files in the directory. For example, if a new file ff is created in a given directory D, an appropriate entry should be *automatically* added to D corresponding to ff, rather than by calling a function such as writedir() to modify D. Otherwise, we will again have the same problem as above, i.e., new stuff may be written into D that is inconsistent with the files that we have in the directory.