AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
initramfs.c
Go to the documentation of this file.
1
7
8#include <core/system.h>
9#include <core/string.h>
10#include <core/panic.h>
11#include <mm/mm.h>
12
13#include <dev/ramdev.h>
14#include <fs/vfs.h>
15#include <fs/initramfs.h>
16#include <fs/devfs.h>
17#include <fs/posix.h>
18#include <aquila/errno.h>
19
20#include <ds/queue.h>
21#include <boot/boot.h>
22
23static struct vnode *rd_dev = NULL;
24static struct queue *archivers = QUEUE_NEW();
25
33{
34 if (!enqueue(archivers, fs))
35 return -ENOMEM;
36
37 printk("initramfs: registered archiver: %s\n", fs->name);
38
39 return 0;
40}
41
50{
51 printk("kernel: loading ramdisk\n");
52
53 rd_dev = kmalloc(sizeof(struct vnode), &M_VNODE, M_ZERO);
54 if (!rd_dev) return -ENOMEM;
55
56 extern size_t rd_size;
57
58 rd_dev->mode = S_IFBLK;
59 rd_dev->rdev = DEV(1, 0);
61 rd_dev->fs = &devfs;
62
63 struct vnode *root = NULL;
64 int err = -1;
65
66 queue_for (node, archivers) {
67 struct fs *fs = node->value;
68
69 if (!(err = fs->load(rd_dev, &root)))
70 break;
71 }
72
73 if (err) {
74 printk("Error code = %d\n", err);
75 panic("Could not load ramdisk\n");
76 }
77
78 return vfs_mount_root(root);
79}
#define panic(s)
Definition panic.h:15
#define DEV(major, minor)
Definition dev.h:76
struct fs devfs
Definition devfs.c:60
static struct vnode * rd_dev
Definition initramfs.c:23
int initramfs_archiver_register(struct fs *fs)
Registers a filesystem that can make a root from a RAM disk archive.
Definition initramfs.c:32
int load_ramdisk(module_t *module)
Mounts the RAM disk as the root filesystem.
Definition initramfs.c:49
static struct queue * archivers
Definition initramfs.c:24
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
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
#define queue_for(n, q)
Definition queue.h:37
#define QUEUE_NEW()
Definition queue.h:40
size_t rd_size
Definition ramdisk.c:25
#define NULL
Definition stddef.h:27
A filesystem type.
Definition vfs.h:98
char * name
Definition vfs.h:99
int(*) load(struct vnode *dev, struct vnode **super)
Definition vfs.h:101
A queue.
Definition queue.h:29
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
struct fs * fs
Definition vfs.h:127
size_t size
Definition vfs.h:115
mode_t mode
Definition vfs.h:118
dev_t rdev
Definition vfs.h:117
int vfs_mount_root(struct vnode *vnode)
Makes a vnode the root of the filesystem tree.
Definition vfs.c:37