aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs/vfs.c
blob: fd44f303435709df5af1ec764cee0992a0d4cee8 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdint.h>
#include <stddef.h>
#include <kernel/fs/vfs.h>
#include <kernel/lib/stdlib.h>

struct fs_node *fs_root = NULL;

uint32_t fs_read(struct fs_node *node, uint32_t offset, uint32_t size, char *buf)
{
	if (node->read != NULL)
		return node->read(node, offset, size, buf);
	else
		return 0;
}

uint32_t fs_write(struct fs_node *node, uint32_t offset, uint32_t size, char *buf)
{
	if (node->write != NULL)
		return node->write(node, offset, size, buf);
	else
		return 0;
}

void fs_open(struct fs_node *node)
{
	if (node->open != NULL)
		node->open(node);
}

void fs_close(struct fs_node *node)
{
	if (node->close != NULL)
		node->close(node);
}

struct dirent *fs_read_dir(struct fs_node *node, uint32_t index)
{
	if ((node->type & DIR_NODE) != 0 && node->find_dir != NULL)
		return node->read_dir(node, index);
	else
		return (struct dirent *)NULL;
}

struct fs_node *fs_find_dir(struct fs_node *node, char *name)
{
	if ((node->type & DIR_NODE) != 0 && node->find_dir != NULL)
		return node->find_dir(node, name);
	else
		return (struct fs_node *)NULL;
}