src/simple_hello.c
changeset 56 9dfc861273e5
parent 42 40a3b13ffc9d
child 57 527d23bf6441
equal deleted inserted replaced
42:40a3b13ffc9d 56:9dfc861273e5
     1 
       
     2 #include <event2/event.h>
       
     3 
       
     4 #include "lib/log.h"
       
     5 #include "lib/signals.h"
       
     6 #include "evfuse.h"
       
     7 #include "simple.h"
       
     8 
       
     9 static struct hello {
       
    10     struct event_base *ev_base;
       
    11 
       
    12     struct signals *signals;
       
    13 
       
    14     struct simple_fs *fs;
       
    15 
       
    16     struct evfuse *ev_fuse;
       
    17 
       
    18 } ctx;
       
    19 
       
    20 static struct simple_node node_list[] = {
       
    21     {   1,  S_IFDIR,    0555,   0,  NULL,       NULL                },
       
    22     {   2,  S_IFREG,    0444,   1,  "hello",    "Hello World!\n"    },
       
    23     {   3,  S_IFREG,    0444,   1,  "foo",      "Foo\n"             },
       
    24     {   4,  S_IFREG,    0444,   1,  "bar",      "Bar\n"             },
       
    25     {   5,  S_IFDIR,    0555,   1,  "test",     NULL                },
       
    26     {   6,  S_IFREG,    0444,   5,  "file0",    "data0\n"           },
       
    27     {   7,  S_IFREG,    0444,   5,  "file1",    "data1\n"           },
       
    28     {   8,  S_IFLNK,    0444,   1,  "lnk0",     "test/file0"        },
       
    29     {   0,  0,          0,      0,  NULL,       NULL                },
       
    30 };
       
    31 
       
    32 int main (int argc, char **argv) {
       
    33     struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv);
       
    34     
       
    35     // init libevent
       
    36     if ((ctx.ev_base = event_base_new()) == NULL)
       
    37         ERROR("event_base_new");
       
    38     
       
    39     // setup signals
       
    40     if ((ctx.signals = signals_default(ctx.ev_base)) == NULL)
       
    41         ERROR("signals_default");
       
    42     
       
    43     // setup fs
       
    44     if ((ctx.fs = simple_new(node_list)) == NULL)
       
    45         ERROR("simple_new");
       
    46 
       
    47     // open fuse
       
    48     if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, simple_init(), ctx.fs)) == NULL)
       
    49         ERROR("evfuse_new");
       
    50 
       
    51     // run libevent
       
    52     INFO("running libevent loop");
       
    53 
       
    54     if (event_base_dispatch(ctx.ev_base))
       
    55         PERROR("event_base_dispatch");
       
    56     
       
    57     // clean shutdown
       
    58 
       
    59 error :
       
    60     // cleanup
       
    61     if (ctx.ev_fuse)
       
    62         evfuse_free(ctx.ev_fuse);
       
    63 
       
    64 /*
       
    65     if (ctx.fs)
       
    66         simple_close(ctx.fs);
       
    67 */
       
    68 
       
    69     if (ctx.signals)
       
    70         signals_free(ctx.signals);
       
    71 
       
    72     if (ctx.ev_base)
       
    73         event_base_free(ctx.ev_base);
       
    74     
       
    75     fuse_opt_free_args(&fuse_args);
       
    76 }
       
    77