5 |
5 |
6 /* |
6 /* |
7 * Core fs functionality like lookup, getattr |
7 * Core fs functionality like lookup, getattr |
8 */ |
8 */ |
9 |
9 |
10 void _dbfs_lookup_result (const struct evsql_result_info *res, void *arg) { |
|
11 struct fuse_req *req = arg; |
|
12 struct fuse_entry_param e; ZINIT(e); |
|
13 int err = 0; |
|
14 |
|
15 uint32_t ino; |
|
16 |
|
17 // check the results |
|
18 if ((err = _dbfs_check_res(res, 1, 5))) |
|
19 SERROR(err = (err == 1 ? ENOENT : EIO)); |
|
20 |
|
21 // get the data |
|
22 if (0 |
|
23 || evsql_result_uint32(res, 0, 0, &ino, 0 ) // inodes.ino |
|
24 ) |
|
25 EERROR(err = EIO, "invalid db data"); |
|
26 |
|
27 INFO("\t[dbfs.lookup] -> ino=%u", ino); |
|
28 |
|
29 // stat attrs |
|
30 if ((err = _dbfs_stat_info(&e.attr, res, 0, 1))) |
|
31 goto error; |
|
32 |
10 |
33 // other attrs |
|
34 e.ino = e.attr.st_ino = ino; |
|
35 e.attr_timeout = CACHE_TIMEOUT; |
|
36 e.entry_timeout = CACHE_TIMEOUT; |
|
37 |
|
38 // reply |
|
39 if ((err = fuse_reply_entry(req, &e))) |
|
40 EERROR(err, "fuse_reply_entry"); |
|
41 |
|
42 error: |
|
43 if (err && (err = fuse_reply_err(req, err))) |
|
44 EWARNING(err, "fuse_reply_err"); |
|
45 |
|
46 // free |
|
47 evsql_result_free(res); |
|
48 } |
|
49 |
|
50 void dbfs_lookup (struct fuse_req *req, fuse_ino_t parent, const char *name) { |
|
51 struct dbfs *ctx = fuse_req_userdata(req); |
|
52 int err; |
|
53 |
|
54 INFO("[dbfs.lookup] parent=%lu name=%s", parent, name); |
|
55 |
|
56 // query and params |
|
57 const char *sql = |
|
58 "SELECT" |
|
59 " inodes.ino, " DBFS_STAT_COLS |
|
60 " FROM file_tree INNER JOIN inodes ON (file_tree.ino = inodes.ino)" |
|
61 " WHERE file_tree.parent = $1::int4 AND file_tree.name = $2::varchar"; |
|
62 |
|
63 static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
64 EVSQL_PARAM ( UINT32 ), |
|
65 EVSQL_PARAM ( STRING ), |
|
66 |
|
67 EVSQL_PARAMS_END |
|
68 }; |
|
69 |
|
70 // build params |
|
71 if (0 |
|
72 || evsql_param_uint32(¶ms, 0, parent) |
|
73 || evsql_param_string(¶ms, 1, name) |
|
74 ) |
|
75 EERROR(err = EIO, "evsql_param_*"); |
|
76 |
|
77 // query |
|
78 if (evsql_query_params(ctx->db, NULL, sql, ¶ms, _dbfs_lookup_result, req) == NULL) |
|
79 EERROR(err = EIO, "evsql_query_params"); |
|
80 |
|
81 // XXX: handle interrupts |
|
82 |
|
83 // wait |
|
84 return; |
|
85 |
|
86 error: |
|
87 if ((err = fuse_reply_err(req, err))) |
|
88 EWARNING(err, "fuse_reply_err"); |
|
89 } |
|
90 |
|