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);
states:
File descriptor flags
The following commands manipulate the flags associated with a file descriptor. Currently, only one such flag is defined: FD_CLOEXEC,...
File status flags
Each open file description has certain associated status flags, initialized by open(2)... The file status flags and their semantics are described in open(2).
Given that fcntl
refers entirely to file descriptors (no dealing with streams), I guess the second title should be "File descriptor status flags".
So now we have for a FD "flags" and "status flags".
This man page also mentions that when cmd=F_GETFL
, the return value of fcntl
is "the file access mode and the file status flags".
So now we have also a file access mode.
Now in the man page for open
there are flags and modes, as if they were two different items.
There is even a prototype that makes explicit the difference
int open(const char *pathname, int flags, mode_t mode);
So now we have, for each file descriptor, "flags", "status flags", "file access modes", and "modes" (I would identify the latter two as the same).
To begin with,
1. I don't know the difference between these three categories.
Traversing both quoted man pages, I collected a list of "entities" (below, in order of appearance, some are repeated).
2. I don't know which category each belongs to.
FD_CLOEXEC, O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, O_NONBLOCK, O_DSYNC, O_SYNC, O_CLOEXEC
O_CREAT, O_DIRECTORY, O_EXCL, O_NOCTTY, O_NOFOLLOW, O_TMPFILE, O_TRUNC, O_LARGEFILE, O_NDELAY, O_PATH
I couldn't find a simple list telling "X, Y, Z are flags, W, V are modes, etc." Perhaps they are terms that are used interchangeably, or the mode is a subset of the flags, or...
Related:
Difference between "file pointer", "stream", "file descriptor" and ... "file"? (answers there may be a guide in the present OP, even if not the same).
How to make sense of O_RDONLY = 0?
Difference between "file pointer", "stream", "file descriptor" and ... "file"?
How to get the mode of a file descriptor?
https://www.gnu.org/software/libc/manual/html_node/Access-Modes.html
https://www.gnu.org/software/libc/manual/html_node/File-Status-Flags.html#File-Status-Flags