terom@29: #ifndef DBFS_DBFS_H terom@29: #define DBFS_DBFS_H terom@29: terom@29: #include terom@29: #include terom@29: terom@29: #include terom@29: terom@29: #include "ops.h" terom@29: #include "../evfuse.h" terom@29: #include "../evsql.h" terom@29: terom@29: /* terom@29: * Structs and functions shared between all dbfs components terom@29: */ terom@29: terom@29: #define SERROR(val) do { (val); goto error; } while(0) terom@29: terom@29: struct dbfs { terom@29: struct event_base *ev_base; terom@29: terom@29: const char *db_conninfo; terom@29: struct evsql *db; terom@29: terom@29: struct evfuse *ev_fuse; terom@29: }; terom@29: terom@29: // XXX: not sure how this should work terom@29: #define CACHE_TIMEOUT 1.0 terom@29: terom@29: /* terom@29: * Convert the CHAR(4) inodes.type from SQL into a mode_t. terom@29: * terom@29: * Returns zero for unknown types. terom@29: */ terom@29: mode_t _dbfs_mode (const char *type); terom@29: terom@29: /* terom@29: * Check that the number of rows and columns in the result set matches what we expect. terom@29: * terom@29: * If rows is nonzero, there must be exactly that many rows (mostly useful for rows=1). terom@29: * The number of columns must always be given, and match. terom@29: * terom@29: * Returns; terom@29: * -1 if the query failed, the columns/rows do not match terom@29: * 0 the results match terom@29: * 1 there were no results (zero rows) terom@29: */ terom@29: int _dbfs_check_res (const struct evsql_result_info *res, size_t rows, size_t cols); terom@29: terom@29: /* terom@29: * Fill a `struct state` with info retrieved from a SQL query. terom@29: * terom@29: * The result must contain four columns, starting at the given offset: terom@29: * inodes.type, inodes.mode, inodes.size, count(*) AS nlink terom@29: * terom@29: * Note that this does not fill the st_ino field terom@29: */ terom@29: int _dbfs_stat_info (struct stat *st, const struct evsql_result_info *res, size_t row, size_t col_offset); terom@29: terom@29: #endif /* DBFS_DBFS_H */