
CS485G Spring 2015 54
closedir(). readdir() returns a struct dirent pointer, which
includes the name of the file.
5. Directories associate file names with inode numbers, which uniquely
index the on-disk metadata for each file.
(a) Multiple directories can point to the same inode, in which case
a single file might have multiple path names.
(b) The on-disk inode includes a count of how many directories
point to it.
(c) The ln command introduces such a link between two files.
(d) To remove a name from a directory, use the unlink() system
call.
(e) When the last reference to a file is removed, the kernel can re-
claim the file’s allocated space on the disk.
6. Each open file includes a file position indicator for each open file; it
is advanced by read() and write() and a program can modify it
with lseek().
7. Lecture 30, 4/15/2015
8. Multiple processes may have the same file open.
(a) If they opened the file independently, each has its own file po-
sition.
(b) If they received the file descriptor by inheritance, they share the
file position.
9. The standard I/O library (#include <stdio.h>) provides buffered
versions of input and output.
(a) Instead of file descriptors (small integers), it uses pointers to a
FILE structure.
(b) It predefines stdin, stdout, stderr.
(c) It only submits a system call when a buffer is full (output) or
empty (input) or if there is an explicit request to fflush().
10. Choosing which calls to use in the program (low-level, stdio, or Rio):
(a) low-level: most general, lowest overhead per call, can access
file metadata, async-signal-safe (so they can be used in signal
handlers). But dealing with short counts is tricky, and I/O is
unbuffered, leading to multiple system calls.
Comentarios a estos manuales