FreeNOS
stat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBPOSIX_SYS_STAT_H
19 #define __LIB_LIBPOSIX_SYS_STAT_H
20 
21 #include <FileSystem.h>
22 #include <Macros.h>
23 #include <errno.h>
24 #include <time.h>
25 #include "types.h"
26 
36 #define FILETYPE_BITS 3
37 
39 #define FILETYPE_MASK 7
40 
42 #define FILEMODE_BITS 9
43 
45 #define FILEMODE_MASK 0777
46 
58 #define S_IFMT (FILETYPE_MASK << FILEMODE_BITS)
59 
61 #define S_IFBLK (FileSystem::BlockDeviceFile << FILEMODE_BITS)
62 
64 #define S_IFCHR (FileSystem::CharacterDeviceFile << FILEMODE_BITS)
65 
67 #define S_IFIFO (FileSystem::FIFOFile << FILEMODE_BITS)
68 
70 #define S_IFREG (FileSystem::RegularFile << FILEMODE_BITS)
71 
73 #define S_IFDIR (FileSystem::DirectoryFile << FILEMODE_BITS)
74 
76 #define S_IFLNK (FileSystem::SymlinkFile << FILEMODE_BITS)
77 
79 #define S_IFSOCK (FileSystem::SocketFile << FILEMODE_BITS)
80 
97 #define S_IRWXU FileSystem::OwnerRWX
98 
100 #define S_IRUSR FileSystem::OwnerR
101 
103 #define S_IWUSR FileSystem::OwnerW
104 
106 #define S_IXUSR FileSystem::OwnerX
107 
109 #define S_IRWXG FileSystem::GroupRWX
110 
112 #define S_IRGRP FileSystem::GroupR
113 
115 #define S_IWGRP FileSystem::GroupW
116 
118 #define S_IXGRP FileSystem::GroupX
119 
121 #define S_IRWXO FileSystem::OtherRWX
122 
124 #define S_IROTH FileSystem::OtherR
125 
127 #define S_IWOTH FileSystem::OtherW
128 
130 #define S_IXOTH FileSystem::OtherX
131 
146 #define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
147 
149 #define S_ISBLK(m) S_ISTYPE(m, S_IFBLK)
150 
152 #define S_ISCHR(m) S_ISTYPE(m, S_IFCHR)
153 
155 #define S_ISDIR(m) S_ISTYPE(m, S_IFDIR)
156 
158 #define S_ISFIFO(m) S_ISTYPE(m, S_IFIFO)
159 
161 #define S_ISREG(m) S_ISTYPE(m, S_IFREG)
162 
164 #define S_ISLNK(m) S_ISTYPE(m, S_IFLNK)
165 
167 #define S_ISSOCK(m) S_ISTYPE(m, S_IFSOCK)
168 
176 struct stat
177 {
178 #ifdef CPP
179 
183  void fromFileStat(FileSystem::FileStat *stat)
184  {
185  this->st_ino = stat->inode;
186  this->st_mode = stat->access;
187  this->st_mode |= stat->type << FILEMODE_BITS;
188  this->st_size = stat->size;
189  this->st_uid = stat->userID;
190  this->st_gid = stat->groupID;
191  this->st_dev.major = 0;
192  this->st_dev.minor = 0;
193  }
194 #endif /* CPP */
195 
198 
201 
204 
207 
210 
213 
216 
227 
230 
233 
236 
243 
246 };
247 
266 extern C int stat(const char *path, struct stat *buf);
267 
281 extern C int mknod(const char *path, mode_t mode, dev_t dev);
282 
299 extern C int mkdir(const char *path, mode_t mode);
300 
318 extern C int creat(const char *path, mode_t mode);
319 
325 #endif /* __LIB_LIBPOSIX_SYS_STAT_H */
stat::st_size
off_t st_size
For regular files, the file size in bytes.
Definition: stat.h:226
off_t
sint off_t
Used for file sizes.
Definition: types.h:59
stat
The <sys/stat.h> header shall define the stat structure.
Definition: stat.h:176
gid_t
u16 gid_t
Used for group IDs.
Definition: types.h:53
FileSystem.h
DeviceID::minor
u16 minor
Device specific minor ID number.
Definition: Types.h:151
stat::st_mtim
struct timespec st_mtim
Last data modification timestamp.
Definition: stat.h:232
Macros.h
nlink_t
Size nlink_t
Used for link counts.
Definition: types.h:56
types.h
stat::st_uid
uid_t st_uid
User ID of file.
Definition: stat.h:209
stat::st_blocks
blkcnt_t st_blocks
Number of blocks allocated for this object.
Definition: stat.h:245
stat::st_nlink
nlink_t st_nlink
Number of hard links to the file.
Definition: stat.h:206
stat::st_dev
dev_t st_dev
Device ID of device containing file.
Definition: stat.h:197
FileSystem::FileStat::inode
u32 inode
< File type.
Definition: FileSystem.h:116
mode_t
uint mode_t
Used for some file attributes.
Definition: types.h:47
stat::st_ctim
struct timespec st_ctim
Last file status change timestamp.
Definition: stat.h:235
FileSystem::FileStat::access
FileModes access
< Process identifier of filesystem
Definition: FileSystem.h:118
time.h
FileSystem::FileStat::groupID
GroupID groupID
< User identity.
Definition: FileSystem.h:121
FileSystem::FileStat::type
FileType type
Definition: FileSystem.h:115
stat::st_rdev
dev_t st_rdev
Device ID (if file is character or block special).
Definition: stat.h:215
C
#define C
Used to define external C functions.
Definition: Macros.h:134
FILEMODE_BITS
#define FILEMODE_BITS
Number of bits required for all FileModes.
Definition: stat.h:42
FileSystem::FileStat::size
Size size
< File access permission bits.
Definition: FileSystem.h:119
FileSystem::FileStat::userID
UserID userID
< Size of the file in bytes.
Definition: FileSystem.h:120
uid_t
u16 uid_t
Used for user IDs.
Definition: types.h:50
mkdir
C int mkdir(const char *path, mode_t mode)
Create a new directory.
Definition: mkdir.cpp:25
ino_t
uint ino_t
Used for file serial numbers.
Definition: types.h:44
stat::st_ino
ino_t st_ino
File inode number.
Definition: stat.h:200
stat::st_mode
mode_t st_mode
Mode of file.
Definition: stat.h:203
DeviceID::major
ProcessID major
Major device ID number is a PID.
Definition: Types.h:148
stat
C int stat(const char *path, struct stat *buf)
Get file status.
Definition: stat.cpp:25
creat
C int creat(const char *path, mode_t mode)
Create a new file or rewrite an existing one.
Definition: creat.cpp:25
FileSystem::FileStat
Contains file information.
Definition: FileSystem.h:113
mknod
C int mknod(const char *path, mode_t mode, dev_t dev)
Make directory, special file, or regular file.
Definition: mknod.cpp:25
DeviceID
Describes a device ID number.
Definition: Types.h:145
stat::st_gid
gid_t st_gid
Group ID of file.
Definition: stat.h:212
timespec
The <time.h> header shall declare the timespec structure.
Definition: time.h:35
stat::st_blksize
blksize_t st_blksize
A file system-specific preferred I/O block size for this object.
Definition: stat.h:242
blkcnt_t
sint blkcnt_t
Used for file block counts.
Definition: types.h:62
blksize_t
sint blksize_t
Used for block sizes.
Definition: types.h:65
errno.h
stat::st_atim
struct timespec st_atim
Last data access timestamp.
Definition: stat.h:229