AquilaOS documentation
How it works, and its code
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 */
22
24static int devfs_init()
25{
26 /* devfs is a tmpfs */
29
30 devfs_root = kmalloc(sizeof(struct vnode), &M_VNODE, M_ZERO);
31 if (!devfs_root) return -ENOMEM;
32
34 devfs_root->mode = S_IFDIR | 0775;
35 devfs_root->nlink = 2;
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
47
48 return 0;
49}
50
52static 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
60struct fs devfs = {
61 .name = "devfs",
62 .nodev = 1,
63 .init = devfs_init,
64 .mount = devfs_mount,
65};
66
struct vnode * devfs_root
Definition devfs.c:21
static int devfs_init()
Sets devfs up at boot: tmpfs's operations, and its root directory.
Definition devfs.c:24
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
struct fs devfs
Definition devfs.c:60
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition kvmem.c:123
#define M_ZERO
Definition kvmem.h:26
#define MODULE_INIT(name, i, f)
Definition module.h:10
#define NULL
Definition stddef.h:27
A filesystem type.
Definition vfs.h:98
struct fops fops
Definition vfs.h:105
struct vops vops
Definition vfs.h:104
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
ino_t ino
Definition vfs.h:114
_time_t atime
Definition vfs.h:123
_time_t ctime
Definition vfs.h:125
size_t ref
how many references there are to it
Definition vfs.h:133
nlink_t nlink
Definition vfs.h:121
struct fs * fs
Definition vfs.h:127
_time_t mtime
Definition vfs.h:124
mode_t mode
Definition vfs.h:118
int gettime(struct timespec *ts)
Reads the wall clock (CLOCK_REALTIME).
Definition time.c:29
struct fs tmpfs
Definition tmpfs.c:214
uintptr_t vino_t
Definition types.h:14
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
int vfs_install(struct fs *fs)
Installs a filesystem, so that it can be mounted by name.
Definition vfs.c:85