xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame^] | 1 | /* 'struct stat' and related definitions. NaCl version. |
| 2 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #if !defined _SYS_STAT_H && !defined _FCNTL_H |
| 20 | # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead." |
| 21 | #endif |
| 22 | |
| 23 | #ifndef _BITS_STAT_H |
| 24 | #define _BITS_STAT_H 1 |
| 25 | |
| 26 | /* Versions of the `struct stat' data structure. */ |
| 27 | #define _STAT_VER_NACL 0 |
| 28 | #define _STAT_VER_LINUX 1 |
| 29 | |
| 30 | #define _STAT_VER _STAT_VER_LINUX |
| 31 | |
| 32 | struct stat |
| 33 | { |
| 34 | __dev_t st_dev; /* Device. */ |
| 35 | __ino_t st_ino; /* File serial number. */ |
| 36 | __nlink_t st_nlink; /* Link count. */ |
| 37 | __mode_t st_mode; /* File mode. */ |
| 38 | __uid_t st_uid; /* User ID of the file's owner. */ |
| 39 | __gid_t st_gid; /* Group ID of the file's group.*/ |
| 40 | int __pad0; |
| 41 | __dev_t st_rdev; /* Device number, if device. */ |
| 42 | __off_t st_size; /* Size of file, in bytes. */ |
| 43 | __blksize_t st_blksize; /* Optimal block size for I/O. */ |
| 44 | __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */ |
| 45 | #if defined __USE_XOPEN2K8 |
| 46 | /* Nanosecond resolution timestamps are stored in a format |
| 47 | equivalent to 'struct timespec'. This is the type used |
| 48 | whenever possible but the Unix namespace rules do not allow the |
| 49 | identifier 'timespec' to appear in the <sys/stat.h> header. |
| 50 | Therefore we have to handle the use of this header in strictly |
| 51 | standard-compliant sources special. */ |
| 52 | struct timespec st_atim; /* Time of last access. */ |
| 53 | struct timespec st_mtim; /* Time of last modification. */ |
| 54 | struct timespec st_ctim; /* Time of last status change. */ |
| 55 | # define st_atime st_atim.tv_sec /* Backward compatibility. */ |
| 56 | # define st_mtime st_mtim.tv_sec |
| 57 | # define st_ctime st_ctim.tv_sec |
| 58 | #else |
| 59 | __time_t st_atime; /* Time of last access. */ |
| 60 | __uint64_t st_atimensec; /* Nsecs of last access. */ |
| 61 | __time_t st_mtime; /* Time of last modification. */ |
| 62 | __uint64_t st_mtimensec; /* Nsecs of last modification. */ |
| 63 | __time_t st_ctime; /* Time of last status change. */ |
| 64 | __uint64_t st_ctimensec; /* Nsecs of last status change. */ |
| 65 | #endif |
| 66 | __int64_t __unused[3]; |
| 67 | }; |
| 68 | |
| 69 | #ifdef __USE_LARGEFILE64 |
| 70 | /* Note stat64 has the same shape as stat for NaCl. */ |
| 71 | struct stat64 |
| 72 | { |
| 73 | __dev_t st_dev; /* Device. */ |
| 74 | __ino_t st_ino; /* File serial number. */ |
| 75 | __nlink_t st_nlink; /* Link count. */ |
| 76 | __mode_t st_mode; /* File mode. */ |
| 77 | __uid_t st_uid; /* User ID of the file's owner. */ |
| 78 | __gid_t st_gid; /* Group ID of the file's group.*/ |
| 79 | int __pad0; |
| 80 | __dev_t st_rdev; /* Device number, if device. */ |
| 81 | __off_t st_size; /* Size of file, in bytes. */ |
| 82 | __blksize_t st_blksize; /* Optimal block size for I/O. */ |
| 83 | __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */ |
| 84 | # if defined __USE_XOPEN2K8 |
| 85 | /* Nanosecond resolution timestamps are stored in a format |
| 86 | equivalent to 'struct timespec'. This is the type used |
| 87 | whenever possible but the Unix namespace rules do not allow the |
| 88 | identifier 'timespec' to appear in the <sys/stat.h> header. |
| 89 | Therefore we have to handle the use of this header in strictly |
| 90 | standard-compliant sources special. */ |
| 91 | struct timespec st_atim; /* Time of last access. */ |
| 92 | struct timespec st_mtim; /* Time of last modification. */ |
| 93 | struct timespec st_ctim; /* Time of last status change. */ |
| 94 | # define st_atime st_atim.tv_sec /* Backward compatibility. */ |
| 95 | # define st_mtime st_mtim.tv_sec |
| 96 | # define st_ctime st_ctim.tv_sec |
| 97 | # else |
| 98 | __time_t st_atime; /* Time of last access. */ |
| 99 | __uint64_t st_atimensec; /* Nsecs of last access. */ |
| 100 | __time_t st_mtime; /* Time of last modification. */ |
| 101 | __uint64_t st_mtimensec; /* Nsecs of last modification. */ |
| 102 | __time_t st_ctime; /* Time of last status change. */ |
| 103 | __uint64_t st_ctimensec; /* Nsecs of last status change. */ |
| 104 | # endif |
| 105 | __int64_t __unused[3]; |
| 106 | }; |
| 107 | #endif |
| 108 | |
| 109 | /* Tell code we have these members. */ |
| 110 | #define _STATBUF_ST_BLKSIZE 1 |
| 111 | #define _STATBUF_ST_RDEV 1 |
| 112 | /* Nanosecond resolution time values are supported. */ |
| 113 | #define _STATBUF_ST_NSEC 1 |
| 114 | |
| 115 | /* Encoding of the file mode. */ |
| 116 | |
| 117 | #define __S_IFMT 0170000 /* These bits determine file type. */ |
| 118 | |
| 119 | /* File types. */ |
| 120 | #define __S_IFDIR 0040000 /* Directory. */ |
| 121 | #define __S_IFCHR 0020000 /* Character device. */ |
| 122 | #define __S_IFBLK 0060000 /* Block device. */ |
| 123 | #define __S_IFREG 0100000 /* Regular file. */ |
| 124 | #define __S_IFIFO 0010000 /* FIFO. */ |
| 125 | #define __S_IFLNK 0120000 /* Symbolic link. */ |
| 126 | #define __S_IFSOCK 0140000 /* Socket. */ |
| 127 | |
| 128 | /* POSIX.1b objects. Note that these macros always evaluate to zero. But |
| 129 | they do it by enforcing the correct use of the macros. */ |
| 130 | #define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode) |
| 131 | #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode) |
| 132 | #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode) |
| 133 | |
| 134 | /* Protection bits. */ |
| 135 | |
| 136 | #define __S_ISUID 04000 /* Set user ID on execution. */ |
| 137 | #define __S_ISGID 02000 /* Set group ID on execution. */ |
| 138 | #define __S_ISVTX 01000 /* Save swapped text after use (sticky). */ |
| 139 | #define __S_IREAD 0400 /* Read by owner. */ |
| 140 | #define __S_IWRITE 0200 /* Write by owner. */ |
| 141 | #define __S_IEXEC 0100 /* Execute by owner. */ |
| 142 | |
| 143 | #ifdef __USE_ATFILE |
| 144 | /* XXX missing: UTIME_NOW, UTIME_OMIT */ |
| 145 | #endif |
| 146 | |
| 147 | #endif /* bits/stat.h */ |