#include <sys/fcntl.h>

sys/fcntl.h

140 macros · 16 functions · 13 structs · 10 typedefs · 1 enum

macroO_RDONLY

File status flags: these are used by open(2), fcntl(2). They are also used (indirectly) in the kernel file structure f_flags, which is a superset of the open/fcntl flags. Open flags and f_flags are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). Open/fcntl flags begin with O_; kernel-internal flags begin with F. open-only flags
#define O_RDONLY 0x0000
open for reading only

macroO_WRONLY

#define O_WRONLY 0x0001
open for writing only

macroO_RDWR

#define O_RDWR 0x0002
open for reading and writing

macroO_ACCMODE

#define O_ACCMODE 0x0003
mask for above modes

macroFREAD

Kernel encoding of open mode; separate read and write bits that are independently testable: 1 greater than the above. XXX FREAD and FWRITE are excluded from the #ifdef KERNEL so that TIOCFLUSH, which was documented to use FREAD/FWRITE, continues to work.
#define FREAD 0x00000001

macroFWRITE

#define FWRITE 0x00000002

macroO_NONBLOCK

#define O_NONBLOCK 0x00000004
no delay

macroO_APPEND

#define O_APPEND 0x00000008
set append mode

macroO_SHLOCK

#define O_SHLOCK 0x00000010
open with shared file lock

macroO_EXLOCK

#define O_EXLOCK 0x00000020
open with exclusive file lock

macroO_ASYNC

#define O_ASYNC 0x00000040
signal pgrp when data ready

macroO_FSYNC

#define O_FSYNC O_SYNC
source compatibility: do not use

macroO_NOFOLLOW

#define O_NOFOLLOW 0x00000100
don't follow symlinks

macroO_CREAT

#define O_CREAT 0x00000200
create if nonexistant

macroO_TRUNC

#define O_TRUNC 0x00000400
truncate to zero length

macroO_EXCL

#define O_EXCL 0x00000800
error if already exists

macroO_RESOLVE_BENEATH

#define O_RESOLVE_BENEATH 0x00001000
only for open(2), same value as FMARK

macroO_UNIQUE

#define O_UNIQUE 0x00002000
only for open(2), same value as FDEFER

macroO_EVTONLY

#define O_EVTONLY 0x00008000
descriptor requested for event notifications only

macroO_NOCTTY

#define O_NOCTTY 0x00020000
don't assign controlling terminal

macroO_DIRECTORY

#define O_DIRECTORY 0x00100000

macroO_CLOEXEC

#define O_CLOEXEC 0x01000000
implicitly set FD_CLOEXEC

macroO_NOFOLLOW_ANY

#define O_NOFOLLOW_ANY 0x20000000
no symlinks allowed in path

macroO_EXEC

#define O_EXEC 0x40000000
open file for execute only

macroAT_FDCWD

Descriptor value for the current working directory
#define AT_FDCWD -2

macroAT_EACCESS

Flags for the at functions
#define AT_EACCESS 0x0010
Use effective ids in access check

macroAT_REMOVEDIR

#define AT_REMOVEDIR 0x0080
Path refers to directory

macroAT_REALDEV

#define AT_REALDEV 0x0200
Return real device inodes resides on for fstatat(2)

macroAT_FDONLY

#define AT_FDONLY 0x0400
Use only the fd and Ignore the path for fstatat(2)

macroAT_RESOLVE_BENEATH

#define AT_RESOLVE_BENEATH 0x2000
Path must reside in the hierarchy beneath the starting directory

macroAT_NODELETEBUSY

#define AT_NODELETEBUSY 0x4000
Don't delete busy files

macroAT_UNIQUE

#define AT_UNIQUE 0x8000
prevent a path lookup from succeeding on a vnode with multiple links

macroO_DP_GETRAWENCRYPTED

Data Protection Flags
#define O_DP_GETRAWENCRYPTED 0x0001

macroO_DP_GETRAWUNENCRYPTED

#define O_DP_GETRAWUNENCRYPTED 0x0002

macroO_DP_AUTHENTICATE

#define O_DP_AUTHENTICATE 0x0004

macroAUTH_OPEN_NOAUTHFD

Descriptor value for openat_authenticated_np() to skip authentication with another fd
#define AUTH_OPEN_NOAUTHFD -1

macroFAPPEND

The O_* flags used to have only F* names, which were used in the kernel and by fcntl. We retain the F* names for the kernel f_flags field and for backward compatibility for fcntl.
#define FAPPEND O_APPEND
kernel/compat

macroFASYNC

#define FASYNC O_ASYNC
kernel/compat

macroFFSYNC

#define FFSYNC O_FSYNC
kernel

macroFFDSYNC

#define FFDSYNC O_DSYNC
kernel

macroFNONBLOCK

#define FNONBLOCK O_NONBLOCK
kernel

macroFNDELAY

#define FNDELAY O_NONBLOCK
compat

macroO_NDELAY

#define O_NDELAY O_NONBLOCK
compat

macroCPF_OVERWRITE

#define CPF_OVERWRITE 0x0001

macroCPF_IGNORE_MODE

#define CPF_IGNORE_MODE 0x0002

macroCPF_MASK

#define CPF_MASK (CPF_OVERWRITE|CPF_IGNORE_MODE)

macroF_DUPFD

command values
#define F_DUPFD 0
duplicate file descriptor

macroF_GETFD

#define F_GETFD 1
get file descriptor flags

macroF_SETFD

#define F_SETFD 2
set file descriptor flags

macroF_GETFL

#define F_GETFL 3
get file status flags

macroF_SETFL

#define F_SETFL 4
set file status flags

macroF_GETOWN

#define F_GETOWN 5
get SIGIO/SIGURG proc/pgrp

macroF_SETOWN

#define F_SETOWN 6
set SIGIO/SIGURG proc/pgrp

macroF_GETLK

#define F_GETLK 7
get record locking information

macroF_SETLK

#define F_SETLK 8
set record locking information

macroF_SETLKW

#define F_SETLKW 9
F_SETLK; wait if blocked

macroF_SETLKWTIMEOUT

#define F_SETLKWTIMEOUT 10
F_SETLK; wait if blocked, return on timeout

macroF_FLUSH_DATA

#define F_FLUSH_DATA 40

macroF_CHKCLEAN

#define F_CHKCLEAN 41
Used for regression test

macroF_PREALLOCATE

#define F_PREALLOCATE 42
Preallocate storage

macroF_SETSIZE

#define F_SETSIZE 43
Truncate a file. Equivalent to calling truncate(2)

macroF_RDADVISE

#define F_RDADVISE 44
Issue an advisory read async with no copy to user

macroF_RDAHEAD

#define F_RDAHEAD 45
turn read ahead off/on for this fd

macroF_NOCACHE

46,47 used to be F_READBOOTSTRAP and F_WRITEBOOTSTRAP
#define F_NOCACHE 48
turn data caching off/on for this fd

macroF_LOG2PHYS

#define F_LOG2PHYS 49
file offset to device offset

macroF_GETPATH

#define F_GETPATH 50
return the full path of the fd

macroF_FULLFSYNC

#define F_FULLFSYNC 51
fsync + ask the drive to flush to the media

macroF_PATHPKG_CHECK

#define F_PATHPKG_CHECK 52
find which component (if any) is a package

macroF_FREEZE_FS

#define F_FREEZE_FS 53
"freeze" all fs operations

macroF_THAW_FS

#define F_THAW_FS 54
"thaw" all fs operations

macroF_GLOBAL_NOCACHE

#define F_GLOBAL_NOCACHE 55
turn data caching off/on (globally) for this file

macroF_ADDSIGS

#define F_ADDSIGS 59
add detached signatures

macroF_ADDFILESIGS

#define F_ADDFILESIGS 61
add signature from same file (used by dyld for shared libs)

macroF_NODIRECT

#define F_NODIRECT 62
used in conjunction with F_NOCACHE to indicate that DIRECT, synchonous writes

macroF_GETPROTECTIONCLASS

#define F_GETPROTECTIONCLASS 63
Get the protection class of a file from the EA, returns int

macroF_SETPROTECTIONCLASS

#define F_SETPROTECTIONCLASS 64
Set the protection class of a file for the EA, requires int

macroF_LOG2PHYS_EXT

#define F_LOG2PHYS_EXT 65
file offset to device offset, extended

macroF_GETLKPID

#define F_GETLKPID 66
See man fcntl(2) F_GETLK Similar to F_GETLK but in addition l_pid is treated as an input parameter which is used as a matching value when searching locks on the file so that only locks owned by the process with pid l_pid are returned. However, any flock(2) type lock will also be found with the returned value of l_pid set to -1 (as with F_GETLK).

macroF_SETBACKINGSTORE

#define F_SETBACKINGSTORE 70
Mark the file as being the backing store for another filesystem

macroF_GETPATH_MTMINFO

#define F_GETPATH_MTMINFO 71
return the full path of the FD, but error in specific mtmd circumstances

macroF_GETCODEDIR

#define F_GETCODEDIR 72
Returns the code directory, with associated hashes, to the caller

macroF_SETNOSIGPIPE

#define F_SETNOSIGPIPE 73
No SIGPIPE generated on EPIPE

macroF_GETNOSIGPIPE

#define F_GETNOSIGPIPE 74
Status of SIGPIPE for this fd

macroF_TRANSCODEKEY

#define F_TRANSCODEKEY 75
For some cases, we need to rewrap the key for AKS/MKB

macroF_SINGLE_WRITER

#define F_SINGLE_WRITER 76
file being written to a by single writer... if throttling enabled, writes

macroF_GETPROTECTIONLEVEL

#define F_GETPROTECTIONLEVEL 77
Get the protection version number for this filesystem

macroF_FINDSIGS

#define F_FINDSIGS 78
Add detached code signatures (used by dyld for shared libs)

macroF_ADDFILESIGS_FOR_DYLD_SIM

#define F_ADDFILESIGS_FOR_DYLD_SIM 83
Add signature from same file, only if it is signed by Apple (used by dyld for simulator)

macroF_BARRIERFSYNC

#define F_BARRIERFSYNC 85
fsync + issue barrier to drive

macroF_OFD_SETLK

#define F_OFD_SETLK 90
Acquire or release open file description lock

macroF_OFD_SETLKW

#define F_OFD_SETLKW 91
(as F_OFD_SETLK but blocking if conflicting lock)

macroF_OFD_GETLK

#define F_OFD_GETLK 92
Examine OFD lock

macroF_OFD_SETLKWTIMEOUT

#define F_OFD_SETLKWTIMEOUT 93
(as F_OFD_SETLKW but return if timeout)

macroF_ADDFILESIGS_RETURN

#define F_ADDFILESIGS_RETURN 97
Add signature from same file, return end offset in structure on success

macroF_CHECK_LV

#define F_CHECK_LV 98
Check if Library Validation allows this Mach-O file to be mapped into the calling process

macroF_PUNCHHOLE

#define F_PUNCHHOLE 99
Deallocate a range of the file

macroF_TRIM_ACTIVE_FILE

#define F_TRIM_ACTIVE_FILE 100
Trim an active file

macroF_SPECULATIVE_READ

#define F_SPECULATIVE_READ 101
Asynchronous advisory read fcntl for regular and compressed file

macroF_ADDFILESIGS_INFO

#define F_ADDFILESIGS_INFO 103
Add signature from same file, return information

macroF_ADDFILESUPPL

#define F_ADDFILESUPPL 104
Add supplemental signature from same file with fd reference to original

macroF_GETSIGSINFO

#define F_GETSIGSINFO 105
Look up code signature information attached to a file or slice

macroF_SETLEASE

#define F_SETLEASE 106
Acquire or release lease

macroF_GETLEASE

#define F_GETLEASE 107
Retrieve lease information

macroF_SETLEASE_ARG

#define F_SETLEASE_ARG(t, oc) ((t) | ((oc) << 2))

macroF_TRANSFEREXTENTS

#define F_TRANSFEREXTENTS 110
Transfer allocated extents beyond leof to a different file

macroF_ATTRIBUTION_TAG

#define F_ATTRIBUTION_TAG 111
Based on flags, query/set/delete a file's attribution tag

macroF_NOCACHE_EXT

#define F_NOCACHE_EXT 112
turn data caching off/on for this fd and relax size and alignment restrictions for write

macroF_ADDSIGS_MAIN_BINARY

#define F_ADDSIGS_MAIN_BINARY 113
add detached signatures for main binary -- development only

macroFCNTL_FS_SPECIFIC_BASE

FS-specific fcntl()'s numbers begin at 0x00010000 and go up
#define FCNTL_FS_SPECIFIC_BASE 0x00010000

macroF_DUPFD_CLOEXEC

#define F_DUPFD_CLOEXEC 67
mark the dup with FD_CLOEXEC

macroFD_CLOEXEC

file descriptor flags (F_GETFD, F_SETFD)
#define FD_CLOEXEC 1
close-on-exec flag

macroF_RDLCK

record locking flags (F_GETLK, F_SETLK, F_SETLKW)
#define F_RDLCK 1
shared or read lock

macroF_UNLCK

#define F_UNLCK 2
unlock

macroF_WRLCK

#define F_WRLCK 3
exclusive or write lock

macroF_ALLOCATECONTIG

#define F_ALLOCATECONTIG 0x00000002
allocate contigious space

macroF_ALLOCATEALL

#define F_ALLOCATEALL 0x00000004
allocate all requested space or no space at all

macroF_ALLOCATEPERSIST

#define F_ALLOCATEPERSIST 0x00000008
do not free space upon close(2)

macroF_PEOFPOSMODE

#define F_PEOFPOSMODE 3
Make it past all of the SEEK pos modes so that

macroF_VOLPOSMODE

we can keep them in sync should we desire
#define F_VOLPOSMODE 4
specify volume starting postion

structflock

Advisory file segment locking data type - information passed to system by user
size 24, align 8
off_tl_startstarting offset
off_tl_lenlen = 0 means until end of file
pid_tl_pidlock owner
shortl_typelock type: read/write, etc.
shortl_whencetype of l_start

structflocktimeout

Advisory file segment locking with time out - Information passed to system by user for F_SETLKWTIMEOUT
size 40, align 8
struct flockflflock passed for file locking
struct timespectimeouttimespec struct for timeout

structradvisory

size 16, align 8
off_tra_offset
intra_count

macroUSER_FSIGNATURES_CDHASH_LEN

detached code signatures data type - information passed by user to system used by F_ADDSIGS and F_ADDFILESIGS. F_ADDFILESIGS is a shortcut for files that contain their own signature and doesn't require mapping of the file in order to load the signature.
#define USER_FSIGNATURES_CDHASH_LEN 20

structfsignatures

size 56, align 8
off_tfs_file_start
void *fs_blob_start
size_tfs_blob_size
size_tfs_fsignatures_sizeThe following fields are only applicable to F_ADDFILESIGS_INFO (64bit only). Prior to F_ADDFILESIGS_INFO, this struct ended after fs_blob_size. input: size of this struct (for compatibility)
char[20]fs_cdhashoutput: cdhash
intfs_hash_typeoutput: hash algorithm type for cdhash

typedeffsignatures_t

typedef struct fsignatures fsignatures_t;

structfsupplement

size 32, align 8
off_tfs_file_startoffset of Mach-O image in FAT file
off_tfs_blob_startoffset of signature in Mach-O image
size_tfs_blob_sizesignature blob size
intfs_orig_fdaddress of original image

typedeffsupplement_t

typedef struct fsupplement fsupplement_t;

structfchecklv

DYLD needs to check if the object is allowed to be combined into the main binary. This is done between the code signature is loaded and dyld is doing all the work to process the LOAD commands. While this could be done in F_ADDFILESIGS.* family the hook into the MAC module doesn't say no when LV isn't enabled and then that is cached on the vnode, and the MAC module never gets change once a process that library validation enabled.
size 24, align 8
off_tlv_file_start
size_tlv_error_message_size
void *lv_error_message

typedeffchecklv_t

typedef struct fchecklv fchecklv_t;

macroGETSIGSINFO_PLATFORM_BINARY

At this time F_GETSIGSINFO can only indicate platformness. As additional requestable information is defined, new keys will be added and the fgetsigsinfo_t structure will be lengthened to add space for the additional information
#define GETSIGSINFO_PLATFORM_BINARY 1

structfgetsigsinfo

size 16, align 8
off_tfg_file_startIN: Offset in the file to look for a signature, -1 for any signature
intfg_info_requestIN: Key indicating the info requested
intfg_sig_is_platformOUT: 1 if the signature is a plat form binary, 0 if not

typedeffgetsigsinfo_t

typedef struct fgetsigsinfo fgetsigsinfo_t;

macroLOCK_SH

lock operations for flock(2)
#define LOCK_SH 0x01
shared file lock

macroLOCK_EX

#define LOCK_EX 0x02
exclusive file lock

macroLOCK_NB

#define LOCK_NB 0x04
don't block when locking

macroLOCK_UN

#define LOCK_UN 0x08
unlock file

structfstore

size 32, align 8
unsigned intfst_flagsIN: flags word
intfst_posmodeIN: indicates use of offset field
off_tfst_offsetIN: start of the region
off_tfst_lengthIN: size of the region
off_tfst_bytesallocOUT: number of bytes allocated

typedeffstore_t

typedef struct fstore fstore_t;

structfpunchhole

size 24, align 8
unsigned intfp_flagsunused
unsigned intreserved(to maintain 8-byte alignment)
off_tfp_offsetIN: start of the region
off_tfp_lengthIN: size of the region

typedeffpunchhole_t

typedef struct fpunchhole fpunchhole_t;

structftrimactivefile

factive_file_trim_t used by F_TRIM_ACTIVE_FILE
size 16, align 8
off_tfta_offsetIN: start of the region
off_tfta_lengthIN: size of the region

typedefftrimactivefile_t

typedef struct ftrimactivefile ftrimactivefile_t;

structfspecread

size 24, align 8
unsigned intfsr_flagsIN: flags word
unsigned intreservedto maintain 8-byte alignment
off_tfsr_offsetIN: start of the region
off_tfsr_lengthIN: size of the region

typedeffspecread_t

typedef struct fspecread fspecread_t;

macroATTRIBUTION_NAME_MAX

#define ATTRIBUTION_NAME_MAX 255

structfattributiontag

size 272, align 8
unsigned intft_flagsIN: flags word
unsigned long longft_hashOUT: hash of attribution tag name
char[255]ft_attribution_nameIN/OUT: attribution tag name associated with the file

typedeffattributiontag_t

typedef struct fattributiontag fattributiontag_t;

macroF_CREATE_TAG

#define F_CREATE_TAG 0x00000001

macroF_DELETE_TAG

#define F_DELETE_TAG 0x00000002

macroF_QUERY_TAG

#define F_QUERY_TAG 0x00000004

structlog2phys

size 20, align 4
unsigned intl2p_flagsunused so far
off_tl2p_contigbytesF_LOG2PHYS: unused so far
off_tl2p_devoffsetF_LOG2PHYS_EXT: IN: number of bytes to be queried OUT: number of contiguous bytes at this position F_LOG2PHYS: OUT: bytes into device

macroO_POPUP

#define O_POPUP 0x80000000
force window to popup on open

macroO_ALERT

#define O_ALERT 0x20000000
small, clean popup window

enumfilesec_property_t

underlying type unsigned int
FILESEC_OWNER1
FILESEC_GROUP2
FILESEC_UUID3
FILESEC_MODE4
FILESEC_ACL5
FILESEC_GRPUUID6
FILESEC_ACL_RAW100XXX these are private to the implementation
FILESEC_ACL_ALLOCSIZE101

typedeffilesec_property_t

typedef enum filesec_property_t filesec_property_t;

macroFILESEC_GUID

XXX backwards compatibility
#define FILESEC_GUID FILESEC_UUID

functionopen

__DARWIN_ALIAS_C(open)
int open(const char *, int, ...)

functionopenat

__DARWIN_NOCANCEL(openat) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
int openat(int, const char *, int, ...)

functioncreat

__DARWIN_ALIAS_C(creat)
int creat(const char *, mode_t)
man page · June 2, 1993
creat(2) — create a new file

functionfcntl

__DARWIN_ALIAS_C(fcntl)
int fcntl(int, int, ...)
man page · August 12, 2021
fcntl(2) — file control

functionopenx_np

int openx_np(const char *, int, filesec_t)

functionopen_dprotected_np

int open_dprotected_np(const char *, int, int, int, ...)
data-protected non-portable open(2) : int open_dprotected_np(user_addr_t path, int flags, int class, int dpflags, int mode)

functionopenat_dprotected_np

int openat_dprotected_np(int, const char *, int, int, int, ...)

functionopenat_authenticated_np

int openat_authenticated_np(int, const char *, int, int)
man page · October 22, 2025
openat_authenticated_np(2) — open files with authenticated volume verification

functionflock

int flock(int, int)
man page · December 11, 1993
flock(2) — "apply or remove an advisory lock on an open file"

functionfilesec_init

filesec_t filesec_init(void)

functionfilesec_dup

filesec_t filesec_dup(filesec_t)

functionfilesec_free

void filesec_free(filesec_t)

functionfilesec_get_property

int filesec_get_property(filesec_t, filesec_property_t, void *)

functionfilesec_query_property

int filesec_query_property(filesec_t, filesec_property_t, int *)

functionfilesec_set_property

int filesec_set_property(filesec_t, filesec_property_t, const void *)

functionfilesec_unset_property

__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
int filesec_unset_property(filesec_t, filesec_property_t)

macro_FILESEC_UNSET_PROPERTY

#define _FILESEC_UNSET_PROPERTY ((void *)0)

macro_FILESEC_REMOVE_ACL

#define _FILESEC_REMOVE_ACL ((void *)1)