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
176struct stat
177{
178#ifdef CPP
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
266extern C int stat(const char *path, struct stat *buf);
267
281extern C int mknod(const char *path, mode_t mode, dev_t dev);
282
299extern C int mkdir(const char *path, mode_t mode);
300
318extern C int creat(const char *path, mode_t mode);
319
325#endif /* __LIB_LIBPOSIX_SYS_STAT_H */
C int creat(const char *path, mode_t mode)
Create a new file or rewrite an existing one.
Definition creat.cpp:25
#define FILEMODE_BITS
Number of bits required for all FileModes.
Definition stat.h:42
C int mkdir(const char *path, mode_t mode)
Create a new directory.
Definition mkdir.cpp:25
uint ino_t
Used for file serial numbers.
Definition types.h:44
Size nlink_t
Used for link counts.
Definition types.h:56
uint mode_t
Used for some file attributes.
Definition types.h:47
sint off_t
Used for file sizes.
Definition types.h:59
C int mknod(const char *path, mode_t mode, dev_t dev)
Make directory, special file, or regular file.
Definition mknod.cpp:25
u16 gid_t
Used for group IDs.
Definition types.h:53
u16 uid_t
Used for user IDs.
Definition types.h:50
sint blksize_t
Used for block sizes.
Definition types.h:65
sint blkcnt_t
Used for file block counts.
Definition types.h:62
#define C
Used to define external C functions.
Definition Macros.h:134
Describes a device ID number.
Definition Types.h:146
ProcessID major
Major device ID number is a PID.
Definition Types.h:148
u16 minor
Device specific minor ID number.
Definition Types.h:151
Contains file information.
Definition FileSystem.h:114
UserID userID
< Size of the file in bytes.
Definition FileSystem.h:120
u32 inode
< File type.
Definition FileSystem.h:116
FileModes access
< Process identifier of filesystem
Definition FileSystem.h:118
Size size
< File access permission bits.
Definition FileSystem.h:119
GroupID groupID
< User identity.
Definition FileSystem.h:121
The <sys/stat.h> header shall define the stat structure.
Definition stat.h:177
off_t st_size
For regular files, the file size in bytes.
Definition stat.h:226
nlink_t st_nlink
Number of hard links to the file.
Definition stat.h:206
blksize_t st_blksize
A file system-specific preferred I/O block size for this object.
Definition stat.h:242
blkcnt_t st_blocks
Number of blocks allocated for this object.
Definition stat.h:245
uid_t st_uid
User ID of file.
Definition stat.h:209
mode_t st_mode
Mode of file.
Definition stat.h:203
struct timespec st_mtim
Last data modification timestamp.
Definition stat.h:232
struct timespec st_atim
Last data access timestamp.
Definition stat.h:229
struct timespec st_ctim
Last file status change timestamp.
Definition stat.h:235
ino_t st_ino
File inode number.
Definition stat.h:200
dev_t st_rdev
Device ID (if file is character or block special).
Definition stat.h:215
gid_t st_gid
Group ID of file.
Definition stat.h:212
dev_t st_dev
Device ID of device containing file.
Definition stat.h:197
The <time.h> header shall declare the timespec structure.
Definition time.h:36