src/dbfs/dbfs.c
changeset 30 d8fabd347a8e
parent 29 5de62ca9a5aa
child 31 7804cd7b5cd5
equal deleted inserted replaced
29:5de62ca9a5aa 30:d8fabd347a8e
     2 #include <stdlib.h>
     2 #include <stdlib.h>
     3 
     3 
     4 #include "dbfs.h"
     4 #include "dbfs.h"
     5 #include "../dbfs.h"
     5 #include "../dbfs.h"
     6 #include "../lib/log.h"
     6 #include "../lib/log.h"
     7 #include "../lib/misc.h"
       
     8 
     7 
     9 static struct fuse_lowlevel_ops dbfs_llops = {
     8 static struct fuse_lowlevel_ops dbfs_llops = {
    10 
     9 
    11     .init           = dbfs_init,
    10     .init           = dbfs_init,
    12     .destroy        = dbfs_destroy,
    11     .destroy        = dbfs_destroy,
    13     
    12     
    14     .lookup         = dbfs_lookup,
    13     .lookup         = dbfs_lookup,
    15 
    14 
    16     .getattr        = dbfs_getattr,
    15     .getattr        = dbfs_getattr,
       
    16 
       
    17     .open           = dbfs_open,
       
    18     .read           = dbfs_read,
       
    19     // .write       = dbfs_write,
       
    20     .flush          = dbfs_flush,
       
    21     .release        = dbfs_release,
    17 
    22 
    18     .opendir        = dbfs_opendir,
    23     .opendir        = dbfs_opendir,
    19     .readdir        = dbfs_readdir,
    24     .readdir        = dbfs_readdir,
    20     .releasedir     = dbfs_releasedir,
    25     .releasedir     = dbfs_releasedir,
    21 };
    26 };
    41     WARNING("[dbfs] SQL error: BREAKING MAIN LOOP LIEK NAO");
    46     WARNING("[dbfs] SQL error: BREAKING MAIN LOOP LIEK NAO");
    42 
    47 
    43     event_base_loopbreak(ctx->ev_base);
    48     event_base_loopbreak(ctx->ev_base);
    44 }
    49 }
    45 
    50 
    46 struct dbfs *dbfs_open (struct event_base *ev_base, struct fuse_args *args, const char *db_conninfo) {
    51 struct dbfs *dbfs_new (struct event_base *ev_base, struct fuse_args *args, const char *db_conninfo) {
    47     struct dbfs *ctx = NULL;
    52     struct dbfs *ctx = NULL;
    48 
    53 
    49     // alloc ctx
    54     // alloc ctx
    50     if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
    55     if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
    51         ERROR("calloc");
    56         ERROR("calloc");
    64     // success
    69     // success
    65     return ctx;
    70     return ctx;
    66 
    71 
    67 error:
    72 error:
    68     if (ctx)
    73     if (ctx)
    69         dbfs_release(ctx);
    74         dbfs_free(ctx);
    70 
    75 
    71     return NULL;
    76     return NULL;
    72 }    
    77 }    
    73 
    78 
    74 void dbfs_release (struct dbfs *ctx) {
    79 void dbfs_free (struct dbfs *ctx) {
    75     // cleanup
    80     // cleanup
    76     if (ctx->ev_fuse) {
    81     if (ctx->ev_fuse) {
    77         evfuse_free(ctx->ev_fuse);
    82         evfuse_free(ctx->ev_fuse);
    78     
    83     
    79         ctx->ev_fuse = NULL;
    84         ctx->ev_fuse = NULL;