Blame man-pages-posix-2013-a/man0p/sys_stat.h.0p

Packit 7cfc04
'\" et
Packit 7cfc04
.TH sys_stat.h "0P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
Packit 7cfc04
.SH PROLOG
Packit 7cfc04
This manual page is part of the POSIX Programmer's Manual.
Packit 7cfc04
The Linux implementation of this interface may differ (consult
Packit 7cfc04
the corresponding Linux manual page for details of Linux behavior),
Packit 7cfc04
or the interface may not be implemented on Linux.
Packit 7cfc04
Packit 7cfc04
.SH NAME
Packit 7cfc04
sys/stat.h
Packit 7cfc04
\(em data returned by the stat(\|) function
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <sys/stat.h>
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the structure of the data returned by the
Packit 7cfc04
\fIfstat\fR(),
Packit 7cfc04
\fIlstat\fR(),
Packit 7cfc04
and
Packit 7cfc04
\fIstat\fR()
Packit 7cfc04
functions.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure, which shall include at least the following members:
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
dev_t st_dev            \fRDevice ID of device containing file.\fR
Packit 7cfc04
ino_t st_ino            \fRFile serial number.\fR
Packit 7cfc04
mode_t st_mode          \fRMode of file (see below).\fR
Packit 7cfc04
nlink_t st_nlink        \fRNumber of hard links to the file.\fR
Packit 7cfc04
uid_t st_uid            \fRUser ID of file.\fR
Packit 7cfc04
gid_t st_gid            \fRGroup ID of file.\fR
Packit 7cfc04
dev_t st_rdev           \fRDevice ID (if file is character or block special).\fR
Packit 7cfc04
off_t st_size           \fRFor regular files, the file size in bytes.\fR
Packit 7cfc04
                        \fRFor symbolic links, the length in bytes of the\fR
Packit 7cfc04
                        \fRpathname contained in the symbolic link.\fR
Packit 7cfc04
                        \fRFor a shared memory object, the length in bytes.\fR
Packit 7cfc04
                        \fRFor a typed memory object, the length in bytes.\fR
Packit 7cfc04
                        \fRFor other file types, the use of this field is\fR
Packit 7cfc04
                        \fRunspecified.\fR
Packit 7cfc04
struct timespec st_atim \fRLast data access timestamp.\fR
Packit 7cfc04
struct timespec st_mtim \fRLast data modification timestamp.\fR
Packit 7cfc04
struct timespec st_ctim \fRLast file status change timestamp.\fR
Packit 7cfc04
blksize_t st_blksize    \fRA file system-specific preferred I/O block size\fR
Packit 7cfc04
                        \fRfor this object. In some file system types, this\fR
Packit 7cfc04
                        \fRmay vary from file to file.\fR
Packit 7cfc04
blkcnt_t st_blocks      \fRNumber of blocks allocated for this object.\fR
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR st_ino
Packit 7cfc04
and
Packit 7cfc04
.IR st_dev
Packit 7cfc04
fields taken together uniquely identify the file within the system.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the
Packit 7cfc04
.BR blkcnt_t ,
Packit 7cfc04
.BR blksize_t ,
Packit 7cfc04
.BR dev_t ,
Packit 7cfc04
.BR ino_t ,
Packit 7cfc04
.BR mode_t ,
Packit 7cfc04
.BR nlink_t ,
Packit 7cfc04
.BR uid_t ,
Packit 7cfc04
.BR gid_t ,
Packit 7cfc04
.BR off_t ,
Packit 7cfc04
and
Packit 7cfc04
.BR time_t
Packit 7cfc04
types as described in
Packit 7cfc04
.IR <sys/types.h> .
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the
Packit 7cfc04
.BR timespec
Packit 7cfc04
structure as described in
Packit 7cfc04
.IR <time.h> .
Packit 7cfc04
Times shall be given in seconds since the Epoch.
Packit 7cfc04
.P
Packit 7cfc04
Which structure members have meaningful values depends on the
Packit 7cfc04
type of file. For further information, see the descriptions of
Packit 7cfc04
\fIfstat\fR(),
Packit 7cfc04
\fIlstat\fR(),
Packit 7cfc04
and
Packit 7cfc04
\fIstat\fR()
Packit 7cfc04
in the System Interfaces volume of POSIX.1\(hy2008.
Packit 7cfc04
.P
Packit 7cfc04
For compatibility with earlier versions of this standard, the
Packit 7cfc04
.IR st_atime
Packit 7cfc04
macro shall be defined with the value
Packit 7cfc04
.IR st_atim.tv_sec .
Packit 7cfc04
Similarly,
Packit 7cfc04
.IR st_ctime
Packit 7cfc04
and
Packit 7cfc04
.IR st_mtime
Packit 7cfc04
shall be defined as macros with the values
Packit 7cfc04
.IR st_ctim.tv_sec
Packit 7cfc04
and
Packit 7cfc04
.IR st_mtim.tv_sec ,
Packit 7cfc04
respectively.
Packit 7cfc04
.br
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the following symbolic constants for the
Packit 7cfc04
file types encoded in type
Packit 7cfc04
.BR mode_t .
Packit 7cfc04
The values shall be suitable for use in
Packit 7cfc04
.BR #if
Packit 7cfc04
preprocessing directives:
Packit 7cfc04
.IP S_IFMT 12
Packit 7cfc04
Type of file.
Packit 7cfc04
.RS 12 
Packit 7cfc04
.IP S_IFBLK 12
Packit 7cfc04
Block special.
Packit 7cfc04
.IP S_IFCHR 12
Packit 7cfc04
Character special.
Packit 7cfc04
.IP S_IFIFO 12
Packit 7cfc04
FIFO special.
Packit 7cfc04
.IP S_IFREG 12
Packit 7cfc04
Regular.
Packit 7cfc04
.IP S_IFDIR 12
Packit 7cfc04
Directory.
Packit 7cfc04
.IP S_IFLNK 12
Packit 7cfc04
Symbolic link.
Packit 7cfc04
.IP S_IFSOCK 12
Packit 7cfc04
Socket.
Packit 7cfc04
.RE
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the following symbolic constants for the file mode
Packit 7cfc04
bits encoded in type
Packit 7cfc04
.BR mode_t ,
Packit 7cfc04
with the indicated numeric values. These macros shall expand to an
Packit 7cfc04
expression which has a type that allows them to be used, either singly
Packit 7cfc04
or OR'ed together, as the third argument to
Packit 7cfc04
\fIopen\fR()
Packit 7cfc04
without the need for a
Packit 7cfc04
.BR mode_t
Packit 7cfc04
cast. The values shall be suitable for use in
Packit 7cfc04
.BR #if
Packit 7cfc04
preprocessing directives.
Packit 7cfc04
.TS
Packit 7cfc04
center box tab(@);
Packit 7cfc04
cB | cB | cB
Packit 7cfc04
l | n | l.
Packit 7cfc04
Name@Numeric Value@Description
Packit 7cfc04
_
Packit 7cfc04
S_IRWXU@0700@Read, write, execute/search by owner.
Packit 7cfc04
S_IRUSR@0400@Read permission, owner.
Packit 7cfc04
S_IWUSR@0200@Write permission, owner.
Packit 7cfc04
S_IXUSR@0100@Execute/search permission, owner.
Packit 7cfc04
_
Packit 7cfc04
S_IRWXG@070@Read, write, execute/search by group.
Packit 7cfc04
S_IRGRP@040@Read permission, group.
Packit 7cfc04
S_IWGRP@020@Write permission, group.
Packit 7cfc04
S_IXGRP@010@Execute/search permission, group.
Packit 7cfc04
_
Packit 7cfc04
S_IRWXO@07@Read, write, execute/search by others.
Packit 7cfc04
S_IROTH@04@Read permission, others.
Packit 7cfc04
S_IWOTH@02@Write permission, others.
Packit 7cfc04
S_IXOTH@01@Execute/search permission, others.
Packit 7cfc04
_
Packit 7cfc04
S_ISUID@04000@Set-user-ID on execution.
Packit 7cfc04
S_ISGID@02000@Set-group-ID on execution.
Packit 7cfc04
\*!S_ISVTX@01000@On directories, restricted deletion flag.\0\0\0\*?
Packit 7cfc04
.TE
Packit 7cfc04
.P
Packit 7cfc04
The following macros shall be provided to test whether a file is of the
Packit 7cfc04
specified type. The value
Packit 7cfc04
.IR m
Packit 7cfc04
supplied to the macros is the value of
Packit 7cfc04
.IR st_mode
Packit 7cfc04
from a
Packit 7cfc04
.BR stat
Packit 7cfc04
structure. The macro shall evaluate to a non-zero value if the test is
Packit 7cfc04
true; 0 if the test is false.
Packit 7cfc04
.IP "S_ISBLK(\fIm\fP)" 14
Packit 7cfc04
Test for a block special file.
Packit 7cfc04
.IP "S_ISCHR(\fIm\fP)" 14
Packit 7cfc04
Test for a character special file.
Packit 7cfc04
.IP "S_ISDIR(\fIm\fP)" 14
Packit 7cfc04
Test for a directory.
Packit 7cfc04
.IP "S_ISFIFO(\fIm\fP)" 14
Packit 7cfc04
Test for a pipe or FIFO special file.
Packit 7cfc04
.IP "S_ISREG(\fIm\fP)" 14
Packit 7cfc04
Test for a regular file.
Packit 7cfc04
.IP "S_ISLNK(\fIm\fP)" 14
Packit 7cfc04
Test for a symbolic link.
Packit 7cfc04
.IP "S_ISSOCK(\fIm\fP)" 14
Packit 7cfc04
Test for a socket.
Packit 7cfc04
.P
Packit 7cfc04
The implementation may implement message queues, semaphores, or shared
Packit 7cfc04
memory objects as distinct file types. The following macros shall be
Packit 7cfc04
provided to test whether a file is of the specified type. The value of
Packit 7cfc04
the
Packit 7cfc04
.IR buf
Packit 7cfc04
argument supplied to the macros is a pointer to a
Packit 7cfc04
.BR stat
Packit 7cfc04
structure. The macro shall evaluate to a non-zero value if the
Packit 7cfc04
specified object is implemented as a distinct file type and the
Packit 7cfc04
specified file type is contained in the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure referenced by
Packit 7cfc04
.IR buf .
Packit 7cfc04
Otherwise, the macro shall evaluate to zero.
Packit 7cfc04
.IP "S_TYPEISMQ(\fIbuf\fP)" 14
Packit 7cfc04
Test for a message queue.
Packit 7cfc04
.IP "S_TYPEISSEM(\fIbuf\fP)" 14
Packit 7cfc04
Test for a semaphore.
Packit 7cfc04
.IP "S_TYPEISSHM(\fIbuf\fP)" 14
Packit 7cfc04
Test for a shared memory object.
Packit 7cfc04
.P
Packit 7cfc04
The implementation may implement typed memory objects as distinct
Packit 7cfc04
file types, and the following macro shall test whether a file is of the
Packit 7cfc04
specified type. The value of the
Packit 7cfc04
.IR buf
Packit 7cfc04
argument supplied to the macros is a pointer to a
Packit 7cfc04
.BR stat
Packit 7cfc04
structure. The macro shall evaluate to a non-zero value if the
Packit 7cfc04
specified object is implemented as a distinct file type and the
Packit 7cfc04
specified file type is contained in the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure referenced by
Packit 7cfc04
.IR buf .
Packit 7cfc04
Otherwise, the macro shall evaluate to zero.
Packit 7cfc04
.IP "S_TYPEISTMO(\fIbuf\fP)" 14
Packit 7cfc04
Test macro for a typed memory object.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
header shall define the following symbolic constants as distinct
Packit 7cfc04
integer values outside of the range [0,999\|999\|999],
Packit 7cfc04
for use with the
Packit 7cfc04
\fIfutimens\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIutimensat\fR()
Packit 7cfc04
functions:
Packit 7cfc04
UTIME_NOW
Packit 7cfc04
UTIME_OMIT
Packit 7cfc04
.P
Packit 7cfc04
The following shall be declared as functions and may also be defined
Packit 7cfc04
as macros. Function prototypes shall be provided.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
int    chmod(const char *, mode_t);
Packit 7cfc04
int    fchmod(int, mode_t);
Packit 7cfc04
int    fchmodat(int, const char *, mode_t, int);
Packit 7cfc04
int    fstat(int, struct stat *);
Packit 7cfc04
int    fstatat(int, const char *restrict, struct stat *restrict, int);
Packit 7cfc04
int    futimens(int, const struct timespec [2]);
Packit 7cfc04
int    lstat(const char *restrict, struct stat *restrict);
Packit 7cfc04
int    mkdir(const char *, mode_t);
Packit 7cfc04
int    mkdirat(int, const char *, mode_t);
Packit 7cfc04
int    mkfifo(const char *, mode_t);
Packit 7cfc04
int    mkfifoat(int, const char *, mode_t);
Packit 7cfc04
int    mknod(const char *, mode_t, dev_t);
Packit 7cfc04
int    mknodat(int, const char *, mode_t, dev_t);
Packit 7cfc04
int    stat(const char *restrict, struct stat *restrict);
Packit 7cfc04
mode_t umask(mode_t);
Packit 7cfc04
int    utimensat(int, const char *, const struct timespec [2], int);
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
Use of the macros is recommended for determining the type of a file.
Packit 7cfc04
.SH RATIONALE
Packit 7cfc04
A conforming C-language application must include
Packit 7cfc04
.IR <sys/stat.h> 
Packit 7cfc04
for functions that have arguments or return values of type
Packit 7cfc04
.BR mode_t ,
Packit 7cfc04
so that symbolic values for that type can be used. An alternative
Packit 7cfc04
would be to require that these constants are also defined by including
Packit 7cfc04
.IR <sys/types.h> .
Packit 7cfc04
.P
Packit 7cfc04
The S_ISUID and S_ISGID
Packit 7cfc04
bits may be cleared on any write, not just on
Packit 7cfc04
\fIopen\fR(),
Packit 7cfc04
as some historical implementations do.
Packit 7cfc04
.P
Packit 7cfc04
System calls that update the time entry fields in the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure must be documented by the implementors. POSIX-conforming
Packit 7cfc04
systems should not update the time entry fields for functions listed in
Packit 7cfc04
the System Interfaces volume of POSIX.1\(hy2008 unless the standard requires that they do, except in the case
Packit 7cfc04
of documented extensions to the standard.
Packit 7cfc04
.P
Packit 7cfc04
Upon assignment, file timestamps are immediately converted to the
Packit 7cfc04
resolution of the file system by truncation (i.e., the recorded time
Packit 7cfc04
can be older than the actual time). For example, if the file system
Packit 7cfc04
resolution is 1 microsecond, then a conforming
Packit 7cfc04
\fIstat\fR()
Packit 7cfc04
must always return an
Packit 7cfc04
.IR st_mtim.tv_nsec
Packit 7cfc04
that is a multiple of 1000. Some older implementations returned
Packit 7cfc04
higher-resolution timestamps while the
Packit 7cfc04
.IR inode
Packit 7cfc04
information was cached, and then spontaneously truncated the
Packit 7cfc04
.IR tv_nsec
Packit 7cfc04
fields when they were stored to and retrieved from disk, but this behavior
Packit 7cfc04
does not conform.
Packit 7cfc04
.P
Packit 7cfc04
Note that
Packit 7cfc04
.IR st_dev
Packit 7cfc04
must be unique within a Local Area Network (LAN) in a ``system'' made
Packit 7cfc04
up of multiple computers' file systems connected by a LAN.
Packit 7cfc04
.P
Packit 7cfc04
Networked implementations of a POSIX-conforming system must guarantee
Packit 7cfc04
that all files visible within the file tree (including parts of the
Packit 7cfc04
tree that may be remotely mounted from other machines on the network)
Packit 7cfc04
on each individual processor are uniquely identified by the combination
Packit 7cfc04
of the
Packit 7cfc04
.IR st_ino
Packit 7cfc04
and
Packit 7cfc04
.IR st_dev
Packit 7cfc04
fields.
Packit 7cfc04
.P
Packit 7cfc04
The unit for the
Packit 7cfc04
.IR st_blocks
Packit 7cfc04
member of the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure is not defined within POSIX.1\(hy2008. In some implementations
Packit 7cfc04
it is 512 bytes. It may differ on a file system basis. There is no
Packit 7cfc04
correlation between values of the
Packit 7cfc04
.IR st_blocks
Packit 7cfc04
and
Packit 7cfc04
.IR st_blksize ,
Packit 7cfc04
and the
Packit 7cfc04
.IR f_bsize
Packit 7cfc04
(from
Packit 7cfc04
.IR <sys/statvfs.h> )
Packit 7cfc04
structure members.
Packit 7cfc04
.P
Packit 7cfc04
Traditionally, some implementations defined the multiplier for
Packit 7cfc04
.IR st_blocks
Packit 7cfc04
in
Packit 7cfc04
.IR <sys/param.h> 
Packit 7cfc04
as the symbol DEV_BSIZE.
Packit 7cfc04
.P
Packit 7cfc04
Some earlier versions of this standard did not specify values for the
Packit 7cfc04
file mode bit macros. The expectation was that some implementors might
Packit 7cfc04
choose to use a different encoding for these bits than the traditional
Packit 7cfc04
one, and that new applications would use symbolic file modes instead of
Packit 7cfc04
numeric. This version of the standard specifies the traditional encoding,
Packit 7cfc04
in recognition that nearly 20 years after the first publication of this
Packit 7cfc04
standard numeric file modes are still in widespread use by application
Packit 7cfc04
developers, and that all conforming implementations still use the
Packit 7cfc04
traditional encoding.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
No new S_IFMT symbolic names for the file type values of
Packit 7cfc04
.BR mode_t
Packit 7cfc04
will be defined by POSIX.1\(hy2008; if new file types are required, they will
Packit 7cfc04
only be testable through
Packit 7cfc04
.IR S_ISxx (\|)
Packit 7cfc04
or
Packit 7cfc04
.IR S_TYPEISxxx (\|)
Packit 7cfc04
macros instead.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "\fB<sys_statvfs.h>\fP",
Packit 7cfc04
.IR "\fB<sys_types.h>\fP",
Packit 7cfc04
.IR "\fB<time.h>\fP"
Packit 7cfc04
.P
Packit 7cfc04
The System Interfaces volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "\fIchmod\fR\^(\|)",
Packit 7cfc04
.IR "\fIfchmod\fR\^(\|)",
Packit 7cfc04
.IR "\fIfstat\fR\^(\|)",
Packit 7cfc04
.IR "\fIfstatat\fR\^(\|)",
Packit 7cfc04
.IR "\fIfutimens\fR\^(\|)",
Packit 7cfc04
.IR "\fImkdir\fR\^(\|)",
Packit 7cfc04
.IR "\fImkfifo\fR\^(\|)",
Packit 7cfc04
.IR "\fImknod\fR\^(\|)",
Packit 7cfc04
.IR "\fIumask\fR\^(\|)"
Packit 7cfc04
.SH COPYRIGHT
Packit 7cfc04
Portions of this text are reprinted and reproduced in electronic form
Packit 7cfc04
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
Packit 7cfc04
-- Portable Operating System Interface (POSIX), The Open Group Base
Packit 7cfc04
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Packit 7cfc04
Electrical and Electronics Engineers, Inc and The Open Group.
Packit 7cfc04
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
Packit 7cfc04
event of any discrepancy between this version and the original IEEE and
Packit 7cfc04
The Open Group Standard, the original IEEE and The Open Group Standard
Packit 7cfc04
is the referee document. The original Standard can be obtained online at
Packit 7cfc04
http://www.unix.org/online.html .
Packit 7cfc04
Packit 7cfc04
Any typographical or formatting errors that appear
Packit 7cfc04
in this page are most likely
Packit 7cfc04
to have been introduced during the conversion of the source files to
Packit 7cfc04
man page format. To report such errors, see
Packit 7cfc04
https://www.kernel.org/doc/man-pages/reporting_bugs.html .