Specification of file descriptors

后端 未结 2 539
别那么骄傲
别那么骄傲 2021-01-26 14:23

I am trying to understand flags and modes of file descriptors.

The man page for

fcntl - manipulate file descriptor

int fcntl(int fd, int cmd);
<         


        
2条回答
  •  不思量自难忘°
    2021-01-26 15:25

    I will summarize the description by Joseph Sible-Reinstate Monica and add a few remarks on possibly confusing wording across man pages, likely the cause of the OP.

    As per headings in http://man7.org/linux/man-pages/man2/fcntl.2.html (as cited in the OP) Flags = File descriptor flags + File status flags.
    Remark 1: this usage of File status flags is not consistent with the rest of available information, so it should rather be called something like

    Flags = File descriptor flags + Non-FD flags.

    The distinction between these two groups of flags is given by Joseph Sible-Reinstate Monica.

    As per http://man7.org/linux/man-pages/man2/open.2.html,

    Non-FD Flags = Access mode + File creation flags + File status flags

    Note that:

    1. The man page does not use the name Non-FD Flags. It simply calls this flags, as the name of the argument in the prototypes listed. But this should not be taken as if, conceptually, these flags encompass all flags since File descriptor flags are not included.

    2. "The distinction between these two groups of flags is that the file creation flags affect the semantics of the open operation itself, while the file status flags affect the semantics of subsequent I/O operations." [ref]

    3. This is the most common usage of File status flags.

    This is the basic classification of "entities".
    Remark 2: I use quotes since the general use of flags is quite misleading. Access mode are not flags in the usual sense, and this is clarified in How to make sense of O_RDONLY = 0?.

    Remark 3: GNU uses a different naming, adding to the confusion. The translation POSIX.1 <-> GNU is shown below. Usage of File Status Flags in GNU may be especially confusing.

    POSIX.1               GNU
    Non-FD Flags*         File Status Flags
    Access modes          Access mode
    File creation flags   Open-time Flags
    File status flags     Operating Modes
    

    As for the listings enumerating each category, they are given by Joseph Sible-Reinstate Monica. GNU also has its own Access modes, File creation flags (Open-time Flags) and File status flags (Operating Modes).

提交回复
热议问题