Blame SOURCES/1452424-mpo-7.4.2-stat.2.patch

5a015b
From f14d3a310dbaf5456e5267ee56d2b35a78ec540b Mon Sep 17 00:00:00 2001
5a015b
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
5a015b
Date: Mon, 22 May 2017 14:54:07 +0200
5a015b
Subject: [PATCH 2/2] stat.2: update to cover latest things used in RHEL 7
5a015b
5a015b
---
5a015b
 man-pages/man2/stat.2 | 760 +++++++++++++++++++++++++++++++++++---------------
5a015b
 1 file changed, 540 insertions(+), 220 deletions(-)
5a015b
5a015b
diff --git a/man-pages/man2/stat.2 b/man-pages/man2/stat.2
5a015b
index c86ebc0..f108020 100644
5a015b
--- a/man-pages/man2/stat.2
5a015b
+++ b/man-pages/man2/stat.2
5a015b
@@ -1,7 +1,7 @@
5a015b
 '\" t
5a015b
 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
5a015b
 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
5a015b
-.\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
5a015b
+.\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
5a015b
 .\"
5a015b
 .\" %%%LICENSE_START(VERBATIM)
5a015b
 .\" Permission is granted to make and distribute verbatim copies of this
5a015b
@@ -37,21 +37,30 @@
5a015b
 .\" 2007-06-08 mtk: Added example program
5a015b
 .\" 2007-07-05 mtk: Added details on underlying system call interfaces
5a015b
 .\"
5a015b
-.TH STAT 2 2012-11-11 "Linux" "Linux Programmer's Manual"
5a015b
+.TH STAT 2 2017-03-13 "Linux" "Linux Programmer's Manual"
5a015b
 .SH NAME
5a015b
-stat, fstat, lstat \- get file status
5a015b
+stat, fstat, lstat, fstatat \- get file status
5a015b
 .SH SYNOPSIS
5a015b
+.nf
5a015b
 .B #include <sys/types.h>
5a015b
 .br
5a015b
 .B #include <sys/stat.h>
5a015b
 .br
5a015b
 .B #include <unistd.h>
5a015b
 .sp
5a015b
-.BI "int stat(const char *" path ", struct stat *" buf );
5a015b
+.BI "int stat(const char *" pathname ", struct stat *" buf );
5a015b
 .br
5a015b
 .BI "int fstat(int " fd ", struct stat *" buf );
5a015b
 .br
5a015b
-.BI "int lstat(const char *" path ", struct stat *" buf );
5a015b
+.BI "int lstat(const char *" pathname ", struct stat *" buf );
5a015b
+.sp
5a015b
+.BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
5a015b
+.B #include <sys/stat.h>
5a015b
+.sp
5a015b
+.BI "int fstatat(int " dirfd ", const char *" pathname ", struct stat *" \
5a015b
+buf ,
5a015b
+.BI "            int " flags );
5a015b
+.fi
5a015b
 .sp
5a015b
 .in -4n
5a015b
 Feature Test Macro Requirements for glibc (see
5a015b
@@ -62,45 +71,67 @@ Feature Test Macro Requirements for glibc (see
5a015b
 .sp
5a015b
 .BR lstat ():
5a015b
 .RS 4
5a015b
-_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
5a015b
-_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
5a015b
+/* glibc 2.19 and earlier */ _BSD_SOURCE
5a015b
+.br
5a015b
+    || /* Since glibc 2.20 */ _DEFAULT_SOURCE
5a015b
 .br
5a015b
-|| /* Since glibc 2.10: */ _POSIX_C_SOURCE\ >=\ 200112L
5a015b
+    || _XOPEN_SOURCE\ >=\ 500
5a015b
+.\"   _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
5a015b
+.br
5a015b
+    || /* Since glibc 2.10: */ _POSIX_C_SOURCE\ >=\ 200112L
5a015b
+.RE
5a015b
+.sp
5a015b
+.BR fstatat ():
5a015b
+.PD 0
5a015b
+.ad l
5a015b
+.RS 4
5a015b
+.TP 4
5a015b
+Since glibc 2.10:
5a015b
+_POSIX_C_SOURCE\ >=\ 200809L
5a015b
+.TP
5a015b
+Before glibc 2.10:
5a015b
+_ATFILE_SOURCE
5a015b
 .RE
5a015b
 .PD
5a015b
 .ad
5a015b
 .SH DESCRIPTION
5a015b
 .PP
5a015b
-These functions return information about a file.
5a015b
+These functions return information about a file, in the buffer pointed to by
5a015b
+.IR buf .
5a015b
 No permissions are required on the file itself, but\(emin the case of
5a015b
-.BR stat ()
5a015b
+.BR stat (),
5a015b
+.BR fstatat (),
5a015b
 and
5a015b
-.BR lstat ()
5a015b
-\(em
5a015b
-execute (search) permission is required on all of the directories in
5a015b
-.I path
5a015b
+.BR lstat ()\(emexecute
5a015b
+(search) permission is required on all of the directories in
5a015b
+.I pathname
5a015b
 that lead to the file.
5a015b
 .PP
5a015b
 .BR stat ()
5a015b
-stats the file pointed to by
5a015b
-.I path
5a015b
-and fills in
5a015b
-.IR buf .
5a015b
+and
5a015b
+.BR fstatat ()
5a015b
+retrieve information about the file pointed to by
5a015b
+.IR pathname ;
5a015b
+the differences for
5a015b
+.BR fstatat ()
5a015b
+are described below.
5a015b
 
5a015b
 .BR lstat ()
5a015b
 is identical to
5a015b
 .BR stat (),
5a015b
 except that if
5a015b
-.I path
5a015b
-is a symbolic link, then the link itself is stat-ed,
5a015b
+.I pathname
5a015b
+is a symbolic link, then it returns information about the link itself,
5a015b
 not the file that it refers to.
5a015b
 
5a015b
 .BR fstat ()
5a015b
 is identical to
5a015b
 .BR stat (),
5a015b
-except that the file to be stat-ed is specified by the file descriptor
5a015b
+except that the file about which information is to be retrieved
5a015b
+is specified by the file descriptor
5a015b
 .IR fd .
5a015b
-.PP
5a015b
+.\"
5a015b
+.SS The stat structure
5a015b
 All of these system calls return a
5a015b
 .I stat
5a015b
 structure, which contains the following fields:
5a015b
@@ -108,84 +139,123 @@ structure, which contains the following fields:
5a015b
 .in +4n
5a015b
 .nf
5a015b
 struct stat {
5a015b
-    dev_t     st_dev;     /* ID of device containing file */
5a015b
-    ino_t     st_ino;     /* inode number */
5a015b
-    mode_t    st_mode;    /* protection */
5a015b
-    nlink_t   st_nlink;   /* number of hard links */
5a015b
-    uid_t     st_uid;     /* user ID of owner */
5a015b
-    gid_t     st_gid;     /* group ID of owner */
5a015b
-    dev_t     st_rdev;    /* device ID (if special file) */
5a015b
-    off_t     st_size;    /* total size, in bytes */
5a015b
-    blksize_t st_blksize; /* blocksize for file system I/O */
5a015b
-    blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
5a015b
-    time_t    st_atime;   /* time of last access */
5a015b
-    time_t    st_mtime;   /* time of last modification */
5a015b
-    time_t    st_ctime;   /* time of last status change */
5a015b
+    dev_t     st_dev;         /* ID of device containing file */
5a015b
+    ino_t     st_ino;         /* inode number */
5a015b
+    mode_t    st_mode;        /* file type and mode */
5a015b
+    nlink_t   st_nlink;       /* number of hard links */
5a015b
+    uid_t     st_uid;         /* user ID of owner */
5a015b
+    gid_t     st_gid;         /* group ID of owner */
5a015b
+    dev_t     st_rdev;        /* device ID (if special file) */
5a015b
+    off_t     st_size;        /* total size, in bytes */
5a015b
+    blksize_t st_blksize;     /* blocksize for filesystem I/O */
5a015b
+    blkcnt_t  st_blocks;      /* number of 512B blocks allocated */
5a015b
+
5a015b
+    /* Since Linux 2.6, the kernel supports nanosecond
5a015b
+       precision for the following timestamp fields.
5a015b
+       For the details before Linux 2.6, see NOTES. */
5a015b
+
5a015b
+    struct timespec st_atim;  /* time of last access */
5a015b
+    struct timespec st_mtim;  /* time of last modification */
5a015b
+    struct timespec st_ctim;  /* time of last status change */
5a015b
+
5a015b
+#define st_atime st_atim.tv_sec      /* Backward compatibility */
5a015b
+#define st_mtime st_mtim.tv_sec
5a015b
+#define st_ctime st_ctim.tv_sec
5a015b
 };
5a015b
 .fi
5a015b
 .in
5a015b
-.PP
5a015b
-The
5a015b
+
5a015b
+.IR Note :
5a015b
+the order of fields in the
5a015b
+.I stat
5a015b
+structure varies somewhat
5a015b
+across architectures.
5a015b
+In addition,
5a015b
+the definition above does not show the padding bytes
5a015b
+that may be present between some fields on various architectures.
5a015b
+Consult the glibc and kernel source code
5a015b
+if you need to know the details.
5a015b
+
5a015b
+.\" Background: inode attributes are modified with i_mutex held, but
5a015b
+.\" read by stat() without taking the mutex.
5a015b
+.IR Note :
5a015b
+For performance and simplicity reasons, different fields in the
5a015b
+.I stat
5a015b
+structure may contain state information from different moments
5a015b
+during the execution of the system call.
5a015b
+For example, if
5a015b
+.IR st_mode
5a015b
+or
5a015b
+.IR st_uid
5a015b
+is changed by another process by calling
5a015b
+.BR chmod (2)
5a015b
+or
5a015b
+.BR chown (2),
5a015b
+.BR stat ()
5a015b
+might return the old
5a015b
+.I st_mode
5a015b
+together with the new
5a015b
+.IR st_uid ,
5a015b
+or the old
5a015b
+.I st_uid
5a015b
+together with the new
5a015b
+.IR st_mode .
5a015b
+
5a015b
+The fields in the
5a015b
+.I stat
5a015b
+structure are as follows:
5a015b
+.TP
5a015b
 .I st_dev
5a015b
-field describes the device on which this file resides.
5a015b
+This field describes the device on which this file resides.
5a015b
 (The
5a015b
 .BR major (3)
5a015b
 and
5a015b
 .BR minor (3)
5a015b
 macros may be useful to decompose the device ID in this field.)
5a015b
-
5a015b
-The
5a015b
+.TP
5a015b
+.I st_ino
5a015b
+This field contains the file's inode number.
5a015b
+.TP
5a015b
+.I st_mode
5a015b
+See the discussion of file type and mode, below.
5a015b
+.TP
5a015b
+.I st_nlink
5a015b
+This field contains the number of hard links to the file.
5a015b
+.TP
5a015b
+.I st_uid
5a015b
+This field contains the user ID of the owner of the file.
5a015b
+.TP
5a015b
+.I st_gid
5a015b
+This field contains the ID of the group owner of the file.
5a015b
+.TP
5a015b
 .I st_rdev
5a015b
-field describes the device that this file (inode) represents.
5a015b
-
5a015b
-The
5a015b
+This field describes the device that this file (inode) represents.
5a015b
+.TP
5a015b
 .I st_size
5a015b
-field gives the size of the file (if it is a regular
5a015b
+This field gives the size of the file (if it is a regular
5a015b
 file or a symbolic link) in bytes.
5a015b
 The size of a symbolic link is the length of the pathname
5a015b
 it contains, without a terminating null byte.
5a015b
-
5a015b
-The
5a015b
+.TP
5a015b
+.I st_blksize
5a015b
+This field gives the "preferred" blocksize for efficient filesystem I/O.
5a015b
+(Writing to a file in smaller chunks may cause
5a015b
+an inefficient read-modify-rewrite.)
5a015b
+.TP
5a015b
 .I st_blocks
5a015b
-field indicates the number of blocks allocated to the file, 512-byte units.
5a015b
+This field indicates the number of blocks allocated to the file,
5a015b
+512-byte units.
5a015b
 (This may be smaller than
5a015b
 .IR st_size /512
5a015b
 when the file has holes.)
5a015b
-
5a015b
-The
5a015b
-.I st_blksize
5a015b
-field gives the "preferred" blocksize for efficient file system I/O.
5a015b
-(Writing to a file in smaller chunks may cause
5a015b
-an inefficient read-modify-rewrite.)
5a015b
-.PP
5a015b
-Not all of the Linux file systems implement all of the time fields.
5a015b
-Some file system types allow mounting in such a way that file
5a015b
-and/or directory accesses do not cause an update of the
5a015b
-.I st_atime
5a015b
-field.
5a015b
-(See
5a015b
-.IR noatime ,
5a015b
-.IR nodiratime ,
5a015b
-and
5a015b
-.I relatime
5a015b
-in
5a015b
-.BR mount (8),
5a015b
-and related information in
5a015b
-.BR mount (2).)
5a015b
-In addition,
5a015b
-.I st_atime
5a015b
-is not updated if a file is opened with the
5a015b
-.BR O_NOATIME ;
5a015b
-see
5a015b
-.BR open (2).
5a015b
-
5a015b
-The field
5a015b
+.TP
5a015b
 .I st_atime
5a015b
-is changed by file accesses, for example, by
5a015b
+This is the file's last access timestamp.
5a015b
+It is changed by file accesses, for example, by
5a015b
 .BR execve (2),
5a015b
 .BR mknod (2),
5a015b
 .BR pipe (2),
5a015b
-.BR utime (2)
5a015b
+.BR utime (2),
5a015b
 and
5a015b
 .BR read (2)
5a015b
 (of more than zero bytes).
5a015b
@@ -193,13 +263,13 @@ Other routines, like
5a015b
 .BR mmap (2),
5a015b
 may or may not update
5a015b
 .IR st_atime .
5a015b
-
5a015b
-The field
5a015b
+.TP
5a015b
 .I st_mtime
5a015b
-is changed by file modifications, for example, by
5a015b
+This is the file's last modification timestamp.
5a015b
+It is changed by file modifications, for example, by
5a015b
 .BR mknod (2),
5a015b
 .BR truncate (2),
5a015b
-.BR utime (2)
5a015b
+.BR utime (2),
5a015b
 and
5a015b
 .BR write (2)
5a015b
 (of more than zero bytes).
5a015b
@@ -212,15 +282,78 @@ The
5a015b
 field is
5a015b
 .I not
5a015b
 changed for changes in owner, group, hard link count, or mode.
5a015b
-
5a015b
-The field
5a015b
+.TP
5a015b
 .I st_ctime
5a015b
-is changed by writing or by setting inode information
5a015b
+This is the file's last status change timestamp.
5a015b
+It is changed by writing or by setting inode information
5a015b
 (i.e., owner, group, link count, mode, etc.).
5a015b
 .PP
5a015b
-The following POSIX macros are defined to check the file type using the
5a015b
+Not all of the Linux filesystems implement all of the time fields.
5a015b
+Some filesystem types allow mounting in such a way that file
5a015b
+and/or directory accesses do not cause an update of the
5a015b
+.I st_atime
5a015b
+field.
5a015b
+(See
5a015b
+.IR noatime ,
5a015b
+.IR nodiratime ,
5a015b
+and
5a015b
+.I relatime
5a015b
+in
5a015b
+.BR mount (8),
5a015b
+and related information in
5a015b
+.BR mount (2).)
5a015b
+In addition,
5a015b
+.I st_atime
5a015b
+is not updated if a file is opened with the
5a015b
+.BR O_NOATIME
5a015b
+flag; see
5a015b
+.BR open (2).
5a015b
+.\"
5a015b
+.SS The file type and mode (st_mode)
5a015b
+POSIX refers to the
5a015b
+.I st_mode
5a015b
+bits corresponding to the mask
5a015b
+.B S_IFMT
5a015b
+(see below) as the
5a015b
+.IR "file type" ,
5a015b
+the 12 bits corresponding to the mask 07777 as the
5a015b
+.IR "file mode bits"
5a015b
+and the least significant 9 bits (0777) as the
5a015b
+.IR "file permission bits" .
5a015b
+.PP
5a015b
+The following mask values are defined for the file type of the
5a015b
 .I st_mode
5a015b
 field:
5a015b
+.in +4n
5a015b
+.TS
5a015b
+lB l l.
5a015b
+S_IFMT	0170000	bit mask for the file type bit field
5a015b
+
5a015b
+S_IFSOCK	0140000	socket
5a015b
+S_IFLNK	0120000	symbolic link
5a015b
+S_IFREG	0100000	regular file
5a015b
+S_IFBLK	0060000	block device
5a015b
+S_IFDIR	0040000	directory
5a015b
+S_IFCHR	0020000	character device
5a015b
+S_IFIFO	0010000	FIFO
5a015b
+.TE
5a015b
+.in
5a015b
+.PP
5a015b
+Thus, to test for a regular file (for example), one could write:
5a015b
+
5a015b
+.nf
5a015b
+.in +4n
5a015b
+stat(pathname, &sb);
5a015b
+if ((sb.st_mode & S_IFMT) == S_IFREG) {
5a015b
+    /* Handle regular file */
5a015b
+}
5a015b
+.in
5a015b
+.fi
5a015b
+.PP
5a015b
+Because tests of the above form are common, additional
5a015b
+macros are defined by POSIX to allow the test of the file type in
5a015b
+.I st_mode
5a015b
+to be written more concisely:
5a015b
 .RS 4
5a015b
 .TP 1.2i
5a015b
 .BR S_ISREG (m)
5a015b
@@ -245,42 +378,85 @@ symbolic link?  (Not in POSIX.1-1996.)
5a015b
 socket?  (Not in POSIX.1-1996.)
5a015b
 .RE
5a015b
 .PP
5a015b
-The following flags are defined for the
5a015b
+The preceding code snippet could thus be rewritten as:
5a015b
+
5a015b
+.nf
5a015b
+.in +4n
5a015b
+stat(pathname, &sb);
5a015b
+if (S_ISREG(sb.st_mode)) {
5a015b
+    /* Handle regular file */
5a015b
+}
5a015b
+.in
5a015b
+.fi
5a015b
+.PP
5a015b
+The definitions of most of the above file type test macros
5a015b
+are provided if any of the following feature test macros is defined:
5a015b
+.BR _BSD_SOURCE
5a015b
+(in glibc 2.19 and earlier),
5a015b
+.BR _SVID_SOURCE
5a015b
+(in glibc 2.19 and earlier),
5a015b
+or
5a015b
+.BR _DEFAULT_SOURCE
5a015b
+(in glibc 2.20 and later).
5a015b
+In addition, definitions of all of the above macros except
5a015b
+.BR S_IFSOCK
5a015b
+and
5a015b
+.BR S_ISSOCK ()
5a015b
+are provided if
5a015b
+.BR _XOPEN_SOURCE
5a015b
+is defined.
5a015b
+The definition of
5a015b
+.BR S_IFSOCK
5a015b
+can also be exposed by defining
5a015b
+.BR _XOPEN_SOURCE
5a015b
+with a value of 500 or greater.
5a015b
+
5a015b
+The definition of
5a015b
+.BR S_ISSOCK ()
5a015b
+is exposed if any of the following feature test macros is defined:
5a015b
+.BR _BSD_SOURCE
5a015b
+(in glibc 2.19 and earlier),
5a015b
+.BR _DEFAULT_SOURCE
5a015b
+(in glibc 2.20 and later),
5a015b
+.BR _XOPEN_SOURCE
5a015b
+with a value of 500 or greater, or
5a015b
+.BR _POSIX_C_SOURCE
5a015b
+with a value of 200112L or greater.
5a015b
+.PP
5a015b
+The following mask values are defined for
5a015b
+the file mode component of the
5a015b
 .I st_mode
5a015b
 field:
5a015b
 .in +4n
5a015b
 .TS
5a015b
 lB l l.
5a015b
-S_IFMT	0170000	bit mask for the file type bit fields
5a015b
-S_IFSOCK	0140000	socket
5a015b
-S_IFLNK	0120000	symbolic link
5a015b
-S_IFREG	0100000	regular file
5a015b
-S_IFBLK	0060000	block device
5a015b
-S_IFDIR	0040000	directory
5a015b
-S_IFCHR	0020000	character device
5a015b
-S_IFIFO	0010000	FIFO
5a015b
-S_ISUID	0004000	set-user-ID bit
5a015b
-S_ISGID	0002000	set-group-ID bit (see below)
5a015b
-S_ISVTX	0001000	sticky bit (see below)
5a015b
-S_IRWXU	00700	mask for file owner permissions
5a015b
-S_IRUSR	00400	owner has read permission
5a015b
-S_IWUSR	00200	owner has write permission
5a015b
-S_IXUSR	00100	owner has execute permission
5a015b
-S_IRWXG	00070	mask for group permissions
5a015b
-S_IRGRP	00040	group has read permission
5a015b
-S_IWGRP	00020	group has write permission
5a015b
-S_IXGRP	00010	group has execute permission
5a015b
-S_IRWXO	00007	mask for permissions for others (not in group)
5a015b
-S_IROTH	00004	others have read permission
5a015b
-S_IWOTH	00002	others have write permission
5a015b
-S_IXOTH	00001	others have execute permission
5a015b
+S_ISUID	  04000	set-user-ID bit
5a015b
+S_ISGID	  02000	set-group-ID bit (see below)
5a015b
+S_ISVTX	  01000	sticky bit (see below)
5a015b
+
5a015b
+S_IRWXU	  00700	owner has read, write, and execute permission
5a015b
+S_IRUSR	  00400	owner has read permission
5a015b
+S_IWUSR	  00200	owner has write permission
5a015b
+S_IXUSR	  00100	owner has execute permission
5a015b
+
5a015b
+S_IRWXG	  00070	group has read, write, and execute permission
5a015b
+S_IRGRP	  00040	group has read permission
5a015b
+S_IWGRP	  00020	group has write permission
5a015b
+S_IXGRP	  00010	group has execute permission
5a015b
+
5a015b
+S_IRWXO	  00007	T{
5a015b
+others (not in group) have read, write, and execute permission
5a015b
+T}
5a015b
+S_IROTH	  00004	others have read permission
5a015b
+S_IWOTH	  00002	others have write permission
5a015b
+S_IXOTH	  00001	others have execute permission
5a015b
 .TE
5a015b
 .in
5a015b
 .P
5a015b
 The set-group-ID bit
5a015b
 .RB ( S_ISGID )
5a015b
 has several special uses.
5a015b
-For a directory it indicates that BSD semantics is to be used
5a015b
+For a directory, it indicates that BSD semantics is to be used
5a015b
 for that directory: files created there inherit their group ID from
5a015b
 the directory, not from the effective group ID of the creating process,
5a015b
 and directories created there will also get the
5a015b
@@ -297,6 +473,100 @@ on a directory means that a file
5a015b
 in that directory can be renamed or deleted only by the owner
5a015b
 of the file, by the owner of the directory, and by a privileged
5a015b
 process.
5a015b
+.\"
5a015b
+.\"
5a015b
+.SS fstatat()
5a015b
+The
5a015b
+.BR fstatat ()
5a015b
+system call operates in exactly the same way as
5a015b
+.BR stat (),
5a015b
+except for the differences described here.
5a015b
+
5a015b
+If the pathname given in
5a015b
+.I pathname
5a015b
+is relative, then it is interpreted relative to the directory
5a015b
+referred to by the file descriptor
5a015b
+.I dirfd
5a015b
+(rather than relative to the current working directory of
5a015b
+the calling process, as is done by
5a015b
+.BR stat ()
5a015b
+for a relative pathname).
5a015b
+
5a015b
+If
5a015b
+.I pathname
5a015b
+is relative and
5a015b
+.I dirfd
5a015b
+is the special value
5a015b
+.BR AT_FDCWD ,
5a015b
+then
5a015b
+.I pathname
5a015b
+is interpreted relative to the current working
5a015b
+directory of the calling process (like
5a015b
+.BR stat ()).
5a015b
+
5a015b
+If
5a015b
+.I pathname
5a015b
+is absolute, then
5a015b
+.I dirfd
5a015b
+is ignored.
5a015b
+
5a015b
+.I flags
5a015b
+can either be 0, or include one or more of the following flags ORed:
5a015b
+.TP
5a015b
+.BR AT_EMPTY_PATH " (since Linux 2.6.39)"
5a015b
+.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
5a015b
+If
5a015b
+.I pathname
5a015b
+is an empty string, operate on the file referred to by
5a015b
+.IR dirfd
5a015b
+(which may have been obtained using the
5a015b
+.BR open (2)
5a015b
+.B O_PATH
5a015b
+flag).
5a015b
+In this case,
5a015b
+.I dirfd
5a015b
+can refer to any type of file, not just a directory.
5a015b
+If
5a015b
+.I dirfd
5a015b
+is
5a015b
+.BR AT_FDCWD ,
5a015b
+the call operates on the current working directory.
5a015b
+This flag is Linux-specific; define
5a015b
+.B _GNU_SOURCE
5a015b
+.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
5a015b
+to obtain its definition.
5a015b
+.TP
5a015b
+.BR AT_NO_AUTOMOUNT " (since Linux 2.6.38)"
5a015b
+Don't automount the terminal ("basename") component of
5a015b
+.I pathname
5a015b
+if it is a directory that is an automount point.
5a015b
+This allows the caller to gather attributes of an automount point
5a015b
+(rather than the location it would mount).
5a015b
+This flag can be used in tools that scan directories
5a015b
+to prevent mass-automounting of a directory of automount points.
5a015b
+The
5a015b
+.B AT_NO_AUTOMOUNT
5a015b
+flag has no effect if the mount point has already been mounted over.
5a015b
+This flag is Linux-specific; define
5a015b
+.B _GNU_SOURCE
5a015b
+.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
5a015b
+to obtain its definition.
5a015b
+.TP
5a015b
+.B AT_SYMLINK_NOFOLLOW
5a015b
+If
5a015b
+.I pathname
5a015b
+is a symbolic link, do not dereference it:
5a015b
+instead return information about the link itself, like
5a015b
+.BR lstat ().
5a015b
+(By default,
5a015b
+.BR fstatat ()
5a015b
+dereferences symbolic links, like
5a015b
+.BR stat ().)
5a015b
+.PP
5a015b
+See
5a015b
+.BR openat (2)
5a015b
+for an explanation of the need for
5a015b
+.BR fstatat ().
5a015b
 .SH RETURN VALUE
5a015b
 On success, zero is returned.
5a015b
 On error, \-1 is returned, and
5a015b
@@ -307,13 +577,13 @@ is set appropriately.
5a015b
 .B EACCES
5a015b
 Search permission is denied for one of the directories
5a015b
 in the path prefix of
5a015b
-.IR path .
5a015b
+.IR pathname .
5a015b
 (See also
5a015b
 .BR path_resolution (7).)
5a015b
 .TP
5a015b
 .B EBADF
5a015b
 .I fd
5a015b
-is bad.
5a015b
+is not a valid open file descriptor.
5a015b
 .TP
5a015b
 .B EFAULT
5a015b
 Bad address.
5a015b
@@ -322,26 +592,26 @@ Bad address.
5a015b
 Too many symbolic links encountered while traversing the path.
5a015b
 .TP
5a015b
 .B ENAMETOOLONG
5a015b
-.I path
5a015b
+.I pathname
5a015b
 is too long.
5a015b
 .TP
5a015b
 .B ENOENT
5a015b
 A component of
5a015b
-.I path
5a015b
+.I pathname
5a015b
 does not exist, or
5a015b
-.I path
5a015b
-is an empty string.
5a015b
+.I pathname
5a015b
+is an empty string and AT_EMPTY_PATH was not specified.
5a015b
 .TP
5a015b
 .B ENOMEM
5a015b
 Out of memory (i.e., kernel memory).
5a015b
 .TP
5a015b
 .B ENOTDIR
5a015b
 A component of the path prefix of
5a015b
-.I path
5a015b
+.I pathname
5a015b
 is not a directory.
5a015b
 .TP
5a015b
 .B EOVERFLOW
5a015b
-.I path
5a015b
+.I pathname
5a015b
 or
5a015b
 .I fd
5a015b
 refers to a file whose size, inode number,
5a015b
@@ -358,8 +628,32 @@ calls
5a015b
 on a file whose size exceeds
5a015b
 .I (1<<31)-1
5a015b
 bytes.
5a015b
+.PP
5a015b
+The following additional errors can occur for
5a015b
+.BR fstatat ():
5a015b
+.TP
5a015b
+.B EBADF
5a015b
+.I dirfd
5a015b
+is not a valid file descriptor.
5a015b
+.TP
5a015b
+.B EINVAL
5a015b
+Invalid flag specified in
5a015b
+.IR flags .
5a015b
+.TP
5a015b
+.B ENOTDIR
5a015b
+.I pathname
5a015b
+is relative and
5a015b
+.I dirfd
5a015b
+is a file descriptor referring to a file other than a directory.
5a015b
+.SH VERSIONS
5a015b
+.BR fstatat ()
5a015b
+was added to Linux in kernel 2.6.16;
5a015b
+library support was added to glibc in version 2.4.
5a015b
 .SH CONFORMING TO
5a015b
-These system calls conform to SVr4, 4.3BSD, POSIX.1-2001.
5a015b
+.BR stat (),
5a015b
+.BR fstat (),
5a015b
+.BR lstat ():
5a015b
+SVr4, 4.3BSD, POSIX.1-2001, POSIX.1.2008.
5a015b
 .\" SVr4 documents additional
5a015b
 .\" .BR fstat ()
5a015b
 .\" error conditions EINTR, ENOLINK, and EOVERFLOW.  SVr4
5a015b
@@ -369,18 +663,21 @@ These system calls conform to SVr4, 4.3BSD, POSIX.1-2001.
5a015b
 .\" .BR lstat ()
5a015b
 .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW.
5a015b
 
5a015b
+.BR fstatat ():
5a015b
+POSIX.1-2008.
5a015b
+
5a015b
 According to POSIX.1-2001,
5a015b
 .BR lstat ()
5a015b
 on a symbolic link need return valid information only in the
5a015b
 .I st_size
5a015b
-field and the file-type component of the
5a015b
+field and the file type of the
5a015b
 .IR st_mode
5a015b
 field of the
5a015b
 .IR stat
5a015b
 structure.
5a015b
-POSIX.-2008 tightens the specification, requiring
5a015b
+POSIX.1-2008 tightens the specification, requiring
5a015b
 .BR lstat ()
5a015b
-to return valid information in all fields except the permission bits in
5a015b
+to return valid information in all fields except the mode bits in
5a015b
 .IR st_mode .
5a015b
 
5a015b
 Use of the
5a015b
@@ -413,10 +710,10 @@ POSIX.1-1990 did not describe the
5a015b
 .BR S_IFCHR ,
5a015b
 .BR S_IFIFO ,
5a015b
 .B S_ISVTX
5a015b
-constants, but instead demanded the use of
5a015b
+constants, but instead specified the use of
5a015b
 the macros
5a015b
 .BR S_ISDIR (),
5a015b
-etc.
5a015b
+and so on.
5a015b
 The
5a015b
 .BR S_IF*
5a015b
 constants are present in POSIX.1-2001 and later.
5a015b
@@ -425,11 +722,11 @@ The
5a015b
 .BR S_ISLNK ()
5a015b
 and
5a015b
 .BR S_ISSOCK ()
5a015b
-macros are not in
5a015b
+macros were not in
5a015b
 POSIX.1-1996, but both are present in POSIX.1-2001;
5a015b
 the former is from SVID 4, the latter from SUSv2.
5a015b
 .LP
5a015b
-UNIX V7 (and later systems) had
5a015b
+UNIX\ V7 (and later systems) had
5a015b
 .BR S_IREAD ,
5a015b
 .BR S_IWRITE ,
5a015b
 .BR S_IEXEC ,
5a015b
@@ -438,104 +735,74 @@ prescribes the synonyms
5a015b
 .BR S_IRUSR ,
5a015b
 .BR S_IWUSR ,
5a015b
 .BR S_IXUSR .
5a015b
-.SS Other systems
5a015b
-Values that have been (or are) in use on various systems:
5a015b
-.ad l
5a015b
-.TS
5a015b
-l l l l l.
5a015b
-hex	name	ls	octal	description
5a015b
-f000	S_IFMT		170000	mask for file type
5a015b
-0000			000000	T{
5a015b
-SCO out-of-service inode; BSD unknown type; SVID-v2 and XPG2
5a015b
-have both 0 and 0100000 for ordinary file
5a015b
-T}
5a015b
-1000	S_IFIFO	p|	010000	FIFO (named pipe)
5a015b
-2000	S_IFCHR	c	020000	character special (V7)
5a015b
-3000	S_IFMPC		030000	multiplexed character special (V7)
5a015b
-4000	S_IFDIR	d/	040000	directory (V7)
5a015b
-5000	S_IFNAM		050000	T{
5a015b
-XENIX named special file with two subtypes, distinguished by
5a015b
-\fIst_rdev\fP values 1, 2
5a015b
-T}
5a015b
-0001	S_INSEM	s	000001	XENIX semaphore subtype of IFNAM
5a015b
-0002	S_INSHD	m	000002	XENIX shared data subtype of IFNAM
5a015b
-6000	S_IFBLK	b	060000	block special (V7)
5a015b
-7000	S_IFMPB		070000	multiplexed block special (V7)
5a015b
-8000	S_IFREG	-	100000	regular (V7)
5a015b
-9000	S_IFCMP		110000	VxFS compressed
5a015b
-9000	S_IFNWK	n	110000	network special (HP-UX)
5a015b
-a000	S_IFLNK	l@	120000	symbolic link (BSD)
5a015b
-b000	S_IFSHAD		130000	T{
5a015b
-Solaris shadow inode for ACL (not seen by user space)
5a015b
-T}
5a015b
-c000	S_IFSOCK	s=	140000	socket (BSD; also "S_IFSOC" on VxFS)
5a015b
-d000	S_IFDOOR	D>	150000	Solaris door
5a015b
-e000	S_IFWHT	w%	160000	BSD whiteout (not used for inode)
5a015b
-0200	S_ISVTX		001000	T{
5a015b
-sticky bit: save swapped text even after use (V7)
5a015b
-.br
5a015b
-reserved (SVID-v2)
5a015b
-.br
5a015b
-On nondirectories: don't cache this file (SunOS)
5a015b
-.br
5a015b
-On directories: restricted deletion flag (SVID-v4.2)
5a015b
-T}
5a015b
-0400	S_ISGID		002000	T{
5a015b
-set-group-ID on execution (V7)
5a015b
-.br
5a015b
-for directories: use BSD semantics for propagation of GID
5a015b
-T}
5a015b
-0400	S_ENFMT		002000	T{
5a015b
-System V file locking enforcement (shared with S_ISGID)
5a015b
-T}
5a015b
-0800	S_ISUID		004000	set-user-ID on execution (V7)
5a015b
-0800	S_CDF		004000	T{
5a015b
-directory is a context dependent file (HP-UX)
5a015b
-T}
5a015b
-.TE
5a015b
-.ad
5a015b
-
5a015b
-A sticky command appeared in Version 32V AT&T UNIX.
5a015b
 .SH NOTES
5a015b
+On Linux,
5a015b
+.BR lstat ()
5a015b
+will generally not trigger automounter action, whereas
5a015b
+.BR stat ()
5a015b
+will (but see the description of
5a015b
+.BR fstatat ()
5a015b
+.B AT_NO_AUTOMOUNT
5a015b
+fag, above).
5a015b
+
5a015b
+For pseudofiles that are autogenerated by the kernel,
5a015b
+.BR stat ()
5a015b
+does not return an accurate value in the
5a015b
+.IR st_size
5a015b
+field.
5a015b
+For example, the value 0 is returned for many files under the
5a015b
+.I /proc
5a015b
+directory,
5a015b
+while various files under
5a015b
+.IR /sys
5a015b
+report a size of 4096 bytes, even though the file content is smaller.
5a015b
+For such files, one should simply try to read as many bytes as possible
5a015b
+(and append \(aq\e0\(aq to the returned buffer
5a015b
+if it is to be interpreted as a string).
5a015b
+.\"
5a015b
+.SS Timestamp fields
5a015b
+Older kernels and older standards did not support nanosecond timestamp
5a015b
+fields.
5a015b
+Instead, there were three timestamp
5a015b
+.RI fields\(em st_atime ,
5a015b
+.IR st_mtime ,
5a015b
+and
5a015b
+.IR st_ctime \(emtyped
5a015b
+as
5a015b
+.IR time_t
5a015b
+that recorded timestamps with one-second precision.
5a015b
+
5a015b
 Since kernel 2.5.48, the
5a015b
 .I stat
5a015b
 structure supports nanosecond resolution for the three file timestamp fields.
5a015b
-Glibc exposes the nanosecond component of each field using names of the form
5a015b
-.IR st_atim.tv_nsec
5a015b
-if the
5a015b
-.B _BSD_SOURCE
5a015b
-or
5a015b
-.B _SVID_SOURCE
5a015b
-feature test macro is defined.
5a015b
-These fields are specified in POSIX.1-2008, and, starting with version 2.12,
5a015b
-glibc also exposes these field names if
5a015b
+The nanosecond components of each timestamp are available
5a015b
+via names of the form
5a015b
+.IR st_atim.tv_nsec ,
5a015b
+if suitable feature test macros are defined.
5a015b
+Nanosecond timestamps were standardized in POSIX.1-2008,
5a015b
+and, starting with version 2.12,
5a015b
+glibc exposes the nanosecond component names if
5a015b
 .BR _POSIX_C_SOURCE
5a015b
 is defined with the value 200809L or greater, or
5a015b
 .BR _XOPEN_SOURCE
5a015b
 is defined with the value 700 or greater.
5a015b
+Up to and including glibc 2.19,
5a015b
+the definitions of the nanoseconds components are also defined if
5a015b
+.B _BSD_SOURCE
5a015b
+or
5a015b
+.B _SVID_SOURCE
5a015b
+is defined.
5a015b
 If none of the aforementioned macros are defined,
5a015b
 then the nanosecond values are exposed with names of the form
5a015b
 .IR st_atimensec .
5a015b
-On file systems that do not support subsecond timestamps,
5a015b
-the nanosecond fields are returned with the value 0.
5a015b
-.\" As at kernel 2.6.25, XFS and JFS support nanosecond timestamps,
5a015b
-.\" but ext2, ext3, and Reiserfs do not.
5a015b
-
5a015b
-On Linux,
5a015b
-.BR lstat ()
5a015b
-will generally not trigger automounter action, whereas
5a015b
-.BR stat ()
5a015b
-will (but see
5a015b
-.BR fstatat (2)).
5a015b
 
5a015b
-For most files under the
5a015b
-.I /proc
5a015b
-directory,
5a015b
-.BR stat ()
5a015b
-does not return the file size in the
5a015b
-.I st_size
5a015b
-field; instead the field is returned with the value 0.
5a015b
-.SS Underlying kernel interface
5a015b
+Nanosecond timestamps are supported on XFS, JFS, Btrfs, and
5a015b
+ext4 (since Linux 2.6.23).
5a015b
+.\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
5a015b
+Nanosecond timestamps are not supported in ext2, ext3, and Reiserfs.
5a015b
+On filesystems that do not support subsecond timestamps,
5a015b
+the nanosecond fields are returned with the value 0.
5a015b
+.SS C library/kernel differences
5a015b
 Over time, increases in the size of the
5a015b
 .I stat
5a015b
 structure have led to three successive versions of
5a015b
@@ -548,17 +815,51 @@ structure have led to three successive versions of
5a015b
 .IR __NR_stat ),
5a015b
 and
5a015b
 .I sys_stat64()
5a015b
-(new in kernel 2.4; slot
5a015b
-.IR __NR_stat64 ).
5a015b
+(slot
5a015b
+.IR __NR_stat64 )
5a015b
+on 32-bit platforms such as i386.
5a015b
+The first two versions were already present in Linux 1.0
5a015b
+(albeit with different names);
5a015b
+.\" See include/asm-i386/stat.h in the Linux 2.4 source code for the
5a015b
+.\" various versions of the structure definitions
5a015b
+the last was added in Linux 2.4.
5a015b
+Similar remarks apply for
5a015b
+.BR fstat ()
5a015b
+and
5a015b
+.BR lstat ().
5a015b
+
5a015b
+The kernel-internal versions of the
5a015b
+.I stat
5a015b
+structure dealt with by the different versions are, respectively:
5a015b
+.TP
5a015b
+.IR __old_kernel_stat
5a015b
+The original structure, with rather narrow fields, and no padding.
5a015b
+.TP
5a015b
+.IR stat
5a015b
+Larger
5a015b
+.I st_ino
5a015b
+field and padding added to various parts of the structure to
5a015b
+allow for future expansion.
5a015b
+.TP
5a015b
+.IR stat64
5a015b
+Even larger
5a015b
+.I st_ino
5a015b
+field,
5a015b
+larger
5a015b
+.I st_uid
5a015b
+and
5a015b
+.I st_gid
5a015b
+fields to accommodate the Linux-2.4 expansion of UIDs and GIDs to 32 bits,
5a015b
+and various other enlarged fields and further padding in the structure.
5a015b
+(Various padding bytes were eventually consumed in Linux 2.6,
5a015b
+with the advent of 32-bit device IDs and nanosecond components
5a015b
+for the timestamp fields.)
5a015b
+.PP
5a015b
 The glibc
5a015b
 .BR stat ()
5a015b
 wrapper function hides these details from applications,
5a015b
 invoking the most recent version of the system call provided by the kernel,
5a015b
 and repacking the returned information if required for old binaries.
5a015b
-Similar remarks apply for
5a015b
-.BR fstat ()
5a015b
-and
5a015b
-.BR lstat ().
5a015b
 .\"
5a015b
 .\" A note from Andries Brouwer, July 2007
5a015b
 .\"
5a015b
@@ -587,6 +888,20 @@ and
5a015b
 .\" interface, rather than the libc-kernel interface.
5a015b
 .\"
5a015b
 .\" (Note that the details depend on gcc being used as c compiler.)
5a015b
+
5a015b
+On modern 64-bit systems, life is simpler: there is a single
5a015b
+.BR stat ()
5a015b
+system call and the kernel deals with a
5a015b
+.I stat
5a015b
+structure that contains fields of a sufficient size.
5a015b
+
5a015b
+The underlying system call employed by the glibc
5a015b
+.BR fstatat ()
5a015b
+wrapper function is actually called
5a015b
+.BR fstatat64 ()
5a015b
+or, on some architectures,
5a015b
+.\" strace(1) shows the name "newfstatat" on x86-64
5a015b
+.BR newfstatat ().
5a015b
 .SH EXAMPLE
5a015b
 The following program calls
5a015b
 .BR stat ()
5a015b
@@ -600,6 +915,7 @@ structure.
5a015b
 #include <time.h>
5a015b
 #include <stdio.h>
5a015b
 #include <stdlib.h>
5a015b
+#include <sys/sysmacros.h>
5a015b
 
5a015b
 int
5a015b
 main(int argc, char *argv[])
5a015b
@@ -616,6 +932,9 @@ main(int argc, char *argv[])
5a015b
         exit(EXIT_FAILURE);
5a015b
     }
5a015b
 
5a015b
+    printf("ID of containing device:  [%lx,%lx]\\n",
5a015b
+	    (long) major(sb.st_dev), (long) minor(sb.st_dev));
5a015b
+
5a015b
     printf("File type:                ");
5a015b
 
5a015b
     switch (sb.st_mode & S_IFMT) {
5a015b
@@ -653,10 +972,11 @@ main(int argc, char *argv[])
5a015b
 }
5a015b
 .fi
5a015b
 .SH SEE ALSO
5a015b
+.BR ls (1),
5a015b
+.BR stat (1),
5a015b
 .BR access (2),
5a015b
 .BR chmod (2),
5a015b
 .BR chown (2),
5a015b
-.BR fstatat (2),
5a015b
 .BR readlink (2),
5a015b
 .BR utime (2),
5a015b
 .BR capabilities (7),
5a015b
-- 
5a015b
2.7.4
5a015b