您的位置:首页 > 其它

file descriptor(文件描述符) & file descriptor flags(文件描述符标志) & file status flags(文件状态标志)

2015-09-22 18:47 1001 查看
在阅读Stevens的大作<<Advanced Programming in the UNIX® Environment>> ,简称为<<APUE>>时,在第三章中出现了三个英文词,file descriptor,file descriptor flags,file status flags,即所谓的”文件描述符“,"文件描述符标志", "file status flags",这三个概念在使用fcntl函数时必须要区别清楚。下面就从字面上来解释下:

1)file descriptor(文件描述符):是文件的一个标识,常使用整数标识。内核使用该标识跟踪你在程序中打开的文件;

2)file descriptor flags(文件描述符标志):从字面上来理解,就是描述符的一个标志,目前Unix,Unix-like和Linux中只有一个值:close-on-exec,用FD_CLOEXEC来表示。

3)file status flags(文件状态标志):从字面上来理解,就是用来描述文件状态的一个标志,根据理解,我把此类标志分为三个部分:

a)文件访问性状态标志:O_RDONLY,O_WRONLY,O_RDWR;

b)文件创建性状态标志:O_CREAT,O_EXCL, O_NOCTTY,O_TRUNC,O_APPEND;

c)文件异步/同步标志:O_NONBLOCK, O_SYNC, O_DSYNC, O_RSYNC, O_FSYNC, and O_ASYNC

在<<APUE>>中,使用三种数据结构来描述打开的文件:

1)进程表项,是一个进程表的一行。文件描述符和文件描述符标志存在于这个结构中。

2)文件表,文件状态标志存在于这个结构中。

3)i-node/v-node节点

下面给出具体的英文描述和一张图表:

The kernel uses three data structures to represent an open file, and the relationships among them determine the effect one process has on another with regard to file sharing.

1)Every process has an entry in the process table. Within each process table entry is a table of open file descriptors, which we can think of as a vector, with one entry per descriptor. Associated with each file descriptor are

a)The file descriptor flags.

b)A pointer to a file table entry.

2)The kernel maintains a file table for all open files. Each file table entry contains

a)The file status flags for the file, such as read, write, append, sync, and nonblocking.

b)The current file offset.

c)A pointer to the v-node table entry for the file.

3)Each open file (or device) has a v-node structure that contains information about the type of file and pointers to functions that operate on the file. For most files, the v-node also contains the i-node for the file. This information is read from disk
when the file is opened, so that all the pertinent information about the file is readily available. For example, the i-node contains the owner of the file, the size of the file, pointers to where the actual data blocks for the file are located on
disk, and so on.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: