]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/sys/stat.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / sys / stat.h
1 /** @file
2
3 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made
5 available under the terms and conditions of the BSD License that
6 accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Copyright (c) 1982, 1986, 1989, 1993
13 The Regents of the University of California. All rights reserved.
14 (c) UNIX System Laboratories, Inc.
15 All or some portions of this file are derived from material licensed
16 to the University of California by American Telephone and Telegraph
17 Co. or Unix System Laboratories, Inc. and are reproduced herein with
18 the permission of UNIX System Laboratories, Inc.
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions
22 are met:
23 1. Redistributions of source code must retain the above copyright
24 notice, this list of conditions and the following disclaimer.
25 2. Redistributions in binary form must reproduce the above copyright
26 notice, this list of conditions and the following disclaimer in the
27 documentation and/or other materials provided with the distribution.
28 3. Neither the name of the University nor the names of its contributors
29 may be used to endorse or promote products derived from this software
30 without specific prior written permission.
31
32 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 SUCH DAMAGE.
43
44 stat.h 8.12 (Berkeley) 8/17/94
45 NetBSD: stat.h,v 1.54 2006/02/24 22:01:30 thorpej Exp
46 */
47 #ifndef _SYS_STAT_H_
48 #define _SYS_STAT_H_
49
50 #include <sys/featuretest.h>
51 #include <sys/types.h> /* XXX */
52 #include <sys/time.h>
53
54 struct stat {
55 off_t st_size; /* file size, in bytes */
56 off_t st_physsize; /* physical space the file consumes */
57 dtime_t st_birthtime; /* time of creation */
58 dtime_t st_atime; /* time of last access */
59 dtime_t st_mtime; /* time of last data modification */
60 mode_t st_mode; /* file attributes */
61
62 blksize_t st_blksize; /* optimal blocksize for I/O */
63 #if 0
64 uint32_t st_flags; /* user defined flags for file */
65 blkcnt_t st_blocks; /* blocks allocated for file */
66 ino_t st_ino; /* inode's number */
67 time_t st_ctime; /* time of last file status change */
68 nlink_t st_nlink; /* number of hard links */
69 uid_t st_uid; /* user ID of the file's owner */
70 gid_t st_gid; /* group ID of the file's group */
71 dev_t st_dev; /* inode's device */
72 dev_t st_rdev; /* device type */
73 uint32_t st_gen; /* file generation number */
74 #endif
75 uint32_t st_spare[1];
76 };
77
78 #if 0
79 #define st_atime st_atimespec.tv_sec
80 #define st_atimensec st_atimespec.tv_nsec
81 #define st_mtime st_mtimespec.tv_sec
82 #define st_mtimensec st_mtimespec.tv_nsec
83 #define st_ctime st_ctimespec.tv_sec
84 #define st_ctimensec st_ctimespec.tv_nsec
85 #define st_birthtime st_birthtimespec.tv_sec
86 #define st_birthtimensec st_birthtimespec.tv_nsec
87 #endif
88
89 #define S_ISUID 0004000 /* set user id on execution */
90 #define S_ISGID 0002000 /* set group id on execution */
91 #define S_ISTXT 0001000 /* sticky bit */
92
93 #define S_IRWXU 0000700 /* RWX mask for owner */
94 #define S_IRUSR 0000400 /* R for owner */
95 #define S_IWUSR 0000200 /* W for owner */
96 #define S_IXUSR 0000100 /* X for owner */
97
98 #define S_IREAD S_IRUSR
99 #define S_IWRITE S_IWUSR
100 #define S_IEXEC S_IXUSR
101
102 #define S_IRWXG 0000070 /* RWX mask for group */
103 #define S_IRGRP 0000040 /* R for group */
104 #define S_IWGRP 0000020 /* W for group */
105 #define S_IXGRP 0000010 /* X for group */
106
107 #define S_IRWXO 0000007 /* RWX mask for other */
108 #define S_IROTH 0000004 /* R for other */
109 #define S_IWOTH 0000002 /* W for other */
110 #define S_IXOTH 0000001 /* X for other */
111
112 /* The Octal access modes, above, fall into the Hex mask 0x00000FFF.
113 Traditionally, the remainder of the flags are specified in Octal
114 but they are expressed in Hex here for modern clarity.
115 */
116 #define _S_IFMT 0x0001F000 /* type-of-file mask */
117 #define _S_IFCHR 0x00002000 /* character special */
118 #define _S_IFDIR 0x00004000 /* directory */
119 #define _S_IFBLK 0x00006000 /* block special */
120 #define _S_IFREG 0x00008000 /* regular */
121 #define _S_IFSOCK 0x0000C000 /* socket */
122 #define _S_ITTY 0x00010000 /* File connects to a TTY device */
123 #define _S_IWTTY 0x00020000 /* TTY receives Wide characters */
124
125 /* UEFI specific (FAT file system) File attributes.
126 Specifiec in Hexadecimal instead of Octal.
127 These bits correspond to the xx portion of _S_IFMT
128 */
129 #define S_IREADONLY 0x00100000 // Read Only File
130 #define S_IHIDDEN 0x00200000 // Hidden File
131 #define S_ISYSTEM 0x00400000 // System File
132 #define S_IDIRECTORY 0x01000000 // Directory
133 #define S_IARCHIVE 0x02000000 // Archive Bit
134 #define S_IROFS 0x08000000 /* Read Only File System */
135
136 #define S_EFISHIFT 20 // LS bit of the UEFI attributes
137
138 //#define _S_IFIFO 0010000 /* named pipe (fifo) */
139 //#define _S_IFLNK 0120000 /* symbolic link */
140 //#define _S_IFWHT 0160000 /* whiteout */
141 //#define _S_ARCH1 0200000 /* Archive state 1, ls -l shows 'a' */
142 //#define _S_ARCH2 0400000 /* Archive state 2, ls -l shows 'A' */
143 //#define _S_ISVTX 0001000 /* ???? save swapped text even after use */
144
145
146 #define S_IFMT _S_IFMT
147 #define S_IFBLK _S_IFBLK
148 #define S_IFREG _S_IFREG
149 //#define S_IFIFO _S_IFIFO
150 //#define S_IFCHR _S_IFCHR
151 //#define S_IFDIR _S_IFDIR
152 //#define S_IFLNK _S_IFLNK
153 //#define S_ISVTX _S_ISVTX
154 //#define S_IFSOCK _S_IFSOCK
155 //#define S_IFWHT _S_IFWHT
156
157 //#define S_ARCH1 _S_ARCH1
158 //#define S_ARCH2 _S_ARCH2
159
160 #define S_ISDIR(m) ((m & _S_IFMT) == _S_IFDIR) /* directory */
161 #define S_ISCHR(m) ((m & _S_IFMT) == _S_IFCHR) /* char special */
162 #define S_ISREG(m) ((m & _S_IFMT) == _S_IFREG) /* regular file */
163 #define S_ISBLK(m) ((m & _S_IFMT) == _S_IFBLK) /* block special */
164 #define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK) /* socket */
165
166 //#define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */
167 //#define S_ISLNK(m) ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */
168 //#define S_ISWHT(m) ((m & _S_IFMT) == _S_IFWHT) /* whiteout */
169
170 /* The following three macros have been changed to reflect
171 access permissions that better reflect the UEFI FAT file system.
172 UEFI only supports Read or Read+Write instead of the *nix
173 rwx paradigm. Thus, using 0777 is the closest analog.
174 */
175 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
176 #define ALLPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
177 #define DEFFILEMODE (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
178
179 #define S_BLKSIZE 512 /* block size used in the stat struct */
180
181 /*
182 * Definitions of flags stored in file flags word.
183 *
184 * Super-user and owner changeable flags.
185 */
186 #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
187 #define UF_NODUMP 0x00000001 /* do not dump file */
188 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */
189 #define UF_APPEND 0x00000004 /* writes to file may only append */
190 /* UF_NOUNLINK 0x00000010 [NOT IMPLEMENTED] */
191 /*
192 * Super-user changeable flags.
193 */
194 #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */
195 #define SF_ARCHIVED 0x00010000 /* file is archived */
196 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */
197 #define SF_APPEND 0x00040000 /* writes to file may only append */
198 /* SF_NOUNLINK 0x00100000 [NOT IMPLEMENTED] */
199
200 #include <sys/EfiCdefs.h>
201
202 __BEGIN_DECLS
203 #ifndef __STAT_SYSCALLS_DECLARED
204 #define __STAT_SYSCALLS_DECLARED
205 extern int mkdir (const char *, mode_t);
206 extern int fstat (int, struct stat *);
207 extern int lstat (const char *, struct stat *);
208 extern int stat (const char *, void *);
209 // extern int chmod (const char *, mode_t);
210 #endif // __STAT_SYSCALLS_DECLARED
211 __END_DECLS
212
213 #endif /* !_SYS_STAT_H_ */