src/dbfs/common.h
changeset 28 e944453ca924
equal deleted inserted replaced
27:461be4cd34a3 28:e944453ca924
       
     1 #ifndef DBFS_COMMON_H
       
     2 #define DBFS_COMMON_H
       
     3 
       
     4 #include <sys/stat.h>
       
     5 #include <errno.h>
       
     6 
       
     7 #include <event2/event.h>
       
     8 
       
     9 #include "../evfuse.h"
       
    10 #include "../evsql.h"
       
    11 #include "../lib/log.h"
       
    12 #include "../lib/misc.h"
       
    13 
       
    14 /*
       
    15  * Structs and functions shared between all dbfs components
       
    16  */
       
    17 
       
    18 #define SERROR(val) do { (val); goto error; } while(0)
       
    19 
       
    20 struct dbfs {
       
    21     struct event_base *ev_base;
       
    22     
       
    23     const char *db_conninfo;
       
    24     struct evsql *db;
       
    25 
       
    26     struct evfuse *ev_fuse;
       
    27 };
       
    28 
       
    29 // XXX: not sure how this should work
       
    30 #define CACHE_TIMEOUT 1.0
       
    31 
       
    32 /*
       
    33  * Convert the CHAR(4) inodes.type from SQL into a mode_t.
       
    34  *
       
    35  * Returns zero for unknown types.
       
    36  */
       
    37 mode_t _dbfs_mode (const char *type);
       
    38 
       
    39 /*
       
    40  * Check that the number of rows and columns in the result set matches what we expect.
       
    41  *
       
    42  * If rows is nonzero, there must be exactly that many rows (mostly useful for rows=1).
       
    43  * The number of columns must always be given, and match.
       
    44  *
       
    45  * Returns;
       
    46  *  -1  if the query failed, the columns/rows do not match
       
    47  *  0   the results match
       
    48  *  1   there were no results (zero rows)
       
    49  */
       
    50 int _dbfs_check_res (const struct evsql_result_info *res, size_t rows, size_t cols);
       
    51 
       
    52 /*
       
    53  * Fill a `struct state` with info retrieved from a SQL query.
       
    54  *
       
    55  * The result must contain four columns, starting at the given offset:
       
    56  *  inodes.type, inodes.mode, inodes.size, count(*) AS nlink
       
    57  *
       
    58  * Note that this does not fill the st_ino field
       
    59  */
       
    60 int _dbfs_stat_info (struct stat *st, const struct evsql_result_info *res, size_t row, size_t col_offset);
       
    61 
       
    62 #endif /* DBFS_COMMON_H */