CS485G Spring 2015 53
(a) Read: reached the end of file, or the end of a line with fgets().
(b) Network sockets or pipes: read or write can give a short count.
(c) Never from writing files.
(d) The Rio (robust I/O) package from csapp.c handles short counts
and retries.
3. File metadata: data about the file, but not the contents.
(a) Maintained by the kernel in its data structures.
(b) A program can get some of it with stat() or fstat():
1 struct stat {
2 dev_t st_dev;
/
*
ID of device containing file
*
/
3 ino_t st_ino;
/
*
inode number
*
/
4 mode_t st_mode;
/
*
protection and file type
*
/
5 nlink_t st_nlink;
/
*
number of hard links
*
/
6 uid_t st_uid;
/
*
user ID of owner
*
/
7 gid_t st_gid;
/
*
group ID of owner
*
/
8 dev_t st_rdev;
/
*
device ID (if special file)
*
/
9 off_t st_size;
/
*
total size, in bytes
*
/
10 blksize_t st_blksize; /
*
blocksize for filesystem I/O
*
/
11 blkcnt_t st_blocks;
/
*
number of 512B blocks allocated
*
/
12 time_t st_atime;
/
*
time of last access
*
/
13 time_t st_mtime;
/
*
time of last modification
*
/
14 time_t st_ctime;
/
*
time of last status change
*
/
15 };
4. Directories used to be just files with a special format, but now one
reads them with different system calls: opendir(), readdir(),
Comentarios a estos manuales