open() maps a filename to a file description. Some flags for open:
O_ASYNC - SIGIO signal will be generated when the file is ready for read or write. This flag is available only for terminal and socket
O_DIRECT - file to be opened for Direct I/O (i.e. no kernel buffering)
O_DIRECTORY - If the file to be opened is not a directory, the call will fail
O_LARGEFILE - use 64-bit offsets
O_NOCTTY - if the file is a termianl, it will not become the control terminal of the process
O_NOFOLLOW - if the file is a symbolic link, the call will fail
O_NONBLOCK - open using non-blocking mode
O_CREAT - create the file is it does not exist. When use with O_EXCL, the call will fail if the file exist. This combination is used to prevent race condition.
O_SYNC - file to be opened as synchronous mode. write() will only return until data and metadata are written to disk. read() is always synchronous and so this flag has no effect. All I/O write time is incurred to the process. The increase in cost is huge.
O_DSYNC (POSIX) - specifies that only data is synchronized and not metadata.
O_RSYNC (POSIX) - specifies the synchronization of read requests as well as write. It must be used with either O_SYNC or O_DSYNC. As read is always synchronized, this flag ensure the side effect of read is also synchronized (for example, file access time is updated befire read returns).
creat() is equivalent to open() with flags O_WRONLY | O_CREAT | O_TRUNC
No comments:
Post a Comment