src/dbfs/link.c
branchnew-evsql
changeset 49 bb2ff0d2d343
parent 48 8b019d191353
child 50 881de320e483
equal deleted inserted replaced
48:8b019d191353 49:bb2ff0d2d343
    11  * Used for lookup and link
    11  * Used for lookup and link
    12  */
    12  */
    13 void dbfs_entry_res (struct evsql_result *res, void *arg) {
    13 void dbfs_entry_res (struct evsql_result *res, void *arg) {
    14     struct fuse_req *req = arg;
    14     struct fuse_req *req = arg;
    15     struct fuse_entry_param e; ZINIT(e);
    15     struct fuse_entry_param e; ZINIT(e);
    16     int err = 0;
    16     err_t err = 0;
    17     
    17     
    18     uint32_t ino;
    18     uint32_t ino;
    19     
    19     struct dbfs_stat_values stat_values;
    20     // check the results
    20 
    21     if ((err = _dbfs_check_res(res, 1, 5)))
    21     // result info
    22         SERROR(err = (err ==  1 ? ENOENT : EIO));
    22     static struct evsql_result_info result_info = {
    23     
    23         0, {
    24     // get the data
    24             {   EVSQL_FMT_BINARY,   EVSQL_TYPE_UINT32   },  // inodes.ino
    25     if (0
    25             DBFS_STAT_RESULT_INFO,
    26         ||  evsql_result_uint32(res, 0, 0, &ino,        0 ) // inodes.ino
    26             {   0,                  0                   }
    27     )
    27         }
    28         EERROR(err = EIO, "invalid db data");
    28     };
    29         
    29 
       
    30     // begin
       
    31     if ((err = evsql_result_begin(&result_info, res)))
       
    32         EERROR(err, "query failed");
       
    33 
       
    34     // get the one row of data
       
    35     if ((err = evsql_result_next(res, &ino, DBFS_STAT_RESULT_VALUES(&stat_values))) <= 0)
       
    36         EERROR(err = (err ? err : ENOENT), "evsql_result_next");
       
    37    
    30     INFO("\t[dbfs.lookup] -> ino=%u", ino);
    38     INFO("\t[dbfs.lookup] -> ino=%u", ino);
    31     
    39     
    32     // stat attrs
    40     // stat attrs
    33     if ((err = _dbfs_stat_info(&e.attr, res, 0, 1)))
    41     if ((err = _dbfs_stat_info(&e.attr, &stat_values)))
    34         goto error;
    42         goto error;
    35 
    43     
    36     // other attrs
    44     // other attrs
    37     e.ino = e.attr.st_ino = ino;
    45     e.ino = e.attr.st_ino = ino;
    38     e.attr_timeout = CACHE_TIMEOUT;
    46     e.attr_timeout = CACHE_TIMEOUT;
    39     e.entry_timeout = CACHE_TIMEOUT;
    47     e.entry_timeout = CACHE_TIMEOUT;
    40         
    48         
    44 
    52 
    45 error:
    53 error:
    46     if (err && (err = -fuse_reply_err(req, err)))
    54     if (err && (err = -fuse_reply_err(req, err)))
    47         EWARNING(err, "fuse_reply_err");
    55         EWARNING(err, "fuse_reply_err");
    48 
    56 
    49     // free
    57     // done
    50     evsql_result_free(res);
    58     evsql_result_end(res);
    51 }
    59 }
    52 
    60 
    53 void dbfs_lookup (struct fuse_req *req, fuse_ino_t parent, const char *name) {
    61 void dbfs_lookup (struct fuse_req *req, fuse_ino_t parent, const char *name) {
    54     struct dbfs *ctx = fuse_req_userdata(req);
    62     struct dbfs *ctx = fuse_req_userdata(req);
    55     struct evsql_query *query;
    63     struct evsql_query *query;