#include <sys/stat.h>

sys/stat.h

48 macros · 28 functions · 2 structs

structostat

XXX So deprecated, it would make your head spin The old stat structure. In fact, this is not used by the kernel at all, and should not be used by user space, and should be removed from this header file entirely (along with the unused cvtstat() prototype in vnode_internal.h).
size 96, align 8
__uint16_tst_devinode's device
ino_tst_inoinode's number
mode_tst_modeinode protection mode
nlink_tst_nlinknumber of hard links
__uint16_tst_uiduser ID of the file's owner
__uint16_tst_gidgroup ID of the file's group
__uint16_tst_rdevdevice type
__int32_tst_sizefile size, in bytes
struct timespecst_atimespectime of last access
struct timespecst_mtimespectime of last data modification
struct timespecst_ctimespectime of last file status change
__int32_tst_blksizeoptimal blocksize for I/O
__int32_tst_blocksblocks allocated for file
__uint32_tst_flagsuser defined flags for file
__uint32_tst_genfile generation number

structstat

size 144, align 8
dev_tst_dev[XSI] ID of device containing file
mode_tst_mode[XSI] Mode of file (see below)
nlink_tst_nlink[XSI] Number of hard links
__darwin_ino64_tst_ino[XSI] File serial number
uid_tst_uid[XSI] User ID of the file
gid_tst_gid[XSI] Group ID of the file
dev_tst_rdev[XSI] Device ID
struct timespecst_atimespec
struct timespecst_mtimespec
struct timespecst_ctimespec
struct timespecst_birthtimespec
off_tst_size[XSI] file size, in bytes
blkcnt_tst_blocks[XSI] blocks allocated for file
blksize_tst_blksize[XSI] optimal blocksize for I/O
__uint32_tst_flagsuser defined flags for file
__uint32_tst_genfile generation number
__int32_tst_lspareRESERVED: DO NOT USE!
__int64_t[2]st_qspareRESERVED: DO NOT USE!

macrost_atime

#define st_atime st_atimespec.tv_sec

macrost_mtime

#define st_mtime st_mtimespec.tv_sec

macrost_ctime

#define st_ctime st_ctimespec.tv_sec

macrost_birthtime

#define st_birthtime st_birthtimespec.tv_sec

macroS_ISBLK

[XSI] The following macros shall be provided to test whether a file is of the specified type. The value m supplied to the macros is the value of st_mode from a stat structure. The macro shall evaluate to a non-zero value if the test is true; 0 if the test is false.
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
block special

macroS_ISCHR

#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
char special

macroS_ISDIR

#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
directory

macroS_ISFIFO

#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
fifo or socket

macroS_ISREG

#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
regular file

macroS_ISLNK

#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
symbolic link

macroS_ISSOCK

#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
socket

macroS_ISWHT

#define S_ISWHT(m) (((m) & S_IFMT) == S_IFWHT)
OBSOLETE: whiteout

macroS_TYPEISMQ

[XSI] The implementation may implement message queues, semaphores, or shared memory objects as distinct file types. The following macros shall be provided to test whether a file is of the specified type. The value of the buf argument supplied to the macros is a pointer to a stat structure. The macro shall evaluate to a non-zero value if the specified object is implemented as a distinct file type and the specified file type is contained in the stat structure referenced by buf. Otherwise, the macro shall evaluate to zero. NOTE: The current implementation does not do this, although this may change in future revisions, and co currently only provides these macros to ensure source compatability with implementations which do.
#define S_TYPEISMQ(buf) (0)
Test for a message queue

macroS_TYPEISSEM

#define S_TYPEISSEM(buf) (0)
Test for a semaphore

macroS_TYPEISSHM

#define S_TYPEISSHM(buf) (0)
Test for a shared memory object

macroS_TYPEISTMO

[TYM] The implementation may implement typed memory objects as distinct file types, and the following macro shall test whether a file is of the specified type. The value of the buf argument supplied to the macros is a pointer to a stat structure. The macro shall evaluate to a non-zero value if the specified object is implemented as a distinct file type and the specified file type is contained in the stat structure referenced by buf. Otherwise, the macro shall evaluate to zero. NOTE: The current implementation does not do this, although this may change in future revisions, and co currently only provides this macro to ensure source compatability with implementations which do.
#define S_TYPEISTMO(buf) (0)
Test for a typed memory object

macroACCESSPERMS

#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
0777

macroDEFFILEMODE

0666
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

macroS_BLKSIZE

#define S_BLKSIZE 512
block size used in the stat struct

macroUF_SETTABLE

Definitions of flags stored in file flags word. Super-user and owner changeable flags.
#define UF_SETTABLE 0x0000ffff
mask of owner changeable flags

macroUF_NODUMP

#define UF_NODUMP 0x00000001
do not dump file

macroUF_IMMUTABLE

#define UF_IMMUTABLE 0x00000002
file may not be changed

macroUF_APPEND

#define UF_APPEND 0x00000004
writes to file may only append

macroUF_OPAQUE

#define UF_OPAQUE 0x00000008
directory is opaque wrt. union

macroUF_COMPRESSED

#define UF_COMPRESSED 0x00000020
file is compressed (some file-systems)

macroUF_TRACKED

UF_TRACKED is used for dealing with document IDs. We no longer issue notifications for deletes or renames for files which have UF_TRACKED set.
#define UF_TRACKED 0x00000040

macroUF_DATAVAULT

#define UF_DATAVAULT 0x00000080
entitlement required for reading

macroUF_HIDDEN

Bits 0x0100 through 0x4000 are currently undefined.
#define UF_HIDDEN 0x00008000
hint that this item should not be

macroSF_SUPPORTED

displayed in a GUI Super-user changeable flags.
#define SF_SUPPORTED 0x009f0000
mask of superuser supported flags

macroSF_SETTABLE

#define SF_SETTABLE 0x3fff0000
mask of superuser changeable flags

macroSF_SYNTHETIC

#define SF_SYNTHETIC 0xc0000000
mask of system read-only synthetic flags

macroSF_ARCHIVED

#define SF_ARCHIVED 0x00010000
file is archived

macroSF_IMMUTABLE

#define SF_IMMUTABLE 0x00020000
file may not be changed

macroSF_APPEND

#define SF_APPEND 0x00040000
writes to file may only append

macroSF_RESTRICTED

#define SF_RESTRICTED 0x00080000
entitlement required for writing

macroSF_DATALESS

Synthetic flags. These are read-only. We keep them out of SF_SUPPORTED so that attempts to set them will fail.
#define SF_DATALESS 0x40000000
file is dataless object

macroEF_MAY_SHARE_BLOCKS

Extended flags ("EF") returned by ATTR_CMNEXT_EXT_FLAGS from getattrlist/getattrlistbulk
#define EF_MAY_SHARE_BLOCKS 0x00000001
file may share blocks with another file

macroEF_NO_XATTRS

#define EF_NO_XATTRS 0x00000002
file has no xattrs at all

macroEF_IS_SYNC_ROOT

#define EF_IS_SYNC_ROOT 0x00000004
file is a sync root for iCloud

macroEF_IS_PURGEABLE

#define EF_IS_PURGEABLE 0x00000008
file is purgeable

macroEF_IS_SPARSE

#define EF_IS_SPARSE 0x00000010
file has at least one sparse region

macroEF_IS_SYNTHETIC

#define EF_IS_SYNTHETIC 0x00000020
a synthetic directory/symlink

macroEF_SHARES_ALL_BLOCKS

#define EF_SHARES_ALL_BLOCKS 0x00000040
file shares all of its blocks with another file

functionchmod

__DARWIN_ALIAS(chmod)
int chmod(const char *, mode_t)
[XSI]
man page · June 4, 1993
chmod(2) — change mode of file

functionfchmod

__DARWIN_ALIAS(fchmod)
int fchmod(int, mode_t)
man page · June 4, 1993
fchmod(2) — change mode of file

functionfstat

__DARWIN_INODE64(fstat)
int fstat(int, struct stat *)
man page · May 15, 2008
fstat(2) — get file status

functionlstat

__DARWIN_INODE64(lstat)
int lstat(const char *, struct stat *)
man page · May 15, 2008
lstat(2) — get file status

functionmkdir

int mkdir(const char *, mode_t)
man page · December 11, 1993
mkdir(2) — make a directory file

functionmkfifo

int mkfifo(const char *, mode_t)
man page · June 4, 1993
mkfifo(2) — make a fifo file

functionstat

__DARWIN_INODE64(stat)
int stat(const char *, struct stat *)
man page · May 15, 2008
stat(2) — get file status

functionmknod

int mknod(const char *, mode_t, dev_t)
man page · June 4, 1993
mknod(2) — make a special file node

functionumask

mode_t umask(mode_t)
man page · June 4, 1993
umask(2) — set file creation mode mask

functionfchmodat

__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
int fchmodat(int, const char *, mode_t, int)
man page · June 4, 1993
fchmodat(2) — change mode of file

functionfstatat

__DARWIN_INODE64(fstatat) __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
int fstatat(int, const char *, struct stat *, int)
man page · May 15, 2008
fstatat(2) — get file status

functionmkdirat

__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
int mkdirat(int, const char *, mode_t)
man page · December 11, 1993
mkdirat(2) — make a directory file

functionmkfifoat

__API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
int mkfifoat(int, const char *, mode_t)
man page · June 4, 1993
mkfifoat(2) — make a fifo file

functionmknodat

__API_AVAILABLE(macos(13.0), ios(16.0), tvos(16.0), watchos(9.0))
int mknodat(int, const char *, mode_t, dev_t)
man page · June 4, 1993
mknodat(2) — make a special file node

macroUTIME_NOW

#define UTIME_NOW -1

macroUTIME_OMIT

#define UTIME_OMIT -2

functionfutimens

__API_AVAILABLE(macosx(10.13), ios(11.0), tvos(11.0), watchos(4.0))
int futimens(int __fd, const struct timespec __times[2])
man page · January 17, 2016
futimens(2) — set file access and modification times

functionutimensat

__API_AVAILABLE(macosx(10.13), ios(11.0), tvos(11.0), watchos(4.0))
int utimensat(int __fd, const char *__path, const struct timespec __times[2], int __flag)
man page · January 17, 2016
utimensat(2) — set file access and modification times

functionchflags

int chflags(const char *, __uint32_t)
man page · June 9, 1993
chflags(2) — set file flags

functionchmodx_np

int chmodx_np(const char *, filesec_t)

functionfchflags

int fchflags(int, __uint32_t)
man page · June 9, 1993
fchflags(2) — set file flags

functionfchmodx_np

int fchmodx_np(int, filesec_t)

functionfstatx_np

__DARWIN_INODE64(fstatx_np)
int fstatx_np(int, struct stat *, filesec_t)

functionlchflags

__OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0)
int lchflags(const char *, __uint32_t)
man page · Feb 6, 2023
lchflags(3) — set file flags

functionlchmod

__OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0)
int lchmod(const char *, mode_t)
man page · Oct 31, 2005
lchmod(3) — change mode of file

functionlstatx_np

__DARWIN_INODE64(lstatx_np)
int lstatx_np(const char *, struct stat *, filesec_t)

functionmkdirx_np

int mkdirx_np(const char *, filesec_t)

functionmkfifox_np

int mkfifox_np(const char *, filesec_t)

functionstatx_np

__DARWIN_INODE64(statx_np)
int statx_np(const char *, struct stat *, filesec_t)

functionumaskx_np

__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_4, __MAC_10_6, __IPHONE_NA, __IPHONE_NA)
int umaskx_np(filesec_t)
deprecated