Back to index

glibc  2.9
stat.h
Go to the documentation of this file.
00001 /* Copyright (C) 1996,1997,1998,1999,2000,2001,2004
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 /* Versions of the `struct stat' data structure.  */
00025 #define _STAT_VER_KERNEL    0
00026 #define _STAT_VER_GLIBC2    1
00027 #define _STAT_VER_GLIBC2_1  2
00028 #define _STAT_VER_KERNEL64  3
00029 #define _STAT_VER_GLIBC2_3_4       3
00030 #define _STAT_VER           _STAT_VER_GLIBC2_3_4
00031 
00032 /* Versions of the `xmknod' interface.  */
00033 #define _MKNOD_VER_LINUX    0
00034 
00035 
00036 /* Nanosecond resolution timestamps are stored in a format equivalent to
00037    'struct timespec'.  This is the type used whenever possible but the
00038    Unix namespace rules do not allow the identifier 'timespec' to appear
00039    in the <sys/stat.h> header.  Therefore we have to handle the use of
00040    this header in strictly standard-compliant sources special.
00041 
00042    Use neat tidy anonymous unions and structures when possible.  */
00043 
00044 #ifdef __USE_MISC
00045 # if __GNUC_PREREQ(3,3)
00046 #  define __ST_TIME(X)                           \
00047        __extension__ union {                     \
00048            struct timespec st_##X##tim;   \
00049            struct {                       \
00050               __time_t st_##X##time;             \
00051               unsigned long st_##X##timensec;    \
00052            };                             \
00053        }
00054 # else
00055 #  define __ST_TIME(X) struct timespec st_##X##tim
00056 #  define st_atime st_atim.tv_sec
00057 #  define st_mtime st_mtim.tv_sec
00058 #  define st_ctime st_ctim.tv_sec
00059 # endif
00060 #else
00061 # define __ST_TIME(X)                            \
00062        __time_t st_##X##time;                    \
00063        unsigned long st_##X##timensec
00064 #endif
00065 
00066 
00067 struct stat
00068   {
00069     __dev_t st_dev;         /* Device.  */
00070 #ifdef __USE_FILE_OFFSET64
00071     __ino64_t st_ino;              /* File serial number.  */
00072 #else
00073     __ino_t st_ino;         /* File serial number.      */
00074     int __pad0;                    /* 64-bit st_ino.  */
00075 #endif
00076     __dev_t st_rdev;        /* Device number, if device.  */
00077     __off_t st_size;        /* Size of file, in bytes.  */
00078 #ifdef __USE_FILE_OFFSET64
00079     __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated.  */
00080 #else
00081     __blkcnt_t st_blocks;   /* Nr. 512-byte blocks allocated.  */
00082     int __pad1;                    /* 64-bit st_blocks.  */
00083 #endif
00084     __mode_t st_mode;              /* File mode.  */
00085     __uid_t st_uid;         /* User ID of the file's owner.    */
00086     __gid_t st_gid;         /* Group ID of the file's group.*/
00087     __blksize_t st_blksize; /* Optimal block size for I/O.  */
00088     __nlink_t st_nlink;            /* Link count.  */
00089     int __pad2;                    /* Real padding.  */
00090     __ST_TIME(a);           /* Time of last access.  */
00091     __ST_TIME(m);           /* Time of last modification.  */
00092     __ST_TIME(c);           /* Time of last status change.  */
00093     long __unused[3];
00094   };
00095 
00096 #ifdef __USE_LARGEFILE64
00097 /* Note stat64 is the same shape as stat.  */
00098 struct stat64
00099   {
00100     __dev_t st_dev;         /* Device.  */
00101     __ino64_t st_ino;              /* File serial number.  */
00102     __dev_t st_rdev;        /* Device number, if device.  */
00103     __off_t st_size;        /* Size of file, in bytes.  */
00104     __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated.  */
00105     __mode_t st_mode;              /* File mode.  */
00106     __uid_t st_uid;         /* User ID of the file's owner.    */
00107     __gid_t st_gid;         /* Group ID of the file's group.*/
00108     __blksize_t st_blksize; /* Optimal block size for I/O.  */
00109     __nlink_t st_nlink;            /* Link count.  */
00110     int __pad0;                    /* Real padding.  */
00111     __ST_TIME(a);           /* Time of last access.  */
00112     __ST_TIME(m);           /* Time of last modification.  */
00113     __ST_TIME(c);           /* Time of last status change.  */
00114     long __unused[3];
00115   };
00116 #endif
00117 
00118 #undef __ST_TIME
00119 
00120 /* Tell code we have these members.  */
00121 #define       _STATBUF_ST_BLKSIZE
00122 #define _STATBUF_ST_RDEV
00123 #define _STATBUF_ST_NSEC
00124 
00125 /* Encoding of the file mode.  */
00126 
00127 #define       __S_IFMT      0170000       /* These bits determine file type.  */
00128 
00129 /* File types.  */
00130 #define       __S_IFDIR     0040000       /* Directory.  */
00131 #define       __S_IFCHR     0020000       /* Character device.  */
00132 #define       __S_IFBLK     0060000       /* Block device.  */
00133 #define       __S_IFREG     0100000       /* Regular file.  */
00134 #define       __S_IFIFO     0010000       /* FIFO.  */
00135 #define       __S_IFLNK     0120000       /* Symbolic link.  */
00136 #define       __S_IFSOCK    0140000       /* Socket.  */
00137 
00138 /* POSIX.1b objects.  Note that these macros always evaluate to zero.  But
00139    they do it by enforcing the correct use of the macros.  */
00140 #define __S_TYPEISMQ(buf)  ((buf)->st_mode - (buf)->st_mode)
00141 #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
00142 #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
00143 
00144 /* Protection bits.  */
00145 
00146 #define       __S_ISUID     04000  /* Set user ID on execution.  */
00147 #define       __S_ISGID     02000  /* Set group ID on execution.  */
00148 #define       __S_ISVTX     01000  /* Save swapped text after use (sticky).  */
00149 #define       __S_IREAD     0400   /* Read by owner.  */
00150 #define       __S_IWRITE    0200   /* Write by owner.  */
00151 #define       __S_IEXEC     0100   /* Execute by owner.  */
00152 
00153 #if defined __USE_ATFILE || defined __USE_GNU
00154 /* XXX This will change to the macro for the next 2008 POSIX revision.  */
00155 # define UTIME_NOW   ((1l << 30) - 1l)
00156 # define UTIME_OMIT  ((1l << 30) - 2l)
00157 #endif