man-pages/man2/stat.2.html
2021-03-31 01:06:50 +01:00

990 lines
24 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of STAT</TITLE>
</HEAD><BODY>
<H1>STAT</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
stat, fstat, lstat, fstatat - get file status
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<B>int stat(const char *</B><I>pathname</I><B>, struct stat *</B><I>statbuf</I><B>);</B>
<B>int fstat(int </B><I>fd</I><B>, struct stat *</B><I>statbuf</I><B>);</B>
<B>int lstat(const char *</B><I>pathname</I><B>, struct stat *</B><I>statbuf</I><B>);</B>
<B>#include &lt;<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>&gt; </B>/* Definition of AT_* constants */
<B>#include &lt;<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>&gt;</B>
<B>int fstatat(int </B><I>dirfd</I><B>, const char *</B><I>pathname</I><B>, struct stat *</B><I>statbuf</I><B>,</B>
<B> int </B><I>flags</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>lstat</B>():
<DL COMPACT><DT id="1"><DD>
/* glibc 2.19 and earlier */ _BSD_SOURCE
<BR>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.20&nbsp;*/&nbsp;_DEFAULT_SOURCE
<BR>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
<BR>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.10:&nbsp;*/&nbsp;_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
</DL>
<P>
<B>fstatat</B>():
<DL COMPACT><DT id="2"><DD>
<DL COMPACT>
<DT id="3">Since glibc 2.10:<DD>
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200809L
<DT id="4">Before glibc 2.10:<DD>
_ATFILE_SOURCE
</DL>
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
These functions return information about a file, in the buffer pointed to by
<I>statbuf</I>.
No permissions are required on the file itself, but---in the case of
<B>stat</B>(),
<B>fstatat</B>(),
and
<B>lstat</B>()---execute
(search) permission is required on all of the directories in
<I>pathname</I>
that lead to the file.
<P>
<B>stat</B>()
and
<B>fstatat</B>()
retrieve information about the file pointed to by
<I>pathname</I>;
the differences for
<B>fstatat</B>()
are described below.
<P>
<B>lstat</B>()
is identical to
<B>stat</B>(),
except that if
<I>pathname</I>
is a symbolic link, then it returns information about the link itself,
not the file that it refers to.
<P>
<B>fstat</B>()
is identical to
<B>stat</B>(),
except that the file about which information is to be retrieved
is specified by the file descriptor
<I>fd</I>.
<A NAME="lbAE">&nbsp;</A>
<H3>The stat structure</H3>
All of these system calls return a
<I>stat</I>
structure, which contains the following fields:
<P>
struct stat {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;dev_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_dev;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;ID&nbsp;of&nbsp;device&nbsp;containing&nbsp;file&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;ino_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_ino;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Inode&nbsp;number&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;mode_t&nbsp;&nbsp;&nbsp;&nbsp;st_mode;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;File&nbsp;type&nbsp;and&nbsp;mode&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;nlink_t&nbsp;&nbsp;&nbsp;st_nlink;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Number&nbsp;of&nbsp;hard&nbsp;links&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uid_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_uid;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;User&nbsp;ID&nbsp;of&nbsp;owner&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;gid_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_gid;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Group&nbsp;ID&nbsp;of&nbsp;owner&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;dev_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_rdev;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Device&nbsp;ID&nbsp;(if&nbsp;special&nbsp;file)&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;off_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;st_size;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Total&nbsp;size,&nbsp;in&nbsp;bytes&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;blksize_t&nbsp;st_blksize;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Block&nbsp;size&nbsp;for&nbsp;filesystem&nbsp;I/O&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;blkcnt_t&nbsp;&nbsp;st_blocks;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Number&nbsp;of&nbsp;512B&nbsp;blocks&nbsp;allocated&nbsp;*/
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Since&nbsp;Linux&nbsp;2.6,&nbsp;the&nbsp;kernel&nbsp;supports&nbsp;nanosecond
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;precision&nbsp;for&nbsp;the&nbsp;following&nbsp;timestamp&nbsp;fields.
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;the&nbsp;details&nbsp;before&nbsp;Linux&nbsp;2.6,&nbsp;see&nbsp;NOTES.&nbsp;*/
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;timespec&nbsp;st_atim;&nbsp;&nbsp;/*&nbsp;Time&nbsp;of&nbsp;last&nbsp;access&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;timespec&nbsp;st_mtim;&nbsp;&nbsp;/*&nbsp;Time&nbsp;of&nbsp;last&nbsp;modification&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;timespec&nbsp;st_ctim;&nbsp;&nbsp;/*&nbsp;Time&nbsp;of&nbsp;last&nbsp;status&nbsp;change&nbsp;*/
<P>
#define st_atime st_atim.tv_sec /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
};
<P>
<I>Note</I>:
the order of fields in the
<I>stat</I>
structure varies somewhat
across architectures.
In addition,
the definition above does not show the padding bytes
that may be present between some fields on various architectures.
Consult the glibc and kernel source code
if you need to know the details.
<P>
<I>Note</I>:
for performance and simplicity reasons, different fields in the
<I>stat</I>
structure may contain state information from different moments
during the execution of the system call.
For example, if
<I>st_mode</I>
or
<I>st_uid</I>
is changed by another process by calling
<B><A HREF="/cgi-bin/man/man2html?2+chmod">chmod</A></B>(2)
or
<B><A HREF="/cgi-bin/man/man2html?2+chown">chown</A></B>(2),
<B>stat</B>()
might return the old
<I>st_mode</I>
together with the new
<I>st_uid</I>,
or the old
<I>st_uid</I>
together with the new
<I>st_mode</I>.
<P>
The fields in the
<I>stat</I>
structure are as follows:
<DL COMPACT>
<DT id="5"><I>st_dev</I>
<DD>
This field describes the device on which this file resides.
(The
<B><A HREF="/cgi-bin/man/man2html?3+major">major</A></B>(3)
and
<B><A HREF="/cgi-bin/man/man2html?3+minor">minor</A></B>(3)
macros may be useful to decompose the device ID in this field.)
<DT id="6"><I>st_ino</I>
<DD>
This field contains the file's inode number.
<DT id="7"><I>st_mode</I>
<DD>
This field contains the file type and mode.
See
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7)
for further information.
<DT id="8"><I>st_nlink</I>
<DD>
This field contains the number of hard links to the file.
<DT id="9"><I>st_uid</I>
<DD>
This field contains the user ID of the owner of the file.
<DT id="10"><I>st_gid</I>
<DD>
This field contains the ID of the group owner of the file.
<DT id="11"><I>st_rdev</I>
<DD>
This field describes the device that this file (inode) represents.
<DT id="12"><I>st_size</I>
<DD>
This field gives the size of the file (if it is a regular
file or a symbolic link) in bytes.
The size of a symbolic link is the length of the pathname
it contains, without a terminating null byte.
<DT id="13"><I>st_blksize</I>
<DD>
This field gives the &quot;preferred&quot; block size for efficient filesystem I/O.
<DT id="14"><I>st_blocks</I>
<DD>
This field indicates the number of blocks allocated to the file,
in 512-byte units.
(This may be smaller than
<I>st_size</I>/512
when the file has holes.)
<DT id="15"><I>st_atime</I>
<DD>
This is the file's last access timestamp.
<DT id="16"><I>st_mtime</I>
<DD>
This is the file's last modification timestamp.
<DT id="17"><I>st_ctime</I>
<DD>
This is the file's last status change timestamp.
</DL>
<P>
For further information on the above fields, see
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7).
<A NAME="lbAF">&nbsp;</A>
<H3>fstatat()</H3>
The
<B>fstatat</B>()
system call is a more general interface for accessing file information
which can still provide exactly the behavior of each of
<B>stat</B>(),
<B>lstat</B>(),
and
<B>fstat</B>().
<P>
If the pathname given in
<I>pathname</I>
is relative, then it is interpreted relative to the directory
referred to by the file descriptor
<I>dirfd</I>
(rather than relative to the current working directory of
the calling process, as is done by
<B>stat</B>()
and
<B>lstat</B>()
for a relative pathname).
<P>
If
<I>pathname</I>
is relative and
<I>dirfd</I>
is the special value
<B>AT_FDCWD</B>,
then
<I>pathname</I>
is interpreted relative to the current working
directory of the calling process (like
<B>stat</B>()
and
<B>lstat</B>()).
<P>
If
<I>pathname</I>
is absolute, then
<I>dirfd</I>
is ignored.
<P>
<I>flags</I>
can either be 0, or include one or more of the following flags ORed:
<DL COMPACT>
<DT id="18"><B>AT_EMPTY_PATH</B> (since Linux 2.6.39)
<DD>
If
<I>pathname</I>
is an empty string, operate on the file referred to by
<I>dirfd</I>
(which may have been obtained using the
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2)
<B>O_PATH</B>
flag).
In this case,
<I>dirfd</I>
can refer to any type of file, not just a directory, and
the behavior of
<B>fstatat</B>()
is similar to that of
<B>fstat</B>().
If
<I>dirfd</I>
is
<B>AT_FDCWD</B>,
the call operates on the current working directory.
This flag is Linux-specific; define
<B>_GNU_SOURCE</B>
to obtain its definition.
<DT id="19"><B>AT_NO_AUTOMOUNT</B> (since Linux 2.6.38)
<DD>
Don't automount the terminal (&quot;basename&quot;) component of
<I>pathname</I>
if it is a directory that is an automount point.
This allows the caller to gather attributes of an automount point
(rather than the location it would mount).
Since Linux 4.14,
also don't instantiate a nonexistent name in an
on-demand directory such as used for automounter indirect maps.
This flag can be used in tools that scan directories
to prevent mass-automounting of a directory of automount points.
The
<B>AT_NO_AUTOMOUNT</B>
flag has no effect if the mount point has already been mounted over.
This flag is Linux-specific; define
<B>_GNU_SOURCE</B>
to obtain its definition.
Both
<B>stat</B>()
and
<B>lstat</B>()
act as though
<B>AT_NO_AUTOMOUNT</B>
was set.
<DT id="20"><B>AT_SYMLINK_NOFOLLOW</B>
<DD>
If
<I>pathname</I>
is a symbolic link, do not dereference it:
instead return information about the link itself, like
<B>lstat</B>().
(By default,
<B>fstatat</B>()
dereferences symbolic links, like
<B>stat</B>().)
</DL>
<P>
See
<B><A HREF="/cgi-bin/man/man2html?2+openat">openat</A></B>(2)
for an explanation of the need for
<B>fstatat</B>().
<A NAME="lbAG">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAH">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="21"><B>EACCES</B>
<DD>
Search permission is denied for one of the directories
in the path prefix of
<I>pathname</I>.
(See also
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
<DT id="22"><B>EBADF</B>
<DD>
<I>fd</I>
is not a valid open file descriptor.
<DT id="23"><B>EFAULT</B>
<DD>
Bad address.
<DT id="24"><B>ELOOP</B>
<DD>
Too many symbolic links encountered while traversing the path.
<DT id="25"><B>ENAMETOOLONG</B>
<DD>
<I>pathname</I>
is too long.
<DT id="26"><B>ENOENT</B>
<DD>
A component of
<I>pathname</I>
does not exist or is a dangling symbolic link.
<DT id="27"><B>ENOENT</B>
<DD>
<I>pathname</I>
is an empty string and
<B>AT_EMPTY_PATH</B>
was not specified in
<I>flags</I>.
<DT id="28"><B>ENOMEM</B>
<DD>
Out of memory (i.e., kernel memory).
<DT id="29"><B>ENOTDIR</B>
<DD>
A component of the path prefix of
<I>pathname</I>
is not a directory.
<DT id="30"><B>EOVERFLOW</B>
<DD>
<I>pathname</I>
or
<I>fd</I>
refers to a file whose size, inode number,
or number of blocks cannot be represented in, respectively, the types
<I>off_t</I>,
<I>ino_t</I>,
or
<I>blkcnt_t</I>.
This error can occur when, for example,
an application compiled on a 32-bit platform without
<I>-D_FILE_OFFSET_BITS=64</I>
calls
<B>stat</B>()
on a file whose size exceeds
<I>(1&lt;&lt;31)-1</I>
bytes.
</DL>
<P>
The following additional errors can occur for
<B>fstatat</B>():
<DL COMPACT>
<DT id="31"><B>EBADF</B>
<DD>
<I>dirfd</I>
is not a valid file descriptor.
<DT id="32"><B>EINVAL</B>
<DD>
Invalid flag specified in
<I>flags</I>.
<DT id="33"><B>ENOTDIR</B>
<DD>
<I>pathname</I>
is relative and
<I>dirfd</I>
is a file descriptor referring to a file other than a directory.
</DL>
<A NAME="lbAI">&nbsp;</A>
<H2>VERSIONS</H2>
<B>fstatat</B>()
was added to Linux in kernel 2.6.16;
library support was added to glibc in version 2.4.
<A NAME="lbAJ">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>stat</B>(),
<B>fstat</B>(),
<B>lstat</B>():
SVr4, 4.3BSD, POSIX.1-2001, POSIX.1.2008.
<P>
<B>fstatat</B>():
POSIX.1-2008.
<P>
According to POSIX.1-2001,
<B>lstat</B>()
on a symbolic link need return valid information only in the
<I>st_size</I>
field and the file type of the
<I>st_mode</I>
field of the
<I>stat</I>
structure.
POSIX.1-2008 tightens the specification, requiring
<B>lstat</B>()
to return valid information in all fields except the mode bits in
<I>st_mode</I>.
<P>
Use of the
<I>st_blocks</I>
and
<I>st_blksize</I>
fields may be less portable.
(They were introduced in BSD.
The interpretation differs between systems,
and possibly on a single system when NFS mounts are involved.)
<A NAME="lbAK">&nbsp;</A>
<H2>NOTES</H2>
<A NAME="lbAL">&nbsp;</A>
<H3>Timestamp fields</H3>
Older kernels and older standards did not support nanosecond timestamp
fields.
Instead, there were three timestamp
fields---<I>st_atime</I>,
<I>st_mtime</I>,
and
<I>st_ctime</I>---typed
as
<I>time_t</I>
that recorded timestamps with one-second precision.
<P>
Since kernel 2.5.48, the
<I>stat</I>
structure supports nanosecond resolution for the three file timestamp fields.
The nanosecond components of each timestamp are available
via names of the form
<I>st_atim.tv_nsec</I>,
if suitable feature test macros are defined.
Nanosecond timestamps were standardized in POSIX.1-2008,
and, starting with version 2.12,
glibc exposes the nanosecond component names if
<B>_POSIX_C_SOURCE</B>
is defined with the value 200809L or greater, or
<B>_XOPEN_SOURCE</B>
is defined with the value 700 or greater.
Up to and including glibc 2.19,
the definitions of the nanoseconds components are also defined if
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
is defined.
If none of the aforementioned macros are defined,
then the nanosecond values are exposed with names of the form
<I>st_atimensec</I>.
<A NAME="lbAM">&nbsp;</A>
<H3>C library/kernel differences</H3>
Over time, increases in the size of the
<I>stat</I>
structure have led to three successive versions of
<B>stat</B>():
<I>sys_stat</I>()
(slot
<I>__NR_oldstat</I>),
<I>sys_newstat</I>()
(slot
<I>__NR_stat</I>),
and
<I>sys_stat64()</I>
(slot
<I>__NR_stat64</I>)
on 32-bit platforms such as i386.
The first two versions were already present in Linux 1.0
(albeit with different names);
the last was added in Linux 2.4.
Similar remarks apply for
<B>fstat</B>()
and
<B>lstat</B>().
<P>
The kernel-internal versions of the
<I>stat</I>
structure dealt with by the different versions are, respectively:
<DL COMPACT>
<DT id="34"><I>__old_kernel_stat</I>
<DD>
The original structure, with rather narrow fields, and no padding.
<DT id="35"><I>stat</I>
<DD>
Larger
<I>st_ino</I>
field and padding added to various parts of the structure to
allow for future expansion.
<DT id="36"><I>stat64</I>
<DD>
Even larger
<I>st_ino</I>
field,
larger
<I>st_uid</I>
and
<I>st_gid</I>
fields to accommodate the Linux-2.4 expansion of UIDs and GIDs to 32 bits,
and various other enlarged fields and further padding in the structure.
(Various padding bytes were eventually consumed in Linux 2.6,
with the advent of 32-bit device IDs and nanosecond components
for the timestamp fields.)
</DL>
<P>
The glibc
<B>stat</B>()
wrapper function hides these details from applications,
invoking the most recent version of the system call provided by the kernel,
and repacking the returned information if required for old binaries.
<P>
On modern 64-bit systems, life is simpler: there is a single
<B>stat</B>()
system call and the kernel deals with a
<I>stat</I>
structure that contains fields of a sufficient size.
<P>
The underlying system call employed by the glibc
<B>fstatat</B>()
wrapper function is actually called
<B>fstatat64</B>()
or, on some architectures,
<B>newfstatat</B>().
<A NAME="lbAN">&nbsp;</A>
<H2>EXAMPLE</H2>
The following program calls
<B>lstat</B>()
and displays selected fields in the returned
<I>stat</I>
structure.
<P>
#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/time.h">time.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/sys/sysmacros.h">sys/sysmacros.h</A>&gt;
<P>
int
main(int argc, char *argv[])
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;struct&nbsp;stat&nbsp;sb;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(argc&nbsp;!=&nbsp;2)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;&quot;Usage:&nbsp;%s&nbsp;&lt;pathname&gt;\n&quot;,&nbsp;argv[0]);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_FAILURE);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(lstat(argv[1],&nbsp;&amp;sb)&nbsp;==&nbsp;-1)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(&quot;lstat&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_FAILURE);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;ID&nbsp;of&nbsp;containing&nbsp;device:&nbsp;&nbsp;[%lx,%lx]\n&quot;,
<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TT> (long) major(sb.st_dev), (long) minor(sb.st_dev));<BR>
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;File&nbsp;type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(sb.st_mode&nbsp;&amp;&nbsp;S_IFMT)&nbsp;{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFBLK:&nbsp;&nbsp;printf(&quot;block&nbsp;device\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFCHR:&nbsp;&nbsp;printf(&quot;character&nbsp;device\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFDIR:&nbsp;&nbsp;printf(&quot;directory\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFIFO:&nbsp;&nbsp;printf(&quot;FIFO/pipe\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFLNK:&nbsp;&nbsp;printf(&quot;symlink\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFREG:&nbsp;&nbsp;printf(&quot;regular&nbsp;file\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;S_IFSOCK:&nbsp;printf(&quot;socket\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;unknown?\n&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;I-node&nbsp;number:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%ld\n&quot;,&nbsp;(long)&nbsp;sb.st_ino);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Mode:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%lo&nbsp;(octal)\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(unsigned&nbsp;long)&nbsp;sb.st_mode);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Link&nbsp;count:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%ld\n&quot;,&nbsp;(long)&nbsp;sb.st_nlink);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Ownership:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UID=%ld&nbsp;&nbsp;&nbsp;GID=%ld\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(long)&nbsp;sb.st_uid,&nbsp;(long)&nbsp;sb.st_gid);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Preferred&nbsp;I/O&nbsp;block&nbsp;size:&nbsp;%ld&nbsp;bytes\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(long)&nbsp;sb.st_blksize);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;File&nbsp;size:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%lld&nbsp;bytes\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(long&nbsp;long)&nbsp;sb.st_size);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Blocks&nbsp;allocated:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%lld\n&quot;,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(long&nbsp;long)&nbsp;sb.st_blocks);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Last&nbsp;status&nbsp;change:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s&quot;,&nbsp;ctime(&amp;sb.st_ctime));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Last&nbsp;file&nbsp;access:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s&quot;,&nbsp;ctime(&amp;sb.st_atime));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Last&nbsp;file&nbsp;modification:&nbsp;&nbsp;&nbsp;%s&quot;,&nbsp;ctime(&amp;sb.st_mtime));
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAO">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+ls">ls</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+stat">stat</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+access">access</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+chmod">chmod</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+chown">chown</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+readlink">readlink</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+statx">statx</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+utime">utime</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+symlink">symlink</A></B>(7)
<A NAME="lbAP">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="37"><A HREF="#lbAB">NAME</A><DD>
<DT id="38"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="39"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="40"><A HREF="#lbAE">The stat structure</A><DD>
<DT id="41"><A HREF="#lbAF">fstatat()</A><DD>
</DL>
<DT id="42"><A HREF="#lbAG">RETURN VALUE</A><DD>
<DT id="43"><A HREF="#lbAH">ERRORS</A><DD>
<DT id="44"><A HREF="#lbAI">VERSIONS</A><DD>
<DT id="45"><A HREF="#lbAJ">CONFORMING TO</A><DD>
<DT id="46"><A HREF="#lbAK">NOTES</A><DD>
<DL>
<DT id="47"><A HREF="#lbAL">Timestamp fields</A><DD>
<DT id="48"><A HREF="#lbAM">C library/kernel differences</A><DD>
</DL>
<DT id="49"><A HREF="#lbAN">EXAMPLE</A><DD>
<DT id="50"><A HREF="#lbAO">SEE ALSO</A><DD>
<DT id="51"><A HREF="#lbAP">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:34 GMT, March 31, 2021
</BODY>
</HTML>