操作系统的初学者，如有疏漏或错误，欢迎指正 (^ _ ^)
5.Systems that support sequential files always have an operation to rewind files. Do systems that support random-access files need this, too?
No. If you want to read the file again, just randomly access byte 0.
6.Some operating systems provide a system call rename to give a file a new name. Is there any difference at all between using this call to rename a file and just copying the file to a new file with the new name, followed by deleting the old one?
Yes. The rename call does not change the creation time or the time of last modification, but creating a new file causes it to get the current time as both the creation time and the time of last modification. Also, if the disk is full, the copy might fail.
8.A simple operating system supports only a single directory but allows it to have arbitrarily many files with arbitrarily long file names. Can something approximating a hier- archical file system be simulated? How?
Use file name such as /usr/ast/file. While it looks like a hierarchical path name, it is really just a single name containing embedded slashes.
35.Consider a disk that has 10 data blocks starting from block 14 through 23. Let there be 2 files on the disk: f1 and f2. The directory structure lists that the first data blocks of f1 and f2 are respectively 22 and 16. Given the FAT table entries as below, what are the data blocks allotted to f1 and f2?
(14,18);(15,17); (16,23); (17,21); (18,20); (19,15); (20, −1); (21, −1);(22,19); (23,14). In the above notation, (x, y) indicates that the value stored in table entry x points to data block y.
37.A certain file system uses 4-KB disk blocks. The median file size is 1 KB. If all files were exactly 1 KB, what fraction of the disk space would be wasted? Do you think the wastage for a real file system will be higher than this number or lower than it? Explain your answer.
The fraction of the wasted disk space is:1KB/2KB*100%=50%
In practice, every file system has large files as well as many small ones, and these files use the disk much more efficiently. For example, a 32769-byte file would use 17 disk blocks for storage, given a space efficiency of 32768/34861, which is about 94%.
41.How many disk operations are needed to fetch the i-node for a file with the path name /usr/ast/courses/os/handout.t? Assume that the i-node for the root directory is in memory, but nothing else along the path is in memory. Also assume that all directories fit in one disk block.
The following disk reads are needed:
- directory for /
- i-node for /usr
- directory for /usr
- i-node for /usr/ast
- directory for /usr/ast
- i-node for /usr/ast/course
- directory for /usr/course
- i-node for /usr/ast/course/os
- directory for /usr/course/os
- i-node for /usr/ast/course/os/handout.t
In total, 10 disk reads are required.