Back to index

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