1 .\" $OpenBSD: stat.2,v 1.3 1997/02/13 05:20:55 millert Exp $
3 .\" Copyright (c) 1980, 1991, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)stat.2 8.3 (Berkeley) 4/19/94
49 .Fd #include <sys/stat.h>
53 .Fa "struct stat *buf"
57 .Fa "const char *restrict path"
58 .Fa "struct stat *restrict buf"
62 .Fa "const char *restrict path"
63 .Fa "struct stat *restrict buf"
66 .Fn fstatat "int fd" "const char *path" "struct stat *buf" "int flag"
67 .Sh TRANSITIIONAL SYNOPSIS (NOW DEPRECATED)
72 .Fa "struct stat64 *buf"
78 .Fa "const char *restrict path"
79 .Fa "struct stat64 *restrict buf"
85 .Fa "const char *restrict path"
86 .Fa "struct stat64 *restrict buf"
91 function obtains information about the file pointed to by
93 Read, write or execute
94 permission of the named file is not required, but all directories
95 listed in the path name leading to the file must be searchable.
102 except in the case where the named file is a symbolic link;
104 returns information about the link,
107 returns information about the file the link references.
108 The attributes cannot be relied on in case of symbolic links.
109 In this case, the only attributes returned from an
111 that refer to the symbolic link itself are the file type (S_IFLNK),
112 size, blocks, and link count (always 1).
116 obtains the same information about an open file
117 known by the file descriptor
122 system call is equivalent to
126 except in the case where the
128 specifies a relative path.
129 In this case the status is retrieved from a file relative to
130 the directory associated with the file descriptor
132 instead of the current working directory.
136 are constructed by a bitwise-inclusive OR of flags from the following list,
139 .Bl -tag -width indent
140 .It Dv AT_SYMLINK_NOFOLLOW
143 names a symbolic link, the status of the symbolic link is returned.
148 is passed the special value
152 parameter, the current working directory is used and the behavior is
153 identical to a call to
157 respectively, depending on whether or not the
158 .Dv AT_SYMLINK_NOFOLLOW
164 argument is a pointer to a
169 and into which information is placed concerning the file.
171 .Dv _DARWIN_FEATURE_64_BIT_INODE
172 is not defined (see below for more information about this macro), the
174 structure is defined as:
176 struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */
177 dev_t st_dev; /* device inode resides on */
178 ino_t st_ino; /* inode's number */
179 mode_t st_mode; /* inode protection mode */
180 nlink_t st_nlink; /* number of hard links to the file */
181 uid_t st_uid; /* user-id of owner */
182 gid_t st_gid; /* group-id of owner */
183 dev_t st_rdev; /* device type, for special file inode */
184 struct timespec st_atimespec; /* time of last access */
185 struct timespec st_mtimespec; /* time of last data modification */
186 struct timespec st_ctimespec; /* time of last file status change */
187 off_t st_size; /* file size, in bytes */
188 quad_t st_blocks; /* blocks allocated for file */
189 u_long st_blksize;/* optimal file sys I/O ops blocksize */
190 u_long st_flags; /* user defined flags for file */
191 u_long st_gen; /* file generation number */
195 However, when the macro
196 .Dv _DARWIN_FEATURE_64_BIT_INODE
199 structure will now be defined as:
201 struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
202 dev_t st_dev; /* ID of device containing file */
203 mode_t st_mode; /* Mode of file (see below) */
204 nlink_t st_nlink; /* Number of hard links */
205 ino_t st_ino; /* File serial number */
206 uid_t st_uid; /* User ID of the file */
207 gid_t st_gid; /* Group ID of the file */
208 dev_t st_rdev; /* Device ID */
209 struct timespec st_atimespec; /* time of last access */
210 struct timespec st_mtimespec; /* time of last data modification */
211 struct timespec st_ctimespec; /* time of last status change */
212 struct timespec st_birthtimespec; /* time of file creation(birth) */
213 off_t st_size; /* file size, in bytes */
214 blkcnt_t st_blocks; /* blocks allocated for file */
215 blksize_t st_blksize; /* optimal blocksize for I/O */
216 uint32_t st_flags; /* user defined flags for file */
217 uint32_t st_gen; /* file generation number */
218 int32_t st_lspare; /* RESERVED: DO NOT USE! */
219 int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
223 The time-related fields of
226 .Bl -tag -width XXXst_birthtime
228 Time when file data last accessed.
236 Time when file data last modified.
244 Time when file status was last changed (inode data modification).
257 Time of file creation. Only set once when the file is created. This field is
258 only available in the 64 bit inode variants. On filesystems where birthtime is
259 not available, this field is set to 0 (i.e. epoch).
262 The size-related fields of the structures are as follows:
263 .Bl -tag -width XXXst_blksize
265 The optimal I/O block size for the file.
267 The actual number of blocks allocated for the file in 512-byte units.
268 As short symbolic links are stored in the inode, this number may
272 The status information word
274 has the following bits:
276 #define S_IFMT 0170000 /* type of file */
277 #define S_IFIFO 0010000 /* named pipe (fifo) */
278 #define S_IFCHR 0020000 /* character special */
279 #define S_IFDIR 0040000 /* directory */
280 #define S_IFBLK 0060000 /* block special */
281 #define S_IFREG 0100000 /* regular */
282 #define S_IFLNK 0120000 /* symbolic link */
283 #define S_IFSOCK 0140000 /* socket */
284 #define S_IFWHT 0160000 /* whiteout */
285 #define S_ISUID 0004000 /* set user id on execution */
286 #define S_ISGID 0002000 /* set group id on execution */
287 #define S_ISVTX 0001000 /* save swapped text even after use */
288 #define S_IRUSR 0000400 /* read permission, owner */
289 #define S_IWUSR 0000200 /* write permission, owner */
290 #define S_IXUSR 0000100 /* execute/search permission, owner */
293 For a list of access modes, see
299 For a list of the file flags in the
305 .Sh _DARWIN_FEATURE_64_BIT_INODE
306 In order to accommodate advanced capabilities of newer file systems, the
311 data structures were updated in Mac OSX 10.5.
313 The most obvious change is the increased size of
315 from 32 bits to 64 bits. As a consequence, storing an ino_t in an int is
316 no longer safe, and file formats storing ino_t as 32-bit values may need to
317 be updated. There are other changes as well, such as the widening of
328 for more detail on the specific changes to the other affected data structures.
330 On platforms that existed before these updates were available, ABI
331 compatibility is achieved by providing two implementations for related
332 functions: one using the legacy data structures and one using the updated
333 data structures. Variants which make use of the newer structures have their
334 symbols suffixed with $INODE64. These $INODE64 suffixes are automatically
335 appended by the compiler tool-chain and should not be used directly.
337 Platforms that were released after these updates only have the newer variants
338 available to them. These platforms have the macro
339 .Dv _DARWIN_FEATURE_ONLY_64_BIT_INODE
343 .Dv _DARWIN_FEATURE_64_BIT_INODE
344 macro should not be set directly. Instead, developers should make use of the
345 .Dv _DARWIN_NO_64_BIT_INODE
347 .Dv _DARWIN_USE_64_BIT_INODE
348 macros when the default variant is not desired. The following table details
349 the effects of defining these macros for different deployment targets.
359 .Dv _DARWIN_FEATURE_ONLY_64_BIT_INODE Sy not defined
363 user defines: < 10.5 10.5 > 10.5
367 T} 32-bit 32-bit 64-bit
369 .Dv _DARWIN_NO_64_BIT_INODE
370 T} 32-bit 32-bit 32-bit
372 .Dv _DARWIN_USE_64_BIT_INODE
373 T} 32-bit 64-bit 64-bit
383 .Dv _DARWIN_FEATURE_ONLY_64_BIT_INODE Sy defined
386 user defines: Any Deployment Target
392 .Dv _DARWIN_NO_64_BIT_INODE
397 .Dv _DARWIN_USE_64_BIT_INODE
402 .Bl -tag -width 64-bit-only -offset indent
404 32-bit inode values are enabled, and the legacy structures involving the
408 .Dv _DARWIN_FEATURE_64_BIT_INODE
411 64-bit inode values are enabled, and the expanded structures involving the
415 .Dv _DARWIN_FEATURE_64_BIT_INODE
416 is defined, and loader symbols will contain the
420 Like 64-bit, except loader symbols do not have the
424 A compile time error is generated.
427 Due to the increased benefits of the larger structure, it is highly
428 recommended that developers not define
429 .Dv _DARWIN_NO_64_BIT_INODE
431 .Dv _DARWIN_USE_64_BIT_INODE
432 when targeting Mac OSX 10.5.
434 In addition to the $INODE64 suffixed symbols, variants suffixed with 64 are
435 also available for related functions. These functions were provided as a way
436 for developers to use the updated structures in code that also made use of
437 the legacy structures. The enlarged stat structures were also prefixed with
438 64 to distinguish them from their legacy variants. These functions have been
439 deprecated and should be avoided.
441 Upon successful completion a value of 0 is returned.
442 Otherwise, a value of -1 is returned and
444 is set to indicate the error.
446 Previous versions of the system used different types for the
460 system call will fail if:
464 is not a valid open file descriptor.
468 points to an invalid address.
471 An I/O error occurs while reading from or writing to the file system.
478 system calls will fail if:
482 Search permission is denied for a component of the path prefix.
488 points to an invalid address.
491 An I/O error occurs while reading from or writing to the file system.
494 Too many symbolic links are encountered in translating the pathname.
495 This is taken to be indicative of a looping symbolic link.
497 .It Bq Er ENAMETOOLONG
498 A component of a pathname exceeds
500 characters, or an entire path name exceeds
505 The named file does not exist.
508 A component of the path prefix is not a directory.
516 system calls will fail if:
520 The file size in bytes
521 or the number of blocks allocated to the file
522 or the file serial number cannot be represented correctly
523 in the structure pointed to by
527 In addition to the errors returned by the
537 argument does not specify an absolute path and the
541 nor a valid file descriptor open for searching.
545 argument is not valid.
549 argument is not an absolute path and
553 nor a file descriptor associated with a directory.
556 The file generation number,
558 is only available to the super-user.
560 The fields in the stat structure currently marked
565 are present in preparation for inode time stamps expanding
566 to 64 bits. This, however, can break certain programs that
567 depend on the time stamps being contiguous (in calls to
569 .Sh TRANSITIONAL DESCRIPTION (NOW DEPRECATED)
575 routines are equivalent to their corresponding non-64-suffixed routine,
576 when 64-bit inodes are in effect.
577 They were added before there was support for the symbol variants, and so are
579 Instead of using these, set the
580 .Dv _DARWIN_USE_64_BIT_INODE
581 macro before including header files to force 64-bit inode support.
585 structure used by these deprecated routines is the same as the
587 structure when 64-bit inodes are in effect (see above).
599 to a socket (and thus to a pipe)
600 returns a zero'd buffer,
601 except for the blocksize field,
602 and a unique device and inode number.
608 function calls are expected to conform to
612 system call is expected to conform to POSIX.1-2008 .
616 function call appeared in
623 system calls first appeared in Mac OS X 10.5 (Leopard) and are now deprecated
624 in favor of the corresponding symbol variants.
627 system call appeared in OS X 10.10