#include <sys/fcntl.h>
sys/fcntl.h
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
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_DIRECTORY
#define O_DIRECTORY 0x00100000
macroAT_SYMLINK_NOFOLLOW_ANY
#define AT_SYMLINK_NOFOLLOW_ANY 0x0800
Path should not contain any symlinks
macroAT_RESOLVE_BENEATH
#define AT_RESOLVE_BENEATH 0x2000
Path must reside in the hierarchy beneath the starting directory
macroAT_UNIQUE
#define AT_UNIQUE 0x8000
prevent a path lookup from succeeding on a vnode with multiple links
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
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_FLUSH_DATA
#define F_FLUSH_DATA 40
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_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_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_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_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_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_SPECULATIVE_READ
#define F_SPECULATIVE_READ 101
Asynchronous advisory read fcntl for regular and compressed file
macroF_GETPATH_NOFIRMLINK
#define F_GETPATH_NOFIRMLINK 102
return the full path without firmlinks of the fd
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_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_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
| off_t | l_start | starting offset |
| off_t | l_len | len = 0 means until end of file |
| pid_t | l_pid | lock owner |
| short | l_type | lock type: read/write, etc. |
| short | l_whence | type of l_start |
structflocktimeout
Advisory file segment locking with time out -
Information passed to system by user for F_SETLKWTIMEOUT
| struct flock | fl | flock passed for file locking |
| struct timespec | timeout | timespec struct for timeout |
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
| off_t | fs_file_start | |
| void * | fs_blob_start | |
| size_t | fs_blob_size | |
| size_t | fs_fsignatures_size | The 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_cdhash | output: cdhash |
| int | fs_hash_type | output: hash algorithm type for cdhash |
typedeffsignatures_t
typedef struct fsignatures fsignatures_t;
structfsupplement
| off_t | fs_file_start | offset of Mach-O image in FAT file |
| off_t | fs_blob_start | offset of signature in Mach-O image |
| size_t | fs_blob_size | signature blob size |
| int | fs_orig_fd | address 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.
| off_t | lv_file_start | |
| size_t | lv_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
fgetsigsinfo_t used by F_GETSIGSINFO command
| off_t | fg_file_start | IN: Offset in the file to look for a signature, -1 for any signature |
| int | fg_info_request | IN: Key indicating the info requested |
| int | fg_sig_is_platform | OUT: 1 if the signature is a plat form binary, 0 if not |
typedeffgetsigsinfo_t
typedef struct fgetsigsinfo fgetsigsinfo_t;
structfstore
| unsigned int | fst_flags | IN: flags word |
| int | fst_posmode | IN: indicates use of offset field |
| off_t | fst_offset | IN: start of the region |
| off_t | fst_length | IN: size of the region |
| off_t | fst_bytesalloc | OUT: number of bytes allocated |
structfpunchhole
fpunchhole_t used by F_PUNCHHOLE
| unsigned int | fp_flags | unused |
| unsigned int | reserved | (to maintain 8-byte alignment) |
| off_t | fp_offset | IN: start of the region |
| off_t | fp_length | IN: size of the region |
typedeffpunchhole_t
typedef struct fpunchhole fpunchhole_t;
structftrimactivefile
factive_file_trim_t used by F_TRIM_ACTIVE_FILE
| off_t | fta_offset | IN: start of the region |
| off_t | fta_length | IN: size of the region |
typedefftrimactivefile_t
typedef struct ftrimactivefile ftrimactivefile_t;
structfspecread
fspecread_t used by F_SPECULATIVE_READ
| unsigned int | fsr_flags | IN: flags word |
| unsigned int | reserved | to maintain 8-byte alignment |
| off_t | fsr_offset | IN: start of the region |
| off_t | fsr_length | IN: size of the region |
typedeffspecread_t
typedef struct fspecread fspecread_t;
macroATTRIBUTION_NAME_MAX
fattributiontag_t used by F_ATTRIBUTION_TAG
#define ATTRIBUTION_NAME_MAX 255
structfattributiontag
| unsigned int | ft_flags | IN: flags word |
| unsigned long long | ft_hash | OUT: hash of attribution tag name |
| char[255] | ft_attribution_name | IN/OUT: attribution tag name associated with the file |
typedeffattributiontag_t
typedef struct fattributiontag fattributiontag_t;
macroF_DELETE_TAG
#define F_DELETE_TAG 0x00000002
macroF_QUERY_TAG
#define F_QUERY_TAG 0x00000004
structlog2phys
| unsigned int | l2p_flags | unused so far |
| off_t | l2p_contigbytes | F_LOG2PHYS: unused so far |
| off_t | l2p_devoffset | F_LOG2PHYS_EXT: IN: number of bytes to be queried OUT: number of contiguous bytes at this position F_LOG2PHYS: OUT: bytes into device |
enumfilesec_property_t
| FILESEC_OWNER | 1 | |
| FILESEC_GROUP | 2 | |
| FILESEC_UUID | 3 | |
| FILESEC_MODE | 4 | |
| FILESEC_ACL | 5 | |
| FILESEC_GRPUUID | 6 | |
| FILESEC_ACL_RAW | 100 | XXX these are private to the implementation |
| FILESEC_ACL_ALLOCSIZE | 101 |
typedeffilesec_property_t
typedef enum filesec_property_t filesec_property_t;
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 filefunctionfcntl
__DARWIN_ALIAS_C(fcntl)
int fcntl(int, int, ...)man page · August 12, 2021
fcntl(2) — file controlfunctionopen_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 verificationfunctionflock
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)