The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
stat.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* struct stat as user space sees it (stat, fstat). the layout and the
5
* S_ bits are ABI: the libc's <sys/stat.h> has the same ones.
6
*/
7
8
#include "
common/stdint.h
"
9
#include "
kernel/fs/fs.h
"
10
#include "
kernel/time/clock.h
"
11
12
// file type bits of st_mode (the ext2 i_mode values)
13
#define S_IFMT 0170000
14
#define S_IFIFO 0010000
15
#define S_IFSOCK 0140000
16
#define S_IFCHR 0020000
17
#define S_IFDIR 0040000
18
#define S_IFBLK 0060000
19
#define S_IFREG 0100000
20
#define S_IFLNK 0120000
21
22
struct
kstat
23
{
24
uint32_t
st_dev
;
// device of the filesystem (0 for now)
25
uint32_t
st_ino
;
// inode number
26
uint32_t
st_mode
;
// S_IF* type and permission bits
27
uint32_t
st_nlink
;
// hard links
28
uint32_t
st_uid
;
// owner
29
uint32_t
st_gid
;
// group
30
uint32_t
st_rdev
;
// device, for a device node (0 for now)
31
uint32_t
st_pad
;
// puts st_size on 8 bytes on both architectures
32
int64_t
st_size
;
// bytes
33
uint32_t
st_blksize
;
// preferred I/O size
34
uint32_t
st_blocks
;
// 512-byte blocks allocated
35
struct
ktimespec
st_atim
;
// last access, since 1970
36
struct
ktimespec
st_mtim
;
// last modification
37
struct
ktimespec
st_ctim
;
// last status change
38
};
39
40
/**
41
* fill a struct kstat from a filesystem's stat. a filesystem that leaves
42
* the type bits of the mode out gets them from its file type.
43
* @param fs the filesystem's stat.
44
* @param out receives the user-facing stat.
45
*/
46
static
inline
void
stat_from_fs(
const
fs_stat_t
*
fs
,
struct
kstat
*out)
47
{
48
uint32_t
mode =
fs
->mode;
49
if
(!(mode &
S_IFMT
))
50
{
51
mode |=
fs
->file_type ==
FS_TYPE_DIR
? (
S_IFDIR
| 0755) : (
S_IFREG
| 0644);
52
}
53
54
out->
st_dev
= 0;
55
out->
st_ino
=
fs
->inode;
56
out->
st_mode
= mode;
57
out->
st_nlink
=
fs
->links_count;
58
out->
st_uid
=
fs
->uid;
59
out->
st_gid
=
fs
->gid;
60
out->
st_rdev
=
fs
->rdev;
61
out->
st_pad
= 0;
62
out->
st_size
= (
int64_t
)
fs
->size;
63
out->
st_blksize
= 1024;
64
out->
st_blocks
=
fs
->blocks;
65
// the filesystems keep whole seconds
66
out->
st_atim
= (
struct
ktimespec
){.
tv_sec
=
fs
->atime, .tv_nsec = 0};
67
out->
st_mtim
= (
struct
ktimespec
){.
tv_sec
=
fs
->mtime, .tv_nsec = 0};
68
out->
st_ctim
= (
struct
ktimespec
){.
tv_sec
=
fs
->ctime, .tv_nsec = 0};
69
}
clock.h
stdint.h
fs.h
FS_TYPE_DIR
@ FS_TYPE_DIR
Definition
fs.h:16
fs_stat_t
struct fs_stat fs_stat_t
Definition
fs.h:37
fs
uint32_t fs
Definition
gdt.c:22
uint32_t
unsigned int uint32_t
Definition
fb.h:17
int64_t
__INT64_TYPE__ int64_t
Definition
stdint.h:16
S_IFDIR
#define S_IFDIR
Definition
stat.h:18
S_IFREG
#define S_IFREG
Definition
stat.h:20
S_IFMT
#define S_IFMT
Definition
stat.h:14
kstat
Definition
stat.h:23
kstat::st_mtim
struct ktimespec st_mtim
Definition
stat.h:36
kstat::st_uid
uint32_t st_uid
Definition
stat.h:28
kstat::st_pad
uint32_t st_pad
Definition
stat.h:31
kstat::st_atim
struct ktimespec st_atim
Definition
stat.h:35
kstat::st_ino
uint32_t st_ino
Definition
stat.h:25
kstat::st_blksize
uint32_t st_blksize
Definition
stat.h:33
kstat::st_ctim
struct ktimespec st_ctim
Definition
stat.h:37
kstat::st_size
int64_t st_size
Definition
stat.h:32
kstat::st_mode
uint32_t st_mode
Definition
stat.h:26
kstat::st_rdev
uint32_t st_rdev
Definition
stat.h:30
kstat::st_dev
uint32_t st_dev
Definition
stat.h:24
kstat::st_blocks
uint32_t st_blocks
Definition
stat.h:34
kstat::st_gid
uint32_t st_gid
Definition
stat.h:29
kstat::st_nlink
uint32_t st_nlink
Definition
stat.h:27
ktimespec
struct timespec (ABI: long seconds and nanoseconds, as the libc's <time.h> has it).
Definition
clock.h:27
ktimespec::tv_sec
long tv_sec
Definition
clock.h:28
src
kernel
vfs
stat.h
Generated by
1.18.0