fcntl(5)


fcntl -- file control options

Synopsis

   #include <sys/fcntl.h> 

Description

The fcntl.h header defines the following requests and arguments for use by the functions fcntl [see fcntl(2)] and open [see open(2)].

Values for cmd used by fcntl (the following values are unique):

F_DUPFD Duplicate file descriptor
F_DUP2  
F_FREESP  
F_FREESP64  
F_GETADV  
F_SETADV  
F_GETCPUGROUP  
F_SETCPUGROUP  
F_GETFD Get file descriptor flags
F_SETFD Set file descriptor flags
F_GETFL Get file status flags
F_SETFL Set file status flags
F_GETGRAN  
F_SETGRAN  
F_GETLK Get record locking information
F_GETLK64 Get record locking information using an flock64 structure
F_GETOWN  
F_SETOWN  
F_RGETLK  
F_RGETLK64  
F_RSETLK  
F_RSETLK64  
F_RSETLKW  
F_RSETLKW64  
F_SETLK Set record locking information
F_SETLK64 Set record locking information using an flock64 structure
F_SETLKW Set record locking information; wait if blocked
F_SETLKW64 Set record locking information using an flock64 structure; wait if blocked

 
 F_DUPFD         Duplicate file descriptor 
 F_DUP2 
 F_FREESP 
 F_FREESP64 
 F_GETADV 
 F_SETADV 
 F_GETCPUGROUP 
 F_SETCPUGROUP 
 F_GETFD         Get file descriptor flags 
 F_SETFD         Set file descriptor flags 
 F_GETFL         Get file status flags 
 F_SETFL         Set file status flags 
 F_GETGRAN 
 F_SETGRAN 
 F_GETLK         Get record locking information 
 F_GETLK64       Get record locking information using an flock64 structure 
 F_GETOWN 
 F_SETOWN 
 F_RGETLK 
 F_RGETLK64 
 F_RSETLK 
 F_RSETLK64 
 F_RSETLKW 
 F_RSETLKW64 
 F_SETLK         Set record locking information 
 F_SETLK64       Set record locking information using an flock64 structure 
 F_SETLKW        Set record locking information; wait if blocked 
 F_SETLKW64      Set record locking information using an flock64 structure; wait if blocked 

File descriptor flags used for fcntl:

FD_CLOEXEC Close the file descriptor upon execution of an exec function (see exec(2))

 
 FD_CLOEXEC   Close the file descriptor 
              upon execution of an exec 
              function (see exec(2) 

Values for l_type used for record locking with fcntl (the following values are unique):

F_RDLCK Shared or read lock
F_UNLCK Unlock
F_WRLCK Exclusive or write lock

 
 F_RDLCK   Shared or read lock 
 F_UNLCK   Unlock 
 F_WRLCK   Exclusive or write lock 

The following three sets of values are bitwise distinct: Values for oflag used by open:

O_CREAT Create file if it does not exist
O_EXCL Exclusive use flag
O_NOCTTY Do not assign controlling tty
O_TRUNC Truncate flag

 
 O_CREAT    Create file if it does not exist 
 O_EXCL     Exclusive use flag 
 O_NOCTTY   Do not assign controlling tty 
 O_TRUNC    Truncate flag 

File status flags used for open and fcntl:

O_APPEND Set append mode
O_LARGEFILE Set large file mode
O_NDELAY Non-blocking mode
O_NONBLOCK Non-blocking mode (POSIX)
O_SYNC Synchronous writes

 
 O_APPEND      Set append mode 
 O_LARGEFILE   Set large file mode 
 O_NDELAY      Non-blocking mode 
 O_NONBLOCK    Non-blocking mode (POSIX) 
 O_SYNC        Synchronous writes 


Mask for use with file access modes:

O_ACCMODE Mask for file access modes

 
 O_ACCMODE   Mask for file access modes 

File access modes used for open and fcntl:

O_RDONLY Open for reading only
O_RDWR Open for reading and writing
O_WRONLY Open for writing only

 
 O_RDONLY   Open for reading only 
 O_RDWR     Open for reading and writing 
 O_WRONLY   Open for writing only 


The structure flock describes a file lock. It includes the following members:

   short   l_type;     /* Type of lock */ 
   short   l_whence;   /* Flag for starting offset */ 
   off_t   l_start;    /* Relative offset in bytes */ 
   off_t   l_len;      /* Size; if 0 then until EOF */ 
   long    l_sysid;    /* Returned with F_GETLK */ 
   pid_t   l_pid;      /* Returned with F_GETLK */ 
   long    l_pad       /* reserve area */ 

The structure flock64 describes a file lock for large files. It includes the following members:

   short   l_type;     /* Type of lock */ 
   short   l_whence;   /* Flag for starting offset */ 
   off64_t l_start;    /* Relative offset in bytes */ 
   off64_t l_len;      /* Size; if 0 then until EOF */ 
   long    l_sysid;    /* Returned with F_GETLK */ 
   pid_t   l_pid;      /* Returned with F_GETLK */ 
   long    l_pad       /* reserve area */ 

The only differences between the flock and flock64 structures are the l_start and the l_end members, which accomodate large files.

See unistd(4) for definition of values SEEK_CUR, SEEK_END, and SEEK_SET which are used for the l_whence member of both the flock and flock64 structures.

References

creat(2), exec(2), fcntl(2), open(2)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.