MOS Source Code
Loading...
Searching...
No Matches
userfs_manager.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
6#include "mos/syslog/printk.h"
7#include "mos/tasks/kthread.h"
9
10#include <librpc/rpc.h>
11#include <librpc/rpc_server.h>
12#include <mos/proto/fs_server.h>
13#include <mos_stdio.h>
14#include <pb_decode.h>
15#include <pb_encode.h>
16
19
20MOS_RPC_USERFS_MANAGER_SERVER(userfs_manager)
21
23{
24 userfs_t *userfs = kmalloc(userfs_slab);
25 if (!userfs)
27
28 linked_list_init(list_node(&userfs->fs));
29
30 size_t userfs_fsnamelen = strlen("userfs.") + strlen(req->fs.name) + 1;
31 userfs->fs.name = kmalloc(userfs_fsnamelen);
32 if (!userfs->fs.name)
33 {
34 kfree(userfs);
36 }
37
38 snprintf((char *) userfs->fs.name, userfs_fsnamelen, "userfs.%s", req->fs.name);
39 userfs->rpc_server_name = strdup(req->rpc_server_name);
40
41 resp->result.success = true;
42
43 userfs->fs.mount = userfs_fsop_mount;
45 return RPC_RESULT_OK;
46}
47
48static void userfs_manager_server_exec(void *arg)
49{
50 MOS_UNUSED(arg);
51 rpc_server_t *fs_server = rpc_server_create(USERFS_SERVER_RPC_NAME, NULL);
52 rpc_server_register_functions(fs_server, userfs_manager_functions, MOS_ARRAY_SIZE(userfs_manager_functions));
53 rpc_server_exec(fs_server);
54 pr_emerg("fs_rpc_execute_server exited");
55}
56
58{
60}
61
MOSAPI char * strdup(const char *src)
MOSAPI void linked_list_init(list_node_t *head_node)
Initialise a circular double linked list.
Definition list.c:15
#define list_node(element)
Get the ‘list_node’ of a list element. This is exactly the reverse of ‘list_entry’ above.
Definition list.h:68
void vfs_register_filesystem(filesystem_t *fs)
Definition vfs.c:452
thread_t * kthread_create(thread_entry_t entry, void *arg, const char *name)
Create a kernel-mode thread.
Definition kthread.c:36
#define MOS_ARRAY_SIZE(x)
Definition mos_global.h:81
#define MOS_UNUSED(x)
Definition mos_global.h:64
int snprintf(char *__restrict str, size_t size, const char *__restrict format,...)
Definition mos_stdio.c:16
#define NULL
Definition pb_syshdr.h:46
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
#define pr_emerg(fmt,...)
Definition printk.h:39
rpc_result_code_t
Definition rpc.h:25
@ RPC_RESULT_SERVER_INTERNAL_ERROR
Definition rpc.h:29
@ RPC_RESULT_OK
Definition rpc.h:26
MOSAPI rpc_server_t * rpc_server_create(const char *server_name, void *data)
Create a new RPC server.
Definition rpc_server.c:213
MOSAPI bool rpc_server_register_functions(rpc_server_t *server, const rpc_function_info_t *functions, size_t count)
Register multiple functions with the server.
Definition rpc_server.c:299
MOSAPI void rpc_server_exec(rpc_server_t *server)
Run the server, this function will not return until the server is destroyed.
Definition rpc_server.c:271
#define MOS_INIT(_comp, _fn)
Definition setup.h:40
#define SLAB_AUTOINIT(name, var, type)
dentry_t *(* mount)(filesystem_t *fs, const char *dev_name, const char *mount_options)
Definition vfs_types.h:184
const char * name
Definition vfs_types.h:183
Definition slab.h:45
const char * rpc_server_name
The name of the RPC server.
Definition userfs.h:13
filesystem_t fs
The filesystem, "userfs.<name>".
Definition userfs.h:12
dentry_t * userfs_fsop_mount(filesystem_t *fs, const char *device, const char *options)
Definition userfs.c:542
static void userfs_manager_rpc_init()
static slab_t * userfs_slab
static rpc_result_code_t userfs_manager_register_filesystem(rpc_context_t *, mosrpc_userfs_register_request *req, mosrpc_userfs_register_response *resp)
static void userfs_manager_server_exec(void *arg)