23 |
23 |
24 // is it a symlink? |
24 // is it a symlink? |
25 if (_dbfs_mode(type) != S_IFLNK) |
25 if (_dbfs_mode(type) != S_IFLNK) |
26 EERROR(err = EINVAL, "wrong type: %s", type); |
26 EERROR(err = EINVAL, "wrong type: %s", type); |
27 |
27 |
28 INFO("[dbfs.readlink %p] -> ino=%lu, type=%s, link=%s", req, (unsigned long int) ino, type, link); |
28 INFO("\t[dbfs.readlink %p] -> ino=%lu, type=%s, link=%s", req, (unsigned long int) ino, type, link); |
29 |
29 |
30 // reply |
30 // reply |
31 if ((err = fuse_reply_readlink(req, link))) |
31 if ((err = fuse_reply_readlink(req, link))) |
32 EERROR(err, "fuse_reply_readlink"); |
32 EERROR(err, "fuse_reply_readlink"); |
33 |
33 |
76 if ((err = fuse_reply_err(req, err))) |
76 if ((err = fuse_reply_err(req, err))) |
77 EWARNING(err, "fuse_reply_err"); |
77 EWARNING(err, "fuse_reply_err"); |
78 |
78 |
79 } |
79 } |
80 |
80 |
|
81 #define SETERR(err_var, err_val, bool_val) ((err_var) = bool_val ? (err_val) : 0) |
|
82 |
|
83 void dbfs_unlink_res (const struct evsql_result_info *res, void *arg) { |
|
84 struct fuse_req *req = arg; |
|
85 int err = 0; |
|
86 |
|
87 // check the results |
|
88 if ((err = dbfs_check_result(res, 1, 0))) |
|
89 goto error; |
|
90 |
|
91 INFO("\t[dbfs.unlink %p] -> OK", req); |
|
92 |
|
93 // reply |
|
94 if ((err = fuse_reply_err(req, 0))) |
|
95 EERROR(err, "fuse_reply_readlink"); |
|
96 |
|
97 error: |
|
98 if (err && (err = fuse_reply_err(req, err))) |
|
99 EWARNING(err, "fuse_reply_err"); |
|
100 |
|
101 // free |
|
102 evsql_result_free(res); |
|
103 } |
|
104 |
|
105 void dbfs_unlink (struct fuse_req *req, fuse_ino_t parent, const char *name) { |
|
106 struct dbfs *ctx = fuse_req_userdata(req); |
|
107 int err; |
|
108 |
|
109 INFO("[dbfs.unlink %p] parent=%lu, name=%s", req, parent, name); |
|
110 |
|
111 const char *sql = |
|
112 "DELETE" |
|
113 " FROM file_tree" |
|
114 " WHERE parent = $1::int4 AND name = $2::varchar"; |
|
115 |
|
116 static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
117 EVSQL_PARAM ( UINT32 ), |
|
118 EVSQL_PARAM ( STRING ), |
|
119 |
|
120 EVSQL_PARAMS_END |
|
121 }; |
|
122 |
|
123 // build params |
|
124 if (SETERR(err, (0 |
|
125 || evsql_param_uint32(¶ms, 0, parent) |
|
126 || evsql_param_string(¶ms, 1, name) |
|
127 ), EIO)) |
|
128 goto error; |
|
129 |
|
130 // query |
|
131 if (SETERR(err, evsql_query_params(ctx->db, NULL, sql, ¶ms, dbfs_unlink_res, req) == NULL, EIO)) |
|
132 goto error; |
|
133 |
|
134 // XXX: handle interrupts |
|
135 |
|
136 // wait |
|
137 return; |
|
138 |
|
139 error: |
|
140 if ((err = fuse_reply_err(req, err))) |
|
141 EWARNING(err, "fuse_reply_err"); |
|
142 } |