Back to index

glibc  2.9
stat.h
Go to the documentation of this file.
00001 /* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _SYS_STAT_H
00020 # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
00021 #endif
00022 
00023 #include <bits/wordsize.h>
00024 
00025 #if __WORDSIZE == 64
00026 /* Versions of the `struct stat' data structure.  */
00027 # define _STAT_VER_KERNEL   0
00028 # define _STAT_VER_LINUX    1
00029 # define _STAT_VER          _STAT_VER_LINUX
00030 
00031 /* Versions of the `xmknod' interface.    */
00032 #define _MKNOD_VER_LINUX    0
00033 #else
00034 /* Versions of the `struct stat' data structure.  */
00035 # define _STAT_VER_LINUX_OLD       1
00036 # define _STAT_VER_KERNEL   1
00037 # define _STAT_VER_SVR4            2
00038 # define _STAT_VER_LINUX    3
00039 # define _STAT_VER          _STAT_VER_LINUX
00040 
00041 /* Versions of the `xmknod' interface.  */
00042 # define _MKNOD_VER_LINUX   1
00043 # define _MKNOD_VER_SVR4    2
00044 # define _MKNOD_VER         _MKNOD_VER_LINUX
00045 #endif
00046 
00047 #if __WORDSIZE == 64
00048 struct stat
00049   {
00050     __dev_t st_dev;         /* Device.  */
00051     __ino_t st_ino;         /* File serial number.      */
00052     __nlink_t st_nlink;            /* Link count.       */
00053     __mode_t st_mode;              /* File mode.  */
00054     __uid_t st_uid;         /* User ID of the file's owner.    */
00055     __gid_t st_gid;         /* Group ID of the file's group.*/
00056     int pad0;
00057     __dev_t st_rdev;        /* Device number, if device.  */
00058     __off_t st_size;        /* Size of file, in bytes.  */
00059 #ifdef __USE_MISC
00060     /* Nanosecond resolution timestamps are stored in a format
00061        equivalent to 'struct timespec'.  This is the type used
00062        whenever possible but the Unix namespace rules do not allow the
00063        identifier 'timespec' to appear in the <sys/stat.h> header.
00064        Therefore we have to handle the use of this header in strictly
00065        standard-compliant sources special.  */
00066     struct timespec st_atim;              /* Time of last access.  */
00067     struct timespec st_mtim;              /* Time of last modification.  */
00068     struct timespec st_ctim;              /* Time of last status change.  */
00069 # define st_atime st_atim.tv_sec   /* Backward compatibility.  */
00070 # define st_mtime st_mtim.tv_sec
00071 # define st_ctime st_ctim.tv_sec
00072 #else
00073     __time_t st_atime;                    /* Time of last access.  */
00074     unsigned long int st_atimensec;       /* Nscecs of last access.  */
00075     __time_t st_mtime;                    /* Time of last modification.  */
00076     unsigned long int st_mtimensec;       /* Nsecs of last modification.  */
00077     __time_t st_ctime;                    /* Time of last status change.  */
00078     unsigned long int st_ctimensec;       /* Nsecs of last status change.  */
00079 #endif
00080     __blksize_t st_blksize; /* Optimal block size for I/O.     */
00081     __blkcnt_t st_blocks;   /* Nr. 512-byte blocks allocated.  */
00082     long int __unused[3];
00083   };
00084 #else
00085 struct stat
00086   {
00087     __dev_t st_dev;                /* Device.  */
00088     unsigned int __pad1;
00089 # ifndef __USE_FILE_OFFSET64
00090     __ino_t st_ino;                /* File serial number.      */
00091 # else
00092     __ino_t __st_ino;                     /* 32bit file serial number.       */
00093 # endif
00094     __mode_t st_mode;                     /* File mode.  */
00095     __nlink_t st_nlink;                   /* Link count.  */
00096     __uid_t st_uid;                /* User ID of the file's owner.    */
00097     __gid_t st_gid;                /* Group ID of the file's group.*/
00098     __dev_t st_rdev;               /* Device number, if device.  */
00099     unsigned int __pad2;
00100 # ifndef __USE_FILE_OFFSET64
00101     __off_t st_size;               /* Size of file, in bytes.  */
00102 # else
00103     __off64_t st_size;                    /* Size of file, in bytes.  */
00104 # endif
00105     __blksize_t st_blksize;        /* Optimal block size for I/O.  */
00106 
00107 # ifndef __USE_FILE_OFFSET64
00108     __blkcnt_t st_blocks;          /* Number 512-byte blocks allocated. */
00109 # else
00110     __blkcnt64_t st_blocks;        /* Number 512-byte blocks allocated. */
00111 # endif
00112 #ifdef __USE_MISC
00113     /* Nanosecond resolution timestamps are stored in a format
00114        equivalent to 'struct timespec'.  This is the type used
00115        whenever possible but the Unix namespace rules do not allow the
00116        identifier 'timespec' to appear in the <sys/stat.h> header.
00117        Therefore we have to handle the use of this header in strictly
00118        standard-compliant sources special.  */
00119     struct timespec st_atim;              /* Time of last access.  */
00120     struct timespec st_mtim;              /* Time of last modification.  */
00121     struct timespec st_ctim;              /* Time of last status change.  */
00122 # define st_atime st_atim.tv_sec   /* Backward compatibility.  */
00123 # define st_mtime st_mtim.tv_sec
00124 # define st_ctime st_ctim.tv_sec
00125 #else
00126     __time_t st_atime;                    /* Time of last access.  */
00127     unsigned long int st_atimensec;       /* Nscecs of last access.  */
00128     __time_t st_mtime;                    /* Time of last modification.  */
00129     unsigned long int st_mtimensec;       /* Nsecs of last modification.  */
00130     __time_t st_ctime;                    /* Time of last status change.  */
00131     unsigned long int st_ctimensec;       /* Nsecs of last status change.  */
00132 #endif
00133 # ifndef __USE_FILE_OFFSET64
00134     unsigned long int __unused4;
00135     unsigned long int __unused5;
00136 # else
00137     __ino64_t st_ino;                     /* File serial number.      */
00138 # endif
00139   };
00140 #endif
00141 
00142 #ifdef __USE_LARGEFILE64
00143 # if __WORDSIZE == 64
00144 /* Note stat64 is the same shape as stat.  */
00145 struct stat64
00146   {
00147     __dev_t st_dev;         /* Device.  */
00148     __ino64_t st_ino;              /* File serial number.      */
00149     __nlink_t st_nlink;            /* Link count.       */
00150     __mode_t st_mode;              /* File mode.  */
00151     __uid_t st_uid;         /* User ID of the file's owner.    */
00152     __gid_t st_gid;         /* Group ID of the file's group.*/
00153     int pad0;
00154     __dev_t st_rdev;        /* Device number, if device.  */
00155     __off_t st_size;        /* Size of file, in bytes.  */
00156 #ifdef __USE_MISC
00157     /* Nanosecond resolution timestamps are stored in a format
00158        equivalent to 'struct timespec'.  This is the type used
00159        whenever possible but the Unix namespace rules do not allow the
00160        identifier 'timespec' to appear in the <sys/stat.h> header.
00161        Therefore we have to handle the use of this header in strictly
00162        standard-compliant sources special.  */
00163     struct timespec st_atim;              /* Time of last access.  */
00164     struct timespec st_mtim;              /* Time of last modification.  */
00165     struct timespec st_ctim;              /* Time of last status change.  */
00166 # define st_atime st_atim.tv_sec   /* Backward compatibility.  */
00167 # define st_mtime st_mtim.tv_sec
00168 # define st_ctime st_ctim.tv_sec
00169 #else
00170     __time_t st_atime;                    /* Time of last access.  */
00171     unsigned long int st_atimensec;       /* Nscecs of last access.  */
00172     __time_t st_mtime;                    /* Time of last modification.  */
00173     unsigned long int st_mtimensec;       /* Nsecs of last modification.  */
00174     __time_t st_ctime;                    /* Time of last status change.  */
00175     unsigned long int st_ctimensec;       /* Nsecs of last status change.  */
00176 #endif
00177     __blksize_t st_blksize; /* Optimal block size for I/O.     */
00178     __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated.  */
00179     long int __unused[3];
00180   };
00181 # else
00182 struct stat64
00183   {
00184     __dev_t st_dev;                /* Device.  */
00185     unsigned int __pad1;
00186 
00187     __ino_t __st_ino;                     /* 32bit file serial number.       */
00188     __mode_t st_mode;                     /* File mode.  */
00189     __nlink_t st_nlink;                   /* Link count.  */
00190     __uid_t st_uid;                /* User ID of the file's owner.    */
00191     __gid_t st_gid;                /* Group ID of the file's group.*/
00192     __dev_t st_rdev;               /* Device number, if device.  */
00193     unsigned int __pad2;
00194     __off64_t st_size;                    /* Size of file, in bytes.  */
00195     __blksize_t st_blksize;        /* Optimal block size for I/O.  */
00196 
00197     __blkcnt64_t st_blocks;        /* Number 512-byte blocks allocated. */
00198 #ifdef __USE_MISC
00199     /* Nanosecond resolution timestamps are stored in a format
00200        equivalent to 'struct timespec'.  This is the type used
00201        whenever possible but the Unix namespace rules do not allow the
00202        identifier 'timespec' to appear in the <sys/stat.h> header.
00203        Therefore we have to handle the use of this header in strictly
00204        standard-compliant sources special.  */
00205     struct timespec st_atim;              /* Time of last access.  */
00206     struct timespec st_mtim;              /* Time of last modification.  */
00207     struct timespec st_ctim;              /* Time of last status change.  */
00208 # define st_atime st_atim.tv_sec   /* Backward compatibility.  */
00209 # define st_mtime st_mtim.tv_sec
00210 # define st_ctime st_ctim.tv_sec
00211 #else
00212     __time_t st_atime;                    /* Time of last access.  */
00213     unsigned long int st_atimensec;       /* Nscecs of last access.  */
00214     __time_t st_mtime;                    /* Time of last modification.  */
00215     unsigned long int st_mtimensec;       /* Nsecs of last modification.  */
00216     __time_t st_ctime;                    /* Time of last status change.  */
00217     unsigned long int st_ctimensec;       /* Nsecs of last status change.  */
00218 #endif
00219     __ino64_t st_ino;                     /* File serial number.             */
00220   };
00221 # endif
00222 #endif
00223 
00224 /* Tell code we have these members.  */
00225 #define       _STATBUF_ST_BLKSIZE
00226 #define _STATBUF_ST_RDEV
00227 /* Nanosecond resolution time values are supported.  */
00228 #define _STATBUF_ST_NSEC
00229 
00230 /* Encoding of the file mode.  */
00231 
00232 #define       __S_IFMT      0170000       /* These bits determine file type.  */
00233 
00234 /* File types.  */
00235 #define       __S_IFDIR     0040000       /* Directory.  */
00236 #define       __S_IFCHR     0020000       /* Character device.  */
00237 #define       __S_IFBLK     0060000       /* Block device.  */
00238 #define       __S_IFREG     0100000       /* Regular file.  */
00239 #define       __S_IFIFO     0010000       /* FIFO.  */
00240 #define       __S_IFLNK     0120000       /* Symbolic link.  */
00241 #define       __S_IFSOCK    0140000       /* Socket.  */
00242 
00243 /* POSIX.1b objects.  Note that these macros always evaluate to zero.  But
00244    they do it by enforcing the correct use of the macros.  */
00245 #define __S_TYPEISMQ(buf)  ((buf)->st_mode - (buf)->st_mode)
00246 #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
00247 #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
00248 
00249 /* Protection bits.  */
00250 
00251 #define       __S_ISUID     04000  /* Set user ID on execution.  */
00252 #define       __S_ISGID     02000  /* Set group ID on execution.  */
00253 #define       __S_ISVTX     01000  /* Save swapped text after use (sticky).  */
00254 #define       __S_IREAD     0400   /* Read by owner.  */
00255 #define       __S_IWRITE    0200   /* Write by owner.  */
00256 #define       __S_IEXEC     0100   /* Execute by owner.  */
00257 
00258 #if defined __USE_ATFILE || defined __USE_GNU
00259 /* XXX This will change to the macro for the next 2008 POSIX revision.  */
00260 # define UTIME_NOW   ((1l << 30) - 1l)
00261 # define UTIME_OMIT  ((1l << 30) - 2l)
00262 #endif