David van Moolenbroek 5eefd0fec2 libvtreefs: API changes/extensions, part 1
- move primary I/O buffer into vtreefs; change read hook API;
- add hooks for write, truncate, symlink, mknod, unlink, chmod/chown;
- modernize message_hook;
- change procfs, devman, gpio accordingly;

Change-Id: I9f0669e41195efa3253032e95d93f0a78e9d68d6
2014-11-12 12:13:38 +00:00

107 lines
2.1 KiB
C

/* VTreeFS - vtreefs.c - initialization and message loop */
#include "inc.h"
static unsigned int inodes;
static struct inode_stat *root_stat;
static index_t root_entries;
static size_t buf_size;
/*
* Initialize internal state. This is the only place where dynamic memory
* allocation takes place.
*/
static int
init_server(int __unused type, sef_init_info_t * __unused info)
{
int r;
/* Initialize the virtual tree. */
if ((r = init_inodes(inodes, root_stat, root_entries)) != OK)
panic("init_inodes failed: %d", r);
/* Initialize the I/O buffer. */
if ((r = init_buf(buf_size)) != OK)
panic("init_buf failed: %d", r);
return OK;
}
/*
* We received a signal.
*/
static void
got_signal(int signal)
{
if (signal != SIGTERM)
return;
fsdriver_terminate();
}
/*
* SEF initialization.
*/
static void
sef_local_startup(void)
{
sef_setcb_init_fresh(init_server);
sef_setcb_init_restart(init_server);
sef_setcb_signal_handler(got_signal);
/* No support for live update yet. */
sef_startup();
}
/*
* We have received a message that is not a file system request from VFS.
* Call the message hook, if there is one.
*/
void
fs_other(const message * m_ptr, int ipc_status)
{
message msg;
if (vtreefs_hooks->message_hook != NULL) {
/*
* Not all of vtreefs's users play nice with the message, so
* make a copy to allow it to be modified.
*/
msg = *m_ptr;
vtreefs_hooks->message_hook(&msg, ipc_status);
}
}
/*
* This is the main routine of this service. It uses the main loop as provided
* by the fsdriver library. The routine returns once the file system has been
* unmounted and the process is signaled to exit.
*/
void
start_vtreefs(struct fs_hooks * hooks, unsigned int nr_inodes,
struct inode_stat * stat, index_t nr_indexed_entries, size_t bufsize)
{
/*
* Use global variables to work around the inability to pass parameters
* through SEF to the initialization function..
*/
vtreefs_hooks = hooks;
inodes = nr_inodes;
root_stat = stat;
root_entries = nr_indexed_entries;
buf_size = bufsize;
sef_local_startup();
fsdriver_task(&vtreefs_table);
cleanup_buf();
cleanup_inodes();
}