45,10 → 45,154 |
#include <libadt/list.h> |
#include "vfs.h" |
|
vfs_node_t *rootfs = NULL; |
vfs_node_t rootfs = { 0 }; |
|
static int lookup_root(int fs_handle, int dev_handle, vfs_node_t *root) |
{ |
vfs_node_t altroot = { |
.fs_handle = fs_handle, |
.dev_handle = dev_handle, |
/* |
* At this point, we don't know what is the index of the root |
* node. Finally, that's what this function is about. |
*/ |
}; |
|
return vfs_lookup_internal("/", 1, root, &altroot); |
} |
|
void vfs_mount(ipc_callid_t rid, ipc_call_t *request) |
{ |
int dev_handle; |
|
/* |
* We expect the library to do the device-name to device-handle |
* translation for us, thus the device handle will arrive as ARG1 |
* in the request. |
*/ |
dev_handle = IPC_GET_ARG1(*request); |
|
/* |
* For now, don't make use of ARG2 and ARG3, but they can be used to |
* carry mount options in the future. |
*/ |
|
/* |
* Now, we expect the client to send us data with the name of the file |
* system and the path of the mountpoint. |
*/ |
ipc_callid_t callid; |
ipc_call_t call; |
size_t size; |
if (!ipc_data_receive(&callid, &call, NULL, &size)) { |
ipc_answer_fast(callid, EINVAL, 0, 0); |
ipc_answer_fast(rid, EINVAL, 0, 0); |
return; |
} |
|
/* |
* There is no sense in receiving data that can't hold a single |
* character of path. We won't accept data that exceed certain limits |
* either. |
*/ |
if ((size < FS_NAME_MAXLEN + 1) || |
(size > FS_NAME_MAXLEN + MAX_PATH_LEN)) { |
ipc_answer_fast(callid, EINVAL, 0, 0); |
ipc_answer_fast(rid, EINVAL, 0, 0); |
return; |
} |
|
/* |
* Allocate buffer for the data being received. |
*/ |
uint8_t *buf; |
buf = malloc(size); |
if (!buf) { |
ipc_answer_fast(callid, ENOMEM, 0, 0); |
ipc_answer_fast(rid, ENOMEM, 0, 0); |
return; |
} |
|
/* |
* Deliver the data. |
*/ |
(void) ipc_data_deliver(callid, &call, buf, size); |
|
char fs_name[FS_NAME_MAXLEN + 1]; |
memcpy(fs_name, buf, FS_NAME_MAXLEN); |
fs_name[FS_NAME_MAXLEN] = '\0'; |
|
/* |
* Check if we know a file system with the same name as is in fs_name. |
* This will also give us its file system handle. |
*/ |
int fs_handle = fs_name_to_handle(fs_name, true); |
if (!fs_handle) { |
free(buf); |
ipc_answer_fast(rid, ENOENT, 0, 0); |
return; |
} |
|
/* |
* Lookup the root node of the filesystem being mounted. |
*/ |
int rc; |
vfs_node_t mounted_root; |
rc = lookup_root(fs_handle, dev_handle, &mounted_root); |
if (rc != EOK) { |
free(buf); |
ipc_answer_fast(rid, rc, 0, 0); |
return; |
} |
|
/* |
* Finally, we need to resolve the path to the mountpoint. |
*/ |
vfs_node_t mp; |
if (rootfs.fs_handle) { |
/* |
* We already have the root FS. |
*/ |
rc = vfs_lookup_internal((char *) (buf + FS_NAME_MAXLEN), |
size - FS_NAME_MAXLEN, &mp, NULL); |
if (rc != EOK) { |
/* |
* The lookup failed for some reason. |
*/ |
free(buf); |
ipc_answer_fast(rid, rc, 0, 0); |
return; |
} |
} else { |
/* |
* We still don't have the root file system mounted. |
*/ |
if ((size - FS_NAME_MAXLEN == 1) && |
(buf[FS_NAME_MAXLEN] == '/')) { |
/* |
* For this simple, but important case, we are done. |
*/ |
rootfs = mounted_root; |
free(buf); |
ipc_answer_fast(rid, EOK, 0, 0); |
return; |
} else { |
/* |
* We can't resolve this without the root filesystem |
* being mounted first. |
*/ |
free(buf); |
ipc_answer_fast(rid, ENOENT, 0, 0); |
return; |
} |
} |
|
/* |
* At this point, we have all necessary pieces: file system and device |
* handles, and we know the mount point VFS node and also the root node |
* of the file system being mounted. |
*/ |
|
} |
|
/** |