Skip to Content
UNIX Filesystems: Evolution, Design, and Implementation
book

UNIX Filesystems: Evolution, Design, and Implementation

by Steve D. Pate
January 2003
Intermediate to advanced content levelIntermediate to advanced
480 pages
13h 22m
English
Wiley
Content preview from UNIX Filesystems: Evolution, Design, and Implementation

File Control Operations

The fcntl() system call is designed to provide file control functions for open files. The definition was shown in a previous section, File and Record Locking, earlier in the chapter. It is repeated below:

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int fcntl(int fildes, int cmd, …);

The file descriptor refers to a previously opened file and the cmd argument is one of the commands shown below:

F_DUPFD. This command returns a new file descriptor that is the lowest numbered file descriptor available (and is not already open). The file descriptor returned will be greater than or equal to the third argument. The new file descriptor refers to the same open file as the original file descriptor and shares any locks. The FD_CLOEXEC (see F_SETFD below) flag associated with the new file descriptor is cleared to keep the file open across calls to one of the exec functions.

F_GETFD. This command returns the flags associated with the specified file descriptor. This is a little bit of a misnomer because there has only ever been one flag, the FD_CLOEXEC flag that indicates that the file should be closed following a successful call to exec().

F_SETFD. This command sets the FD_CLOEXEC flag.

F_GETFL. This command returns the file status flags and file access modes for fildes. The file access modes can be extracted from the return value using the mask O_ACCMODE. The flags are O_RDONLY, O_WRONLY and O_RDWR.

The file status flags, as described in the sections ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Marshall Kirk McKusick, George V. Neville-Neil, Robert N.M. Watson

Publisher Resources

ISBN: 9780471456759Purchase book