From 9497142004b76377660517857b0ed8b3d133dc7e Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Sat, 11 Apr 2015 07:59:56 +0200 Subject: [PATCH] stat.2: Add some details on various "stat" versions Three versions of "stat" appeared on 32-bit systems, dealing with structures of different (increasing) sizes. Explain some of the details, and also note that the situation is simpler on modern 64-bit architectures. Signed-off-by: Michael Kerrisk --- man2/stat.2 | 54 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/man2/stat.2 b/man2/stat.2 index afe0dc90a..a78ffafe9 100644 --- a/man2/stat.2 +++ b/man2/stat.2 @@ -809,18 +809,52 @@ structure have led to three successive versions of and .I sys_stat64() (slot -.IR __NR_stat64 ). -The first two of these were already present in Linux 1.0 -(albeit with different names); the last was added in Linux 2.4. +.IR __NR_stat64 ) +on 32-bit platforms such as i386. +The first two versions were already present in Linux 1.0 +(albeit with different names); +.\" See include/asm-i386/stat.h in the Linux 2.4 source code for the +.\" various versions of the structure definitions +the last was added in Linux 2.4. +Similar remarks apply for +.BR fstat () +and +.BR lstat (). + +The kernel-internal versions of the +.I stat +structure dealt with by the different versions are, respectively: +.RS +.TP +.IR __old_kernel_stat +The original structure, with rather narrow fields, and no padding. +.TP +.IR stat +Larger +.I st_ino +field and padding added to various parts of the structure to +allow for future expansion. +.TP +.IR stat64 +Even larger +.I st_ino +field, +larger +.I st_uid +and +.I st_gid +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.) +.RE +.PP The glibc .BR stat () 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. -Similar remarks apply for -.BR fstat () -and -.BR lstat (). .\" .\" A note from Andries Brouwer, July 2007 .\" @@ -850,6 +884,12 @@ and .\" .\" (Note that the details depend on gcc being used as c compiler.) +On modern 64-bit systems, life is simpler: there is a single +.BR stat () +system call and the kernel deals with a +.I stat +structure that contains fields of a sufficient size. + The underlying system call employed by the glibc .BR fstatat () wrapper function is actually called