summaryrefslogtreecommitdiff
path: root/src/kernel/vfs/mount.c
blob: bd06370e0f283d32542ba292851458c09950bc86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <kernel/mem.h>
#include <kernel/util.h>
#include <kernel/vfs/mount.h>

struct vfs_mount *vfs_mount_seed(void) {
	struct vfs_mount *mount = kmalloc(sizeof(struct vfs_mount));
	*mount = (struct vfs_mount){
		.prev = NULL,
		.prefix = "/tty",
		.prefix_len = 4,
		.fd = {
			.type = FD_SPECIAL_TTY,
		},
	};
	return mount;
}

struct vfs_mount *vfs_mount_resolve(
		struct vfs_mount *top, const char *path, size_t path_len)
{
	for (; top; top = top->prev) {
		if (top->prefix_len > path_len)
			continue;
		if (memcmp(top->prefix, path, top->prefix_len) != 0)
			continue;

		/* ensure that there's no garbage after the match
		 * recognize that e.g. /thisasdf doesn't get recognized as mounted under
		 * /this */
		
		if (top->prefix_len == path_len) // can't happen if prefix == path
			break;
		if (path[top->prefix_len] == '/')
			break;
	}
	return top;
}