terom@6: terom@6: #include terom@6: terom@6: #include "lib/log.h" terom@6: #include "lib/signals.h" terom@6: #include "evfuse.h" terom@6: #include "simple.h" terom@6: terom@6: static struct hello { terom@6: struct event_base *ev_base; terom@6: terom@6: struct signals *signals; terom@6: terom@6: struct simple_fs *fs; terom@6: terom@6: struct evfuse *ev_fuse; terom@6: terom@6: } ctx; terom@6: terom@6: static struct simple_node node_list[] = { terom@6: { 1, S_IFDIR, 0555, 0, NULL, NULL }, terom@6: { 2, S_IFREG, 0444, 1, "hello", "Hello World!\n" }, terom@10: { 3, S_IFREG, 0444, 1, "foo", "Foo\n" }, terom@10: { 4, S_IFREG, 0444, 1, "bar", "Bar\n" }, terom@10: { 5, S_IFDIR, 0555, 1, "test", NULL }, terom@10: { 6, S_IFREG, 0444, 5, "file0", "data0\n" }, terom@10: { 7, S_IFREG, 0444, 5, "file1", "data1\n" }, terom@10: { 8, S_IFLNK, 0444, 1, "lnk0", "test/file0" }, terom@6: { 0, 0, 0, 0, NULL, NULL }, terom@6: }; terom@6: terom@6: int main (int argc, char **argv) { terom@6: struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv); terom@6: terom@6: // init libevent terom@6: if ((ctx.ev_base = event_base_new()) == NULL) terom@6: ERROR("event_base_new"); terom@6: terom@6: // setup signals terom@6: if ((ctx.signals = signals_default(ctx.ev_base)) == NULL) terom@6: ERROR("signals_default"); terom@6: terom@6: // setup fs terom@6: if ((ctx.fs = simple_new(node_list)) == NULL) terom@6: ERROR("simple_new"); terom@6: terom@6: // open fuse terom@6: if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, simple_init(), ctx.fs)) == NULL) terom@6: ERROR("evfuse_new"); terom@6: terom@6: // run libevent terom@6: INFO("running libevent loop"); terom@6: terom@6: if (event_base_dispatch(ctx.ev_base)) terom@6: PERROR("event_base_dispatch"); terom@6: terom@6: // clean shutdown terom@6: terom@6: error : terom@6: // cleanup terom@6: if (ctx.ev_fuse) terom@27: evfuse_free(ctx.ev_fuse); terom@6: terom@6: /* terom@6: if (ctx.fs) terom@6: simple_close(ctx.fs); terom@6: */ terom@6: terom@6: if (ctx.signals) terom@6: signals_free(ctx.signals); terom@6: terom@6: if (ctx.ev_base) terom@6: event_base_free(ctx.ev_base); terom@6: terom@6: fuse_opt_free_args(&fuse_args); terom@6: } terom@6: