87 lines
1.5 KiB
C
87 lines
1.5 KiB
C
#include "btree.h"
|
|
#include "file.h"
|
|
#include "interface.h"
|
|
|
|
#include <fs/allocator.h>
|
|
#include <fs/context.h>
|
|
|
|
BTREE_DEFINE_SIMPLE_GET(struct fs_file, unsigned long, f_node, f_id, get_file);
|
|
BTREE_DEFINE_SIMPLE_INSERT(struct fs_file, f_node, f_id, put_file);
|
|
|
|
struct fs_context {
|
|
struct fs_superblock *ctx_sb;
|
|
struct fs_allocator *ctx_alloc;
|
|
struct btree ctx_filelist;
|
|
|
|
struct fs_vtable ctx_vtable;
|
|
};
|
|
|
|
struct fs_context *fs_context_create(
|
|
struct fs_allocator *alloc,
|
|
struct fs_superblock *sb)
|
|
{
|
|
struct fs_context *ctx = fs_alloc(alloc, sizeof *ctx);
|
|
if (!ctx) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(ctx, 0x0, sizeof *ctx);
|
|
|
|
ctx->ctx_sb = sb;
|
|
ctx->ctx_alloc = alloc;
|
|
|
|
ctx->ctx_vtable.open = fs_msg_open;
|
|
|
|
return ctx;
|
|
}
|
|
|
|
void fs_context_destroy(struct fs_context *ctx)
|
|
{
|
|
fs_free(ctx->ctx_alloc, ctx);
|
|
}
|
|
|
|
struct fs_file *fs_context_open_file(struct fs_context *ctx, unsigned long id)
|
|
{
|
|
struct fs_file *f = get_file(&ctx->ctx_filelist, id);
|
|
if (!f) {
|
|
f = fs_alloc(ctx->ctx_alloc, sizeof *f);
|
|
if (!f) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(f, 0x0, sizeof *f);
|
|
|
|
f->f_id = id;
|
|
put_file(&ctx->ctx_filelist, f);
|
|
}
|
|
|
|
return f;
|
|
}
|
|
|
|
void fs_context_close_file(struct fs_context *ctx, struct fs_file *f)
|
|
{
|
|
}
|
|
|
|
struct fs_dentry *fs_context_resolve_path(
|
|
struct fs_context *ctx,
|
|
const char *path)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
kern_status_t fs_context_dispatch_msg(
|
|
struct fs_context *ctx,
|
|
kern_handle_t channel,
|
|
struct msg_endpoint *sender,
|
|
struct msg_header *hdr)
|
|
{
|
|
return fs_dispatch(
|
|
channel,
|
|
&ctx->ctx_vtable,
|
|
sender,
|
|
hdr,
|
|
NULL,
|
|
0,
|
|
ctx);
|
|
}
|