219 error: |
219 error: |
220 if ((err = fuse_reply_err(req, err ? err : EIO))) |
220 if ((err = fuse_reply_err(req, err ? err : EIO))) |
221 EWARNING(err, "failed to send error reply"); |
221 EWARNING(err, "failed to send error reply"); |
222 } |
222 } |
223 |
223 |
|
224 void hello_open (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { |
|
225 int err = 0; |
|
226 |
|
227 INFO("[hello.open] ino=%lu, fi=%p, fi->flags=%08X", ino, fi, fi->flags); |
|
228 |
|
229 if (ino != 2) { |
|
230 // must open our only file, not the dir |
|
231 fuse_reply_err(req, ino == 1 ? EISDIR : ENOENT); |
|
232 return; |
|
233 |
|
234 } else if ((fi->flags & 0x03) != O_RDONLY) { |
|
235 // "permission denied" |
|
236 fuse_reply_err(req, EACCES); |
|
237 return; |
|
238 } |
|
239 |
|
240 // XXX: update fi stuff? |
|
241 |
|
242 // open it! |
|
243 if ((err = fuse_reply_open(req, fi))) |
|
244 EERROR(err, "fuse_reply_open"); |
|
245 |
|
246 // success |
|
247 return; |
|
248 |
|
249 error: |
|
250 if ((err = fuse_reply_err(req, err ? err : EIO))) |
|
251 EWARNING(err, "failed to send error reply"); |
|
252 } |
|
253 |
|
254 void hello_read (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi) { |
|
255 int err = 0; |
|
256 |
|
257 // fi is unused |
|
258 (void) fi; |
|
259 |
|
260 INFO("[hello.read] ino=%lu, size=%zu, off=%zu, fi=%p", ino, size, off, fi); |
|
261 |
|
262 if (ino != 2) { |
|
263 // EEK! |
|
264 FATAL("wrong inode"); |
|
265 } |
|
266 |
|
267 // validate off |
|
268 if (off >= strlen(file_data) && (err = EIO)) |
|
269 ERROR("offset is out-of-bounds (%zu >= %zu)", off, strlen(file_data)); |
|
270 |
|
271 // reply |
|
272 if ((err = fuse_reply_buf(req, file_data + off, MIN(strlen(file_data) - off, size)))) |
|
273 PERROR("fuse_reply_buf"); |
|
274 |
|
275 // success |
|
276 return; |
|
277 |
|
278 error: |
|
279 if ((err = fuse_reply_err(req, err ? err : EIO))) |
|
280 EWARNING(err, "failed to send error reply"); |
|
281 } |
|
282 |
224 struct fuse_lowlevel_ops hello_llops = { |
283 struct fuse_lowlevel_ops hello_llops = { |
225 .init = &hello_init, |
284 .init = &hello_init, |
226 .destroy = &hello_destroy, |
285 .destroy = &hello_destroy, |
227 |
286 |
228 .lookup = &hello_lookup, |
287 .lookup = &hello_lookup, |
229 .getattr = &hello_getattr, |
288 .getattr = &hello_getattr, |
|
289 |
|
290 .open = &hello_open, |
|
291 |
|
292 .read = &hello_read, |
230 |
293 |
231 .readdir = &hello_readdir, |
294 .readdir = &hello_readdir, |
232 }; |
295 }; |
233 |
296 |
234 |
297 |