• 沒有找到結果。

File-System Interface

在文檔中 OPERATING SYSTEM CONCEPTS (頁 53-61)

48 Chapter 11 File-System Interface

11.2 Some systems automatically delete all user files when a user logs off or a job terminates, unless the user explicitly requests that they be kept; other systems keep all files unless the user explicitly deletes them. Discuss the relative merits of each approach.

Answer: Deleting all files not specifically saved by the user has the advantage of mini-mizing the file space needed for each user by not saving unwanted or unnecessary files.

Saving all files unless specifically deleted is more secure for the user in that it is not pos-sible to inadvertently lose files by forgetting to save them.

11.3 Why do some systems keep track of the type of a file, while others leave it to the user or simply do not implement multiple file types? Which system is “better?”

Answer: Some systems allow different file operations based on the type of the file (for instance, an ascii file can be read as a stream while a database file can be read via an index to a block). Other systems leave such interpretation of a file’s data to the process and provide no help in accessing the data. The method which is “better” depends on the needs of the processes on the system, and the demands the users place on the operating system. If a system runs mostly database applications, it may be more efficient for the operating system to implement a database-type file and provide operations, rather than making each program implement the same thing (possibly in different ways). For general purpose systems it may be better to only implement basic file types to keep the operating system size smaller and allow maximum freedom to the processes on the system.

11.4 Similarly, some systems support many types of structures for a file’s data, while others simply support a stream of bytes. What are the advantages and disadvantages?

Answer: (See 10.3)

11.5 What are the advantages and disadvantages of recording the name of the creating pro-gram with the file’s attributes (as is done in the Macintosh Operating System)?

Answer: By recording the name of the creating program, the operating system is able to implement features (such as automatic program invocation when the file is accessed) based on this information. It does add overhead in the operating system and require space in the file descriptor, however.

11.6 Could you simulate a multilevel directory structure with a single-level directory structure in which arbitrarily long names can be used? If your answer is yes, explain how you can do so, and contrast this scheme with the multilevel directory scheme. If your answer is no, explain what prevents your simulation’s success. How would your answer change if file names were limited to seven characters?

Answer: If arbitrarily long names can be used then it is possible to simulate a multilevel directory structure. This can be done, for example, by using the character “.” to indicate the end of a subdirectory. Thus, for example, the name jim.pascal.F1 specifies that F1 is a file in subdirectory pascal which in turn is in the root directory jim.

If file names were limited to seven characters, then the above scheme could not be utilized and thus, in general, the answer is no. The next best approach in this situation would be to use a specific file as a symbol table (directory) to map arbitrarily long names (such as jim.pascal.F1) into shorter arbitrary names (such as XX00743), which are then used for actual file access.

11.7 Explain the purpose of theopenandcloseoperations.

Answer:

 The open operation informs the system that the named file is about to become active.

 The close operation informs the system that the named file is no longer in active use by the user who issued the close operation.

Answers to Exercises 49

11.8 Some systems automatically open a file when it is referenced for the first time, and close the file when the job terminates. Discuss the advantages and disadvantages of this scheme as compared to the more traditional one, where the user has to open and close the file explicitly.

Answer: Automatic opening and closing of files relieves the user from the invocation of these functions, and thus makes it more convenient to the user; however, it requires more overhead than the case where explicit opening and closing is required.

11.9 Give an example of an application in which data in a file should be accessed in the fol-lowing order:

a. Sequentially b. Randomly Answer:

a. Print the content of the file.

b. Print the content of record i. This record can be found using hashing or index tech-niques.

11.10 Some systems provide file sharing by maintaining a single copy of a file; other systems maintain several copies, one for each of the users sharing the file. Discuss the relative merits of each approach.

Answer: With a single copy, several concurrent updates to a file may result in user obtaining incorrect information, and the file being left in an incorrect state. With multiple copies, there is storage waste and the various copies may not be consistent with respect to each other.

11.11 In some systems, a subdirectory can be read and written by an authorized user, just as ordinary files can be.

a. Describe the protection problems that could arise.

b. Suggest a scheme for dealing with each of the protection problems you named in part a.

Answer:

a. One piece of information kept in a directory entry is file location. If a user could modify this location, then he could access other files defeating the access-protection scheme.

b. Do not allow the user to directly write onto the subdirectory. Rather, provide system operations to do so.

11.12 Consider a system that supports 5000 users. Suppose that you want to allow 4990 of these users to be able to access one file.

a. How would you specify this protection scheme inUNIX?

b. Could you suggest another protection scheme that can be used more effectively for this purpose than the scheme provided byUNIX?

Answer:

a. There are two methods for achieving this:

50 Chapter 11 File-System Interface

i. Create an access control list with the names of all 4990 users.

ii. Put these 4990 users in one group and set the group access accordingly. This scheme cannot always be implemented since user groups are restricted by the system.

b. The universe access information applies to all users unless their name appears in the access-control list with different access permission. With this scheme you simply put the names of the remaining ten users in the access control list but with no access privileges allowed.

11.13 Researchers have suggested that, instead of having an access list associated with each file (specifying which users can access the file, and how), we should have a user control list associated with each user (specifying which files a user can access, and how). Discuss the relative merits of these two schemes.

Answer:

 File control list. Since the access control information is concentrated in one single place, it is easier to change access control information and this requires less space.

 User control list. This requires less overhead when opening a file.

Review Questions 51

Review Questions

11.1 What is a file?

Answer: A named collection of related data defined by the creator, recorded on sec-ondary storage.

11.2 List sample file types, based on use, on theVAXunderVMS. Answer:

 source programs (.BAS, .FOR, .COB, .PLI, .PAS, .MAR)

 data files (.DAT)

 text files (.TXT)

 command procedures (.COM)

 mail files (.MAI)

 compiler-listing files (.LIS, .LST)

 object files (.OBJ)

 executable image files (.EXE)

 journal files (.JOU)

11.3 List some file types on theVAXunderVMS. Answer:

 source-language for programs (.BAS, .COB, .FOR, .MAR, .PAS, .PLI, ...)

 binary language (.OBJ, .EXE)

 ASCIIcode (.TXT)

 mail format (.MAI) 11.4 What doesOPENdo?

Answer: Creates memory buffers, creates data control blocks, and creates other data structures needed for theI/O. If file is new, it also allocates space, and enters name in directory.

11.5 What doesCLOSEdo?

Answer: Outputs last buffer of information. Deletes buffers, data control blocks, and other data structures.

11.6 List advantages of operating system “knowing” and supporting many file types.

Answer: Can prevent user from making ridiculous mistakes. Can make system conve-nient to use by automatically doing various jobs after one command.

11.7 List the disadvantages of operating system “knowing” and supporting many file types.

Answer: Size of operating system becomes large. Every file type allowed must be de-fined, thus hinders in creating new file types.

11.8 What is a sequential file?

Answer: A file that is read one record or block or parameter at a time in order, based on a tape model of a file.

52 Chapter 11 File-System Interface

11.9 What is direct access?

Answer: A file in which any record or block can be read next. Usually the blocks are fixed length.

11.10 How does user specify block to be fetched in direct access?

Answer: By specifying the relative block number, relative to first block in file, which is block 0.

11.11 Can a direct access file be read sequentially? Explain.

Answer: Yes. Keep a counter, cp, initially set to 0. After reading record cp, increment cp.

11.12 How can an index file be used to speed up the access in direct-access files?

Answer: Have an index in memory; the index gives the key and the disk location of its corresponding record. Scan the index to find the record you want, and then access it directly.

11.13 Explain whatISAMis.

Answer: Indexed sequential access method. The file is stored in sorted order. ISAMhas a master index file, indicating in what part of another index file the key you want is; the secondary index points to the file records. In both cases, a binary search is used to locate a record.

11.14 List two types of system directories Answer:

a. Device directory, describing physical properties of files.

b. File directory, giving logical properties of the files.

11.15 List operations to be performed on directories.

Answer: Search for a file, create a file, delete a file, list a directory, rename a file, traverse the file system.

11.16 List disadvantages of using a single directory.

Answer: Users have no privacy. Users must be careful in choosing file names, to avoid names used by others. Users may destroy each others’ work.

11.17 What is theMFD?UFD? How are they related?

Answer: MFDis master-file directory, which points to theUFDs.UFDis user-file directory, which points to each of user’s files.

11.18 What advantages are there to this two-level directory?

Answer: Users are isolated from each other. Users have more freedom in choosing file names.

11.19 What disadvantages are there to this two-level directory?

Answer: Without other provisions, two users who want to cooperate with each other are hampered in reaching each other’s files, and system files are inaccessible.

11.20 How do we overcome the disadvantages of the two-level directory?

Answer: Provide links from one user directory to another, creating path names; system files become available by letting the command interpreter search your directory first, and then the system directory if file needed is not in first directory.

Review Questions 53

11.21 What is a file path name?

Answer: A list of the directories, subdirectories, and files we must traverse to reach a file from the root directory.

11.22 If we use the two-level directory, how do we access common files and programs, like FORTRANcompiler? Show two or more ways.

Answer:

a. Keep copy of each common file in each user account.

b. Keep common files in a special account of system files, and translate the commands to path names to those files.

c. Permit path names from one directory to another.

11.23 Why would we want a subdirectory in our account?

Answer: To group files into collections of similar nature, and to protect certain groups of files from other users.

11.24 List steps you need to follow to delete a subdirectory in your account.

Answer: Delete all files in subdirectory. Change protection code to allow deletion, and then delete the subdirectory. This procedure must be followed, starting with the deepest subdirectory.

11.25 What is an acyclic graph?

Answer: A tree that has been corrupted by links to other branches, but does not have any cyclic paths in it.

11.26 List ways to share files between directories in operating systems.

Answer:

a. Copy file from one account into another.

b. Link directory entry of “copied” file to directory entry of original file.

c. Copy directory entry of file into account file is “copied” into.

11.27 What problems might arise on deletion if a file is shared?

Answer: Copier of file might delete the original shared file, depriving rest of users. They have a pointer to a deleted directory entry pointing to the original file or one overwritten by other users of the system, or a new entry pointing to a new file created by the original user.

11.28 How can we solve this problem?

Answer: Keep a count of the number of links to a file in original directory. As each person deletes a file, the count decreases by 1.

11.29 What is a general graph?

Answer: A tree structure where links can go from one branch to a node earlier in the same branch or other branch, allowing cycles.

11.30 What problems arise if the directory structure is a general graph?

Answer: Searching for a particular file may result in searching the same directory many times. Deletion of the file may result in the reference count to be nonzero even when no directories point to that file.

54 Chapter 11 File-System Interface

11.31 What is garbage collection?

Answer: Determining what file space is available, and making it available for users.

(Note: garbage collection is also done inBASIC, to reclaim space used by deleted strings.) 11.32 How can we protect files on a single-user system?

Answer:

a. Hide the disks.

b. Use file names that can’t be read.

c. Backup disks.

d. On floppies, place a write-disable-tab on.

11.33 What might damage files?

Answer: Hardware errors, power surges, power failures, disk-head crashes (read/write head scraping magnetic material off disk), dirt, temperature, humidity, software bugs, fingerprints on magnetic material, bent disk or cover, vandalism by other users, storing diskettes near strong magnets which are found inCRTs, radio speakers, and so on.

11.34 List kinds of access we might want to limit on a multiuser system.

Answer: Reading files in given account; creating, writing, or modifying files in given account; executing files in given account; deleting files in given account.

11.35 List four ways systems might provide for users to protect their files against other users.

Answer:

a. Allowing user to use unprintable characters in naming files so other users can’t de-termine the complete name.

b. Assigning password(s) to each file that must be given before access is allowed.

c. Assigning an access list, listing everyone who is allowed to use each file.

d. Assigning protection codes to each file, classifying users as system, owner, group, and world (everyone else).

在文檔中 OPERATING SYSTEM CONCEPTS (頁 53-61)