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
| // error: -1: not directory, -2: not found
int vfs_mount(const char* device, const char* mountpoint, const char* filesystem) {
// check mountpoint is valid
struct vnode* mount_dir;
char path_remain[128];
traversal(mountpoint, &mount_dir, path_remain);
if (!strcmp(path_remain, "")) { // found
if (mount_dir->dentry->type != DIRECTORY) {
return -1;
}
}
else {
return -2;
}
// mount fs on mountpoint
struct mount* mt = (struct mount*)kmalloc(sizeof(struct mount));
if (!strcmp(filesystem, "tmpfs")) {
struct filesystem* tmpfs = (struct filesystem*)kmalloc(sizeof(struct filesystem));
tmpfs->name = (char*)kmalloc(sizeof(char) * strlen(device));
strcpy(tmpfs->name, device);
tmpfs->setup_mount = tmpfs_setup_mount;
tmpfs->setup_mount(tmpfs, mt);
mount_dir->dentry->mountpoint = mt;
mt->root->mount_origin = mount_dir->dentry;
}
return 0;
}
|