The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
stat.h
Go to the documentation of this file.
1#pragma once
2
3#include <sys/types.h>
4#include <time.h>
5
6/**
7 * @file sys/stat.h
8 * @brief file metadata: stat() and fstat().
9 *
10 * struct stat and the S_ bits are ABI and must match the kernel side in
11 * src/kernel/vfs/stat.h exactly.
12 */
13
14#define S_IFMT 0170000
15#define S_IFIFO 0010000
16#define S_IFSOCK 0140000
17#define S_IFCHR 0020000
18#define S_IFDIR 0040000
19#define S_IFBLK 0060000
20#define S_IFREG 0100000
21#define S_IFLNK 0120000
22
23#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
24#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
25#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
26#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
27#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
28#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
29#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
30
31// permission bits
32#define S_IRWXU 0700
33#define S_IRUSR 0400
34#define S_IWUSR 0200
35#define S_IXUSR 0100
36#define S_IRWXG 0070
37#define S_IRGRP 0040
38#define S_IWGRP 0020
39#define S_IXGRP 0010
40#define S_IRWXO 0007
41#define S_IROTH 0004
42#define S_IWOTH 0002
43#define S_IXOTH 0001
44
45struct stat
46{
54 unsigned int __st_pad; // puts st_size on 8 bytes on both architectures
58 struct timespec st_atim; // last access
59 struct timespec st_mtim; // last change of the data
60 struct timespec st_ctim; // last change of the data or the metadata
61};
62
63// the whole seconds, by their older names
64#define st_atime st_atim.tv_sec
65#define st_mtime st_mtim.tv_sec
66#define st_ctime st_ctim.tv_sec
67
68/**
69 * get a file's metadata by path.
70 * @return 0, or -1 (errno set).
71 */
72int stat(const char *path, struct stat *st);
73
74/**
75 * the metadata of a symbolic link itself (stat gives what it points at).
76 */
77int lstat(const char *path, struct stat *st);
78
79/**
80 * get an open file's metadata (pipes and the console too).
81 * @return 0, or -1 (errno set).
82 */
83int fstat(int fd, struct stat *st);
84
85#define S_ISUID 04000 // run with the owner's user id
86#define S_ISGID 02000 // run with the file's group id
87#define S_ISVTX 01000 // sticky directory
88
89/**
90 * create a directory with a mode (taken through the umask).
91 */
92int mkdir(const char *path, mode_t mode);
93int mkdirat(int dirfd, const char *path, mode_t mode);
94int fstatat(int dirfd, const char *path, struct stat *st, int flags);
95int fchmodat(int dirfd, const char *path, mode_t mode, int flags);
96
97/**
98 * change the permission bits of a file (owner or root only).
99 */
100int chmod(const char *path, mode_t mode);
101int fchmod(int fd, mode_t mode);
102
103/**
104 * set the mask taken off the mode of new files.
105 * @return the old mask.
106 */
108
109// utimensat and futimens: a tv_nsec for the time now, or for no change
110#define UTIME_NOW ((1l << 30) - 1)
111#define UTIME_OMIT ((1l << 30) - 2)
112
113/**
114 * set a file's access and modification times (times[0], times[1]); with
115 * times NULL, both to the time now.
116 * @param flags AT_SYMLINK_NOFOLLOW: the link itself.
117 * @return 0, or -1 (errno set).
118 */
119int utimensat(int dirfd, const char *path, const struct timespec times[2], int flags);
120int futimens(int fd, const struct timespec times[2]);
121
122/**
123 * make a named pipe (a FIFO): processes that open it share one pipe.
124 * @return 0, or -1 (errno set).
125 */
126int mkfifo(const char *path, mode_t mode);
127int mkfifoat(int dirfd, const char *path, mode_t mode);
128
129/**
130 * make a named pipe (S_IFIFO), an empty file (S_IFREG) or, as root, a
131 * device node (S_IFCHR, S_IFBLK with makedev's number). a device node
132 * outside /dev opens with ENXIO: ginnOS's devices are in /dev.
133 * @return 0, or -1 (errno set).
134 */
135int mknod(const char *path, mode_t mode, dev_t dev);
136int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev);
uint8_t flags
Definition idt.c:3
int dirfd(DIR *dir)
the file descriptor under a directory stream.
int lstat(const char *path, struct stat *st)
the metadata of a symbolic link itself (stat gives what it points at).
int fchmod(int fd, mode_t mode)
int futimens(int fd, const struct timespec times[2])
int mkdirat(int dirfd, const char *path, mode_t mode)
int mkdir(const char *path, mode_t mode)
create a directory with a mode (taken through the umask).
int fstat(int fd, struct stat *st)
get an open file's metadata (pipes and the console too).
mode_t umask(mode_t mask)
set the mask taken off the mode of new files.
int mknod(const char *path, mode_t mode, dev_t dev)
make a named pipe (S_IFIFO), an empty file (S_IFREG) or, as root, a device node (S_IFCHR,...
int fchmodat(int dirfd, const char *path, mode_t mode, int flags)
int fstatat(int dirfd, const char *path, struct stat *st, int flags)
int chmod(const char *path, mode_t mode)
change the permission bits of a file (owner or root only).
int mkfifo(const char *path, mode_t mode)
make a named pipe (a FIFO): processes that open it share one pipe.
int mkfifoat(int dirfd, const char *path, mode_t mode)
int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev)
int utimensat(int dirfd, const char *path, const struct timespec times[2], int flags)
set a file's access and modification times (times[0], times[1]); with times NULL, both to the time no...
Definition stat.h:46
off_t st_size
Definition stat.h:55
nlink_t st_nlink
Definition stat.h:50
blksize_t st_blksize
Definition stat.h:56
blkcnt_t st_blocks
Definition stat.h:57
uid_t st_uid
Definition stat.h:51
mode_t st_mode
Definition stat.h:49
struct timespec st_mtim
Definition stat.h:59
struct timespec st_atim
Definition stat.h:58
struct timespec st_ctim
Definition stat.h:60
ino_t st_ino
Definition stat.h:48
unsigned int __st_pad
Definition stat.h:54
dev_t st_rdev
Definition stat.h:53
gid_t st_gid
Definition stat.h:52
dev_t st_dev
Definition stat.h:47
Definition time.h:26
struct timeval and gettimeofday.
clock_t times(struct tms *buf)
the CPU times of the process and its reaped children.
basic system types.
__INT64_TYPE__ off_t
Definition types.h:20
unsigned int blksize_t
Definition types.h:24
unsigned int uid_t
Definition types.h:17
unsigned int blkcnt_t
Definition types.h:25
unsigned int gid_t
Definition types.h:18
unsigned int dev_t
Definition types.h:22
unsigned int ino_t
Definition types.h:21
unsigned int mode_t
Definition types.h:19
unsigned int nlink_t
Definition types.h:23