AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
devfs.c
Go to the documentation of this file.
1
8
9
#include <
core/system.h
>
10
#include <
core/module.h
>
11
#include <
core/string.h
>
12
#include <
core/time.h
>
13
14
#include <
fs/vfs.h
>
15
#include <
fs/devfs.h
>
16
#include <
fs/tmpfs.h
>
17
18
#include <aquila/errno.h>
19
20
/* devfs's root directory, usually mounted on /dev */
21
struct
vnode
*
devfs_root
=
NULL
;
22
24
static
int
devfs_init
()
25
{
26
/* devfs is a tmpfs */
27
devfs
.
vops
=
tmpfs
.
vops
;
28
devfs
.
fops
=
tmpfs
.
fops
;
29
30
devfs_root
=
kmalloc
(
sizeof
(
struct
vnode
), &M_VNODE,
M_ZERO
);
31
if
(!
devfs_root
)
return
-ENOMEM;
32
33
devfs_root
->
ino
= (
vino_t
)
devfs_root
;
34
devfs_root
->
mode
= S_IFDIR | 0775;
35
devfs_root
->
nlink
= 2;
36
devfs_root
->
fs
= &
devfs
;
37
devfs_root
->
ref
= 1;
38
39
struct
timespec
ts;
40
gettime
(&ts);
41
42
devfs_root
->
ctime
= ts;
43
devfs_root
->
atime
= ts;
44
devfs_root
->
mtime
= ts;
45
46
vfs_install
(&
devfs
);
47
48
return
0;
49
}
50
52
static
int
devfs_mount
(
struct
vnode
*dir,
int
flags,
void
*data)
53
{
54
if
(!
devfs_root
)
55
return
-EINVAL;
56
57
return
vfs_bind
(dir,
devfs_root
);
58
}
59
60
struct
fs
devfs
= {
61
.name =
"devfs"
,
62
.nodev = 1,
63
.init =
devfs_init
,
64
.mount =
devfs_mount
,
65
};
66
67
MODULE_INIT
(
devfs
,
devfs_init
,
NULL
)
devfs_root
struct vnode * devfs_root
Definition
devfs.c:21
devfs_init
static int devfs_init()
Sets devfs up at boot: tmpfs's operations, and its root directory.
Definition
devfs.c:24
devfs_mount
static int devfs_mount(struct vnode *dir, int flags, void *data)
Mounts devfs on a directory: its one root directory is bound there.
Definition
devfs.c:52
devfs
struct fs devfs
Definition
devfs.c:60
devfs.h
system.h
kmalloc
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition
kvmem.c:123
M_ZERO
#define M_ZERO
Definition
kvmem.h:26
module.h
MODULE_INIT
#define MODULE_INIT(name, i, f)
Definition
module.h:10
NULL
#define NULL
Definition
stddef.h:27
string.h
fs
A filesystem type.
Definition
vfs.h:98
fs::fops
struct fops fops
Definition
vfs.h:105
fs::vops
struct vops vops
Definition
vfs.h:104
timespec
Definition
types.h:30
vnode
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition
vfs.h:113
vnode::ino
ino_t ino
Definition
vfs.h:114
vnode::atime
_time_t atime
Definition
vfs.h:123
vnode::ctime
_time_t ctime
Definition
vfs.h:125
vnode::ref
size_t ref
how many references there are to it
Definition
vfs.h:133
vnode::nlink
nlink_t nlink
Definition
vfs.h:121
vnode::fs
struct fs * fs
Definition
vfs.h:127
vnode::mtime
_time_t mtime
Definition
vfs.h:124
vnode::mode
mode_t mode
Definition
vfs.h:118
gettime
int gettime(struct timespec *ts)
Reads the wall clock (CLOCK_REALTIME).
Definition
time.c:29
time.h
tmpfs
struct fs tmpfs
Definition
tmpfs.c:214
tmpfs.h
vino_t
uintptr_t vino_t
Definition
types.h:14
vfs_bind
int vfs_bind(struct vnode *dir, struct vnode *root)
Mounts a filesystem on a directory: a lookup that reaches dir goes on in root instead.
Definition
vfs.c:53
vfs_install
int vfs_install(struct fs *fs)
Installs a filesystem, so that it can be mounted by name.
Definition
vfs.c:85
vfs.h
kernel
fs
devfs
devfs.c
Generated by
1.18.0