Back to index

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