lib: fs: implement mounting filesystems; reading, writing from files
This commit is contained in:
@@ -1,21 +1,53 @@
|
||||
#include "../file.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fs/context.h>
|
||||
#include <fs/file.h>
|
||||
#include <fs/status.h>
|
||||
|
||||
extern kern_status_t fs_msg_open(
|
||||
const struct msg_endpoint *sender,
|
||||
const char *path,
|
||||
xpc_context_t *xpc,
|
||||
xpc_endpoint_t *sender,
|
||||
const xpc_string_t *path,
|
||||
int flags,
|
||||
int *out_err,
|
||||
void *arg)
|
||||
{
|
||||
char path_buf[4096];
|
||||
size_t path_len = 0;
|
||||
kern_status_t status
|
||||
= xpc_string_read(path, path_buf, sizeof path_buf, &path_len);
|
||||
if (status != KERN_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
struct fs_context *ctx = arg;
|
||||
|
||||
struct fs_dentry *dent = fs_context_resolve_path(ctx, path);
|
||||
if (!dent) {
|
||||
*out_err = ENOENT;
|
||||
struct fs_file *f = fs_context_open_file(ctx, sender->e_port);
|
||||
if (!f) {
|
||||
*out_err = ENOMEM;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
if (f->f_inode) {
|
||||
*out_err = EBUSY;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
struct fs_dentry *dent = NULL;
|
||||
enum fs_status fs_status
|
||||
= fs_context_resolve_path(ctx, path_buf, &dent);
|
||||
if (fs_status != FS_SUCCESS) {
|
||||
fs_context_close_file(ctx, f);
|
||||
*out_err = fs_status_to_errno(status);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
f->f_seek = 0;
|
||||
f->f_dent = dent;
|
||||
f->f_inode = dent->d_inode;
|
||||
f->f_ops = dent->d_inode->i_fops;
|
||||
|
||||
*out_err = SUCCESS;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user