You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1278 lines
27 KiB

  1. /*
  2. ISC License
  3. Copyright (c) 2021, Antonio SJ Musumeci <trapexit@spawn.link>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #define _GNU_SOURCE
  16. #include "fuse_kernel.h"
  17. #include <errno.h>
  18. #include <fcntl.h>
  19. #include <inttypes.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. static FILE *g_OUTPUT = NULL;
  23. #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
  24. static
  25. int
  26. debug_set_output_null()
  27. {
  28. g_OUTPUT = stderr;
  29. setvbuf(g_OUTPUT,NULL,_IOLBF,0);
  30. return 0;
  31. }
  32. static
  33. int
  34. debug_set_output_filepath(const char *filepath_)
  35. {
  36. FILE *tmp;
  37. tmp = fopen(filepath_,"a");
  38. if(tmp == NULL)
  39. return -errno;
  40. g_OUTPUT = tmp;
  41. setvbuf(g_OUTPUT,NULL,_IOLBF,0);
  42. return 0;
  43. }
  44. int
  45. debug_set_output(const char *filepath_)
  46. {
  47. if(filepath_ == NULL)
  48. return debug_set_output_null();
  49. return debug_set_output_filepath(filepath_);
  50. }
  51. static
  52. __attribute__((constructor))
  53. void
  54. debug_constructor(void)
  55. {
  56. debug_set_output(NULL);
  57. }
  58. static
  59. const
  60. char*
  61. open_accmode_to_str(const int flags_)
  62. {
  63. switch(flags_ & O_ACCMODE)
  64. {
  65. case O_RDWR:
  66. return "O_RDWR";
  67. case O_RDONLY:
  68. return "O_RDONLY";
  69. case O_WRONLY:
  70. return "O_WRONLY";
  71. }
  72. return "";
  73. }
  74. #define FUSE_WRITE_FLAG_CASE(X) case FUSE_WRITE_##X: return #X
  75. static
  76. const
  77. char*
  78. fuse_write_flag_to_str(const uint32_t offset_)
  79. {
  80. switch(1 << offset_)
  81. {
  82. FUSE_WRITE_FLAG_CASE(CACHE);
  83. FUSE_WRITE_FLAG_CASE(LOCKOWNER);
  84. FUSE_WRITE_FLAG_CASE(KILL_PRIV);
  85. }
  86. return NULL;
  87. }
  88. #undef FUSE_WRITE_FLAG_CASE
  89. #define OPEN_FLAG_CASE(X) case X: return #X
  90. static
  91. const
  92. char*
  93. open_flag_to_str(const uint64_t offset_)
  94. {
  95. switch(1 << offset_)
  96. {
  97. OPEN_FLAG_CASE(O_APPEND);
  98. OPEN_FLAG_CASE(O_ASYNC);
  99. OPEN_FLAG_CASE(O_CLOEXEC);
  100. OPEN_FLAG_CASE(O_CREAT);
  101. OPEN_FLAG_CASE(O_DIRECT);
  102. OPEN_FLAG_CASE(O_DIRECTORY);
  103. #ifdef O_DSYNC
  104. OPEN_FLAG_CASE(O_DSYNC);
  105. #endif
  106. OPEN_FLAG_CASE(O_EXCL);
  107. #ifdef O_LARGEFILE
  108. OPEN_FLAG_CASE(O_LARGEFILE);
  109. #endif
  110. #ifdef O_NOATIME
  111. OPEN_FLAG_CASE(O_NOATIME);
  112. #endif
  113. OPEN_FLAG_CASE(O_NOCTTY);
  114. OPEN_FLAG_CASE(O_NOFOLLOW);
  115. OPEN_FLAG_CASE(O_NONBLOCK);
  116. #ifdef O_PATH
  117. OPEN_FLAG_CASE(O_PATH);
  118. #endif
  119. OPEN_FLAG_CASE(O_SYNC);
  120. #ifdef O_TMPFILE
  121. OPEN_FLAG_CASE(O_TMPFILE);
  122. #endif
  123. OPEN_FLAG_CASE(O_TRUNC);
  124. }
  125. return NULL;
  126. }
  127. #undef OPEN_FLAG_CASE
  128. #define FUSE_INIT_FLAG_CASE(X) case FUSE_##X: return #X
  129. static
  130. const
  131. char*
  132. fuse_flag_to_str(const uint32_t offset_)
  133. {
  134. switch(1 << offset_)
  135. {
  136. FUSE_INIT_FLAG_CASE(ASYNC_READ);
  137. FUSE_INIT_FLAG_CASE(POSIX_LOCKS);
  138. FUSE_INIT_FLAG_CASE(FILE_OPS);
  139. FUSE_INIT_FLAG_CASE(ATOMIC_O_TRUNC);
  140. FUSE_INIT_FLAG_CASE(EXPORT_SUPPORT);
  141. FUSE_INIT_FLAG_CASE(BIG_WRITES);
  142. FUSE_INIT_FLAG_CASE(DONT_MASK);
  143. FUSE_INIT_FLAG_CASE(SPLICE_WRITE);
  144. FUSE_INIT_FLAG_CASE(SPLICE_MOVE);
  145. FUSE_INIT_FLAG_CASE(SPLICE_READ);
  146. FUSE_INIT_FLAG_CASE(FLOCK_LOCKS);
  147. FUSE_INIT_FLAG_CASE(HAS_IOCTL_DIR);
  148. FUSE_INIT_FLAG_CASE(AUTO_INVAL_DATA);
  149. FUSE_INIT_FLAG_CASE(DO_READDIRPLUS);
  150. FUSE_INIT_FLAG_CASE(READDIRPLUS_AUTO);
  151. FUSE_INIT_FLAG_CASE(ASYNC_DIO);
  152. FUSE_INIT_FLAG_CASE(WRITEBACK_CACHE);
  153. FUSE_INIT_FLAG_CASE(NO_OPEN_SUPPORT);
  154. FUSE_INIT_FLAG_CASE(PARALLEL_DIROPS);
  155. FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV);
  156. FUSE_INIT_FLAG_CASE(POSIX_ACL);
  157. FUSE_INIT_FLAG_CASE(ABORT_ERROR);
  158. FUSE_INIT_FLAG_CASE(MAX_PAGES);
  159. FUSE_INIT_FLAG_CASE(CACHE_SYMLINKS);
  160. FUSE_INIT_FLAG_CASE(NO_OPENDIR_SUPPORT);
  161. FUSE_INIT_FLAG_CASE(EXPLICIT_INVAL_DATA);
  162. FUSE_INIT_FLAG_CASE(MAP_ALIGNMENT);
  163. }
  164. return NULL;
  165. }
  166. #undef FUSE_INIT_FLAG_CASE
  167. static
  168. void
  169. debug_open_flags(const uint32_t flags_)
  170. {
  171. fprintf(stderr,"%s,",open_accmode_to_str(flags_));
  172. for(int i = 0; i < (sizeof(flags_) * 8); i++)
  173. {
  174. const char *str;
  175. if(!(flags_ & (1 << i)))
  176. continue;
  177. str = open_flag_to_str(i);
  178. if(str == NULL)
  179. continue;
  180. fprintf(stderr,"%s,",str);
  181. }
  182. }
  183. #define FOPEN_FLAG_CASE(X) case FOPEN_##X: return #X
  184. static
  185. const
  186. char*
  187. fuse_fopen_flag_to_str(const uint32_t offset_)
  188. {
  189. switch(1 << offset_)
  190. {
  191. FOPEN_FLAG_CASE(DIRECT_IO);
  192. FOPEN_FLAG_CASE(KEEP_CACHE);
  193. FOPEN_FLAG_CASE(NONSEEKABLE);
  194. FOPEN_FLAG_CASE(CACHE_DIR);
  195. FOPEN_FLAG_CASE(STREAM);
  196. }
  197. return NULL;
  198. }
  199. #undef FOPEN_FLAG_CASE
  200. void
  201. debug_fuse_open_out(const struct fuse_open_out *arg_)
  202. {
  203. fprintf(stderr,
  204. "fuse_open_out:"
  205. " fh=0x%"PRIx64";"
  206. " open_flags=0x%X (",
  207. arg_->fh,
  208. arg_->open_flags);
  209. for(int i = 0; i < (sizeof(arg_->open_flags) * 8); i++)
  210. {
  211. const char *str;
  212. if(!(arg_->open_flags & (1 << i)))
  213. continue;
  214. str = fuse_fopen_flag_to_str(i);
  215. if(str == NULL)
  216. continue;
  217. fprintf(stderr,"%s,",str);
  218. }
  219. fprintf(stderr,");\n");
  220. }
  221. static
  222. void
  223. debug_fuse_lookup(const void *arg_)
  224. {
  225. const char *name = arg_;
  226. fprintf(g_OUTPUT,
  227. "fuse_lookup:"
  228. " name=%s;"
  229. "\n"
  230. ,
  231. name);
  232. }
  233. static
  234. void
  235. debug_fuse_getattr_in(const void *arg_)
  236. {
  237. const struct fuse_getattr_in *arg = arg_;
  238. fprintf(g_OUTPUT,
  239. "fuse_getattr_in:"
  240. " getattr_flags=0x%08X;"
  241. " fh=0x%"PRIx64";\n",
  242. arg->getattr_flags,
  243. arg->fh);
  244. }
  245. static
  246. void
  247. debug_fuse_setattr_in(const void *arg_)
  248. {
  249. const struct fuse_setattr_in *arg = arg_;
  250. fprintf(g_OUTPUT,
  251. "fuse_setattr_in:"
  252. " valid=%u;"
  253. " fh=0x%"PRIx64";"
  254. " size=%zu;"
  255. " lock_owner=%zu;"
  256. " atime=%zu;"
  257. " atimensec=%u;"
  258. " mtime=%zu;"
  259. " mtimensec=%u;"
  260. " ctime=%zu;"
  261. " ctimensec=%u;"
  262. " mode=%o;"
  263. " uid=%u;"
  264. " gid=%u;"
  265. "\n"
  266. ,
  267. arg->valid,
  268. arg->fh,
  269. arg->size,
  270. arg->lock_owner,
  271. arg->atime,
  272. arg->atimensec,
  273. arg->mtime,
  274. arg->mtimensec,
  275. arg->ctime,
  276. arg->ctimensec,
  277. arg->mode,
  278. arg->uid,
  279. arg->gid);
  280. }
  281. static
  282. void
  283. debug_fuse_access_in(const void *arg_)
  284. {
  285. const struct fuse_access_in *arg = arg_;
  286. fprintf(g_OUTPUT,
  287. "fuse_access_in:"
  288. " mask=0x%08X;"
  289. "\n"
  290. ,
  291. arg->mask);
  292. }
  293. static
  294. void
  295. debug_fuse_mknod_in(const void *arg_)
  296. {
  297. const struct fuse_mknod_in *arg = arg_;
  298. fprintf(g_OUTPUT,
  299. "fuse_mknod_in:"
  300. " mode=%o;"
  301. " rdev=0x%08X;"
  302. " umask=%o;"
  303. "\n"
  304. ,
  305. arg->mode,
  306. arg->rdev,
  307. arg->umask);
  308. }
  309. static
  310. void
  311. debug_fuse_mkdir_in(const void *arg_)
  312. {
  313. const struct fuse_mkdir_in *arg = arg_;
  314. fprintf(g_OUTPUT,
  315. "fuse_mkdir_in:"
  316. " mode=%o;"
  317. " umask=%o;"
  318. " name=%s;"
  319. "\n"
  320. ,
  321. arg->mode,
  322. arg->umask,
  323. PARAM(arg));
  324. }
  325. static
  326. void
  327. debug_fuse_unlink(const void *arg_)
  328. {
  329. const char *name = arg_;
  330. fprintf(g_OUTPUT,
  331. "fuse_unlink:"
  332. " name=%s;"
  333. "\n"
  334. ,
  335. name);
  336. }
  337. static
  338. void
  339. debug_fuse_rmdir(const void *arg_)
  340. {
  341. const char *name = arg_;
  342. fprintf(g_OUTPUT,
  343. "fuse_mkdir:"
  344. " name=%s;"
  345. "\n"
  346. ,
  347. name);
  348. }
  349. static
  350. void
  351. debug_fuse_symlink(const void *arg_)
  352. {
  353. const char *name;
  354. const char *linkname;
  355. name = arg_;
  356. linkname = (name + (strlen(name) + 1));
  357. fprintf(g_OUTPUT,
  358. "fuse_mkdir:"
  359. " linkname=%s;"
  360. " name=%s;"
  361. "\n"
  362. ,
  363. linkname,
  364. name);
  365. }
  366. static
  367. void
  368. debug_fuse_rename_in(const void *arg_)
  369. {
  370. const char *oldname;
  371. const char *newname;
  372. const struct fuse_rename_in *arg = arg_;
  373. oldname = PARAM(arg);
  374. newname = (oldname + strlen(oldname) + 1);
  375. fprintf(g_OUTPUT,
  376. "fuse_rename_in:"
  377. " oldname=%s;"
  378. " newdir=%zu;"
  379. " newname=%s;"
  380. "\n"
  381. ,
  382. oldname,
  383. arg->newdir,
  384. newname);
  385. }
  386. static
  387. void
  388. debug_fuse_link_in(const void *arg_)
  389. {
  390. const char *name;
  391. const struct fuse_link_in *arg = arg_;
  392. name = PARAM(arg);
  393. fprintf(g_OUTPUT,
  394. "fuse_link_in:"
  395. " oldnodeid=%zu;"
  396. " name=%s;"
  397. "\n"
  398. ,
  399. arg->oldnodeid,
  400. name);
  401. }
  402. static
  403. void
  404. debug_fuse_create_in(const void *arg_)
  405. {
  406. const char *name;
  407. const struct fuse_create_in *arg = arg_;
  408. name = PARAM(arg);
  409. fprintf(g_OUTPUT,
  410. "fuse_create_in:"
  411. " mode=%o;"
  412. " umask=%o;"
  413. " name=%s;"
  414. " flags=0x%X (",
  415. arg->mode,
  416. arg->umask,
  417. name,
  418. arg->flags);
  419. debug_open_flags(arg->flags);
  420. fprintf(g_OUTPUT,");\n");
  421. }
  422. static
  423. void
  424. debug_fuse_open_in(const void *arg_)
  425. {
  426. const struct fuse_open_in *arg = arg_;
  427. fprintf(g_OUTPUT,
  428. "fuse_open_in:"
  429. " flags=0x%08X (",
  430. arg->flags);
  431. debug_open_flags(arg->flags);
  432. fprintf(g_OUTPUT,");\n");
  433. }
  434. static
  435. void
  436. debug_fuse_read_in(const void *arg_)
  437. {
  438. const struct fuse_read_in *arg = arg_;
  439. fprintf(g_OUTPUT,
  440. "fuse_read_in:"
  441. " fh=0x%"PRIx64";"
  442. " offset=%zu;"
  443. " size=%u;"
  444. " read_flags=%X;"
  445. " lock_owner=0x%"PRIx64";"
  446. " flags=0x%X ("
  447. ,
  448. arg->fh,
  449. arg->offset,
  450. arg->size,
  451. arg->read_flags,
  452. arg->lock_owner,
  453. arg->flags);
  454. debug_open_flags(arg->flags);
  455. fprintf(g_OUTPUT,");\n");
  456. }
  457. static
  458. void
  459. debug_fuse_write_in(const void *arg_)
  460. {
  461. const struct fuse_write_in *arg = arg_;
  462. fprintf(g_OUTPUT,
  463. "fuse_write_in:"
  464. " fh=0x%"PRIx64";"
  465. " offset=%zu;"
  466. " size=%u;"
  467. " lock_owner=0x%"PRIx64";"
  468. " flags=0x%X ("
  469. ,
  470. arg->fh,
  471. arg->offset,
  472. arg->size,
  473. arg->lock_owner,
  474. arg->flags);
  475. debug_open_flags(arg->flags);
  476. fprintf(g_OUTPUT,
  477. "); write_flags=0x%X (",
  478. arg->write_flags);
  479. for(int i = 0; i < (sizeof(arg->write_flags) * 8); i++)
  480. {
  481. const char *str;
  482. if(!(arg->write_flags & (1 << i)))
  483. continue;
  484. str = fuse_write_flag_to_str(i);
  485. if(str == NULL)
  486. continue;
  487. fprintf(g_OUTPUT,"%s,",str);
  488. }
  489. fprintf(g_OUTPUT,");\n");
  490. }
  491. static
  492. void
  493. debug_fuse_flush_in(const void *arg_)
  494. {
  495. const struct fuse_flush_in *arg = arg_;
  496. fprintf(g_OUTPUT,
  497. "fuse_flush_in:"
  498. " fh=0x%"PRIx64";"
  499. " lock_owner=0x%"PRIx64";"
  500. "\n"
  501. ,
  502. arg->fh,
  503. arg->lock_owner);
  504. }
  505. static
  506. void
  507. debug_fuse_release_in(const void *arg_)
  508. {
  509. const struct fuse_release_in *arg = arg_;
  510. fprintf(g_OUTPUT,
  511. "fuse_release_in:"
  512. " fh=0x%"PRIx64";"
  513. " release_flags=0x%X;"
  514. " lock_owner=0x%"PRIx64";"
  515. " flags=0x%X ("
  516. ,
  517. arg->fh,
  518. arg->release_flags,
  519. arg->lock_owner,
  520. arg->flags);
  521. debug_open_flags(arg->flags);
  522. fprintf(g_OUTPUT,");\n");
  523. }
  524. static
  525. void
  526. debug_fuse_fsync_in(const void *arg_)
  527. {
  528. const struct fuse_fsync_in *arg = arg_;
  529. fprintf(g_OUTPUT,
  530. "fuse_fsync_in:"
  531. " fh=0x%"PRIx64";"
  532. " fsync_flags=0x%X;"
  533. "\n"
  534. ,
  535. arg->fh,
  536. arg->fsync_flags);
  537. }
  538. static
  539. void
  540. debug_fuse_setxattr_in(const void *arg_)
  541. {
  542. const char *name;
  543. const char *value;
  544. const struct fuse_setxattr_in *arg = arg_;
  545. name = PARAM(arg);
  546. value = (name + strlen(name) + 1);
  547. fprintf(g_OUTPUT,
  548. "fuse_setxattr_in:"
  549. " size=%u;"
  550. " flags=0x%X;"
  551. " name=%s;"
  552. " value=%s;"
  553. "\n"
  554. ,
  555. arg->size,
  556. arg->flags,
  557. name,
  558. value);
  559. }
  560. static
  561. void
  562. debug_fuse_getxattr_in(const void *arg_)
  563. {
  564. const char *name;
  565. const struct fuse_getxattr_in *arg = arg_;
  566. name = PARAM(arg);
  567. fprintf(g_OUTPUT,
  568. "fuse_getxattr_in:"
  569. " size=%u;"
  570. " name=%s;"
  571. "\n"
  572. ,
  573. arg->size,
  574. name);
  575. }
  576. static
  577. void
  578. debug_fuse_listxattr(const void *arg_)
  579. {
  580. const struct fuse_getxattr_in *arg = arg_;
  581. fprintf(g_OUTPUT,
  582. "fuse_listxattr:"
  583. " size=%u;"
  584. "\n"
  585. ,
  586. arg->size);
  587. }
  588. static
  589. void
  590. debug_fuse_removexattr(const void *arg_)
  591. {
  592. const char *name = arg_;
  593. fprintf(g_OUTPUT,
  594. "fuse_removexattr:"
  595. " name=%s;"
  596. "\n"
  597. ,
  598. name);
  599. }
  600. static
  601. void
  602. debug_fuse_fallocate_in(const void *arg_)
  603. {
  604. const struct fuse_fallocate_in *arg = arg_;
  605. fprintf(g_OUTPUT,
  606. "fuse_fallocate_in:"
  607. " fh=0x%"PRIx64";"
  608. " offset=%zu;"
  609. " length=%zu;"
  610. " mode=%o;"
  611. "\n"
  612. ,
  613. arg->fh,
  614. arg->offset,
  615. arg->length,
  616. arg->mode);
  617. }
  618. void
  619. debug_fuse_init_in(const struct fuse_init_in *arg_)
  620. {
  621. fprintf(g_OUTPUT,
  622. "FUSE_INIT_IN: "
  623. " major=%u;"
  624. " minor=%u;"
  625. " max_readahead=%u;"
  626. " flags=0x%08X (",
  627. arg_->major,
  628. arg_->minor,
  629. arg_->max_readahead,
  630. arg_->flags);
  631. for(uint64_t i = 0; i < (sizeof(arg_->flags)*8); i++)
  632. {
  633. const char *str;
  634. if(!(arg_->flags & (1ULL << i)))
  635. continue;
  636. str = fuse_flag_to_str(i);
  637. if(str == NULL)
  638. continue;
  639. fprintf(g_OUTPUT,"%s,",str);
  640. }
  641. fprintf(g_OUTPUT,")\n");
  642. }
  643. void
  644. debug_fuse_init_out(const uint64_t unique_,
  645. const struct fuse_init_out *arg_,
  646. const uint64_t argsize_)
  647. {
  648. const struct fuse_init_out *arg = arg_;
  649. fprintf(g_OUTPUT,
  650. /* "unique=0x%016"PRIx64";" */
  651. /* " opcode=RESPONSE;" */
  652. /* " error=0 (Success);" */
  653. /* " len=%"PRIu64"; || " */
  654. "FUSE_INIT_OUT:"
  655. " major=%u;"
  656. " minor=%u;"
  657. " max_readahead=%u;"
  658. " flags=0x%08X ("
  659. ,
  660. /* unique_, */
  661. /* sizeof(struct fuse_out_header) + argsize_, */
  662. arg->major,
  663. arg->minor,
  664. arg->max_readahead,
  665. arg->flags);
  666. for(uint64_t i = 0; i < (sizeof(arg->flags)*8); i++)
  667. {
  668. const char *str;
  669. if(!(arg->flags & (1ULL << i)))
  670. continue;
  671. str = fuse_flag_to_str(i);
  672. if(str == NULL)
  673. continue;
  674. fprintf(g_OUTPUT,"%s,",str);
  675. }
  676. fprintf(g_OUTPUT,
  677. "); max_background=%u;"
  678. " congestion_threshold=%u;"
  679. " max_write=%u;"
  680. " time_gran=%u;"
  681. " max_pages=%u;"
  682. " map_alignment=%u;"
  683. "\n",
  684. arg->max_background,
  685. arg->congestion_threshold,
  686. arg->max_write,
  687. arg->time_gran,
  688. arg->max_pages,
  689. arg->map_alignment);
  690. }
  691. static
  692. void
  693. debug_fuse_attr(const struct fuse_attr *attr_)
  694. {
  695. fprintf(g_OUTPUT,
  696. "attr:"
  697. " ino=0x%016"PRIx64";"
  698. " size=%"PRIu64";"
  699. " blocks=%"PRIu64";"
  700. " atime=%"PRIu64";"
  701. " atimensec=%u;"
  702. " mtime=%"PRIu64";"
  703. " mtimensec=%u;"
  704. " ctime=%"PRIu64";"
  705. " ctimesec=%u;"
  706. " mode=%o;"
  707. " nlink=%u;"
  708. " uid=%u;"
  709. " gid=%u;"
  710. " rdev=%u;"
  711. " blksize=%u;"
  712. ,
  713. attr_->ino,
  714. attr_->size,
  715. attr_->blocks,
  716. attr_->atime,
  717. attr_->atimensec,
  718. attr_->mtime,
  719. attr_->mtimensec,
  720. attr_->ctime,
  721. attr_->ctimensec,
  722. attr_->mode,
  723. attr_->nlink,
  724. attr_->uid,
  725. attr_->gid,
  726. attr_->rdev,
  727. attr_->blksize);
  728. }
  729. static
  730. void
  731. debug_fuse_entry(const struct fuse_entry_out *entry_)
  732. {
  733. fprintf(g_OUTPUT,
  734. " fuse_entry_out:"
  735. " nodeid=0x%016"PRIx64";"
  736. " generation=0x%016"PRIx64";"
  737. " entry_valid=%"PRIu64";"
  738. " entry_valid_nsec=%u;"
  739. " attr_valid=%"PRIu64";"
  740. " attr_valid_nsec=%u;"
  741. " ",
  742. entry_->nodeid,
  743. entry_->generation,
  744. entry_->entry_valid,
  745. entry_->entry_valid_nsec,
  746. entry_->attr_valid,
  747. entry_->attr_valid_nsec);
  748. debug_fuse_attr(&entry_->attr);
  749. }
  750. void
  751. debug_fuse_entry_out(const uint64_t unique_,
  752. const struct fuse_entry_out *arg_,
  753. const uint64_t argsize_)
  754. {
  755. fprintf(g_OUTPUT,
  756. "unique=0x%016"PRIx64";"
  757. " opcode=RESPONSE;"
  758. " error=0 (Success);"
  759. " len=%"PRIu64"; || "
  760. ,
  761. unique_,
  762. sizeof(struct fuse_out_header) + argsize_);
  763. debug_fuse_entry(arg_);
  764. }
  765. void
  766. debug_fuse_attr_out(const uint64_t unique_,
  767. const struct fuse_attr_out *arg_,
  768. const uint64_t argsize_)
  769. {
  770. fprintf(g_OUTPUT,
  771. "unique=0x%016"PRIx64";"
  772. " opcode=RESPONSE;"
  773. " error=0 (Success);"
  774. " len=%"PRIu64"; || "
  775. "fuse_attr_out:"
  776. " attr_valid=%zu;"
  777. " attr_valid_nsec=%u;"
  778. " ino=%zu;"
  779. " size=%zu;"
  780. " blocks=%zu;"
  781. " atime=%zu;"
  782. " atimensec=%u;"
  783. " mtime=%zu;"
  784. " mtimensec=%u;"
  785. " ctime=%zu;"
  786. " ctimensec=%u;"
  787. " mode=%o;"
  788. " nlink=%u;"
  789. " uid=%u;"
  790. " gid=%u;"
  791. " rdev=%u;"
  792. " blksize=%u;"
  793. "\n",
  794. unique_,
  795. sizeof(struct fuse_out_header) + argsize_,
  796. arg_->attr_valid,
  797. arg_->attr_valid_nsec,
  798. arg_->attr.ino,
  799. arg_->attr.size,
  800. arg_->attr.blocks,
  801. arg_->attr.atime,
  802. arg_->attr.atimensec,
  803. arg_->attr.mtime,
  804. arg_->attr.mtimensec,
  805. arg_->attr.ctime,
  806. arg_->attr.ctimensec,
  807. arg_->attr.mode,
  808. arg_->attr.nlink,
  809. arg_->attr.uid,
  810. arg_->attr.gid,
  811. arg_->attr.rdev,
  812. arg_->attr.blksize);
  813. }
  814. static
  815. void
  816. debug_fuse_interrupt_in(const void *arg_)
  817. {
  818. const struct fuse_interrupt_in *arg = arg_;
  819. fprintf(g_OUTPUT,
  820. "fuse_interrupt_in:"
  821. " unique=0x%016"PRIx64";"
  822. "\n"
  823. ,
  824. arg->unique);
  825. }
  826. static
  827. const
  828. char*
  829. opcode_name(enum fuse_opcode op_)
  830. {
  831. static const char *names[] =
  832. {
  833. [FUSE_LOOKUP] = "LOOKUP",
  834. [FUSE_FORGET] = "FORGET",
  835. [FUSE_GETATTR] = "GETATTR",
  836. [FUSE_SETATTR] = "SETATTR",
  837. [FUSE_READLINK] = "READLINK",
  838. [FUSE_SYMLINK] = "SYMLINK",
  839. [FUSE_MKNOD] = "MKNOD",
  840. [FUSE_MKDIR] = "MKDIR",
  841. [FUSE_UNLINK] = "UNLINK",
  842. [FUSE_RMDIR] = "RMDIR",
  843. [FUSE_RENAME] = "RENAME",
  844. [FUSE_LINK] = "LINK",
  845. [FUSE_OPEN] = "OPEN",
  846. [FUSE_READ] = "READ",
  847. [FUSE_WRITE] = "WRITE",
  848. [FUSE_STATFS] = "STATFS",
  849. [FUSE_RELEASE] = "RELEASE",
  850. [FUSE_FSYNC] = "FSYNC",
  851. [FUSE_SETXATTR] = "SETXATTR",
  852. [FUSE_GETXATTR] = "GETXATTR",
  853. [FUSE_LISTXATTR] = "LISTXATTR",
  854. [FUSE_REMOVEXATTR] = "REMOVEXATTR",
  855. [FUSE_FLUSH] = "FLUSH",
  856. [FUSE_INIT] = "INIT",
  857. [FUSE_OPENDIR] = "OPENDIR",
  858. [FUSE_READDIR] = "READDIR",
  859. [FUSE_RELEASEDIR] = "RELEASEDIR",
  860. [FUSE_FSYNCDIR] = "FSYNCDIR",
  861. [FUSE_GETLK] = "GETLK",
  862. [FUSE_SETLK] = "SETLK",
  863. [FUSE_SETLKW] = "SETLKW",
  864. [FUSE_ACCESS] = "ACCESS",
  865. [FUSE_CREATE] = "CREATE",
  866. [FUSE_INTERRUPT] = "INTERRUPT",
  867. [FUSE_BMAP] = "BMAP",
  868. [FUSE_DESTROY] = "DESTROY",
  869. [FUSE_IOCTL] = "IOCTL",
  870. [FUSE_POLL] = "POLL",
  871. [FUSE_NOTIFY_REPLY] = "NOTIFY_REPLY",
  872. [FUSE_BATCH_FORGET] = "BATCH_FORGET",
  873. [FUSE_FALLOCATE] = "FALLOCATE",
  874. [FUSE_READDIRPLUS] = "READDIRPLUS",
  875. [FUSE_RENAME2] = "RENAME2",
  876. [FUSE_LSEEK] = "LSEEK",
  877. [FUSE_COPY_FILE_RANGE] = "COPY_FILE_RANGE",
  878. [FUSE_SETUPMAPPING] = "SETUPMAPPING",
  879. [FUSE_REMOVEMAPPING] = "REMOVEMAPPING"
  880. };
  881. if(op_ >= (sizeof(names) / sizeof(names[0])))
  882. return "::UNKNOWN::";
  883. return names[op_];
  884. }
  885. void
  886. debug_fuse_in_header(const struct fuse_in_header *hdr_)
  887. {
  888. const void *arg = &hdr_[1];
  889. fprintf(stderr,
  890. "unique=0x%016"PRIx64";"
  891. " opcode=%s (%u);"
  892. " nodeid=%zu;"
  893. " uid=%u;"
  894. " gid=%u;"
  895. " pid=%u; || ",
  896. hdr_->unique,
  897. opcode_name(hdr_->opcode),
  898. hdr_->opcode,
  899. hdr_->nodeid,
  900. hdr_->uid,
  901. hdr_->gid,
  902. hdr_->pid);
  903. switch(hdr_->opcode)
  904. {
  905. case FUSE_LOOKUP:
  906. debug_fuse_lookup(arg);
  907. break;
  908. case FUSE_INIT:
  909. debug_fuse_init_in(arg);
  910. break;
  911. case FUSE_GETATTR:
  912. debug_fuse_getattr_in(arg);
  913. break;
  914. case FUSE_SETATTR:
  915. debug_fuse_setattr_in(arg);
  916. break;
  917. case FUSE_ACCESS:
  918. debug_fuse_access_in(arg);
  919. break;
  920. case FUSE_MKNOD:
  921. debug_fuse_mknod_in(arg);
  922. break;
  923. case FUSE_MKDIR:
  924. debug_fuse_mkdir_in(arg);
  925. break;
  926. case FUSE_UNLINK:
  927. debug_fuse_unlink(arg);
  928. break;
  929. case FUSE_RMDIR:
  930. debug_fuse_rmdir(arg);
  931. break;
  932. case FUSE_SYMLINK:
  933. debug_fuse_symlink(arg);
  934. break;
  935. case FUSE_RENAME:
  936. debug_fuse_rename_in(arg);
  937. break;
  938. case FUSE_LINK:
  939. debug_fuse_link_in(arg);
  940. break;
  941. case FUSE_CREATE:
  942. debug_fuse_create_in(arg);
  943. break;
  944. case FUSE_OPEN:
  945. debug_fuse_open_in(arg);
  946. break;
  947. case FUSE_OPENDIR:
  948. debug_fuse_open_in(arg);
  949. break;
  950. case FUSE_READ:
  951. debug_fuse_read_in(arg);
  952. break;
  953. case FUSE_READDIR:
  954. debug_fuse_read_in(arg);
  955. break;
  956. case FUSE_READDIRPLUS:
  957. debug_fuse_read_in(arg);
  958. break;
  959. case FUSE_WRITE:
  960. debug_fuse_write_in(arg);
  961. break;
  962. case FUSE_RELEASE:
  963. debug_fuse_release_in(arg);
  964. break;
  965. case FUSE_RELEASEDIR:
  966. debug_fuse_release_in(arg);
  967. break;
  968. case FUSE_FSYNCDIR:
  969. debug_fuse_fsync_in(arg);
  970. break;
  971. case FUSE_GETXATTR:
  972. debug_fuse_getxattr_in(arg);
  973. break;
  974. case FUSE_LISTXATTR:
  975. debug_fuse_listxattr(arg);
  976. break;
  977. case FUSE_SETXATTR:
  978. debug_fuse_setxattr_in(arg);
  979. break;
  980. case FUSE_REMOVEXATTR:
  981. debug_fuse_removexattr(arg);
  982. break;
  983. case FUSE_FALLOCATE:
  984. debug_fuse_fallocate_in(arg);
  985. break;
  986. case FUSE_FLUSH:
  987. debug_fuse_flush_in(arg);
  988. break;
  989. case FUSE_INTERRUPT:
  990. debug_fuse_interrupt_in(arg);
  991. break;
  992. default:
  993. fprintf(g_OUTPUT,"FIXME\n");
  994. break;
  995. }
  996. }
  997. void
  998. debug_fuse_out_header(const struct fuse_out_header *hdr_)
  999. {
  1000. fprintf(g_OUTPUT,
  1001. "unique=0x%016"PRIx64";"
  1002. " opcode=RESPONSE;"
  1003. " error=%d (%s);"
  1004. " len=%"PRIu64";"
  1005. ,
  1006. hdr_->unique,
  1007. hdr_->error,
  1008. strerror(-hdr_->error),
  1009. sizeof(struct fuse_out_header));
  1010. }
  1011. void
  1012. debug_fuse_entry_open_out(const uint64_t unique_,
  1013. const struct fuse_entry_out *entry_,
  1014. const struct fuse_open_out *open_)
  1015. {
  1016. fprintf(g_OUTPUT,
  1017. "unique=0x%016"PRIx64";"
  1018. " opcode=RESPONSE;"
  1019. " error=0 (Success);"
  1020. " len=%"PRIu64"; || "
  1021. ,
  1022. unique_,
  1023. sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out));
  1024. debug_fuse_entry(entry_);
  1025. }
  1026. void
  1027. debug_fuse_readlink(const uint64_t unique_,
  1028. const char *linkname_)
  1029. {
  1030. fprintf(g_OUTPUT,
  1031. "unique=0x%016"PRIx64";"
  1032. " opcode=RESPONSE;"
  1033. " error=0 (Success);"
  1034. " len=%"PRIu64"; || "
  1035. "readlink: linkname=%s"
  1036. "\n"
  1037. ,
  1038. unique_,
  1039. (sizeof(struct fuse_out_header) + strlen(linkname_)),
  1040. linkname_);
  1041. }
  1042. void
  1043. debug_fuse_write_out(const uint64_t unique_,
  1044. const struct fuse_write_out *arg_)
  1045. {
  1046. fprintf(g_OUTPUT,
  1047. "unique=0x%016"PRIx64";"
  1048. " opcode=RESPONSE;"
  1049. " error=0 (Success);"
  1050. " len=%"PRIu64"; || "
  1051. " fuse_write_out:"
  1052. " size=%u"
  1053. "\n"
  1054. ,
  1055. unique_,
  1056. sizeof(struct fuse_write_out),
  1057. arg_->size);
  1058. }
  1059. void
  1060. debug_fuse_statfs_out(const uint64_t unique_,
  1061. const struct fuse_statfs_out *arg_)
  1062. {
  1063. fprintf(g_OUTPUT,
  1064. "unique=0x%016"PRIx64";"
  1065. " opcode=RESPONSE;"
  1066. " error=0 (Success);"
  1067. " len=%"PRIu64"; || "
  1068. " fuse_statfs_out:"
  1069. " blocks=%"PRIu64";"
  1070. " bfree=%"PRIu64";"
  1071. " bavail=%"PRIu64";"
  1072. " files=%"PRIu64";"
  1073. " ffree=%"PRIu64";"
  1074. " bsize=%u;"
  1075. " namelen=%u;"
  1076. " frsize=%u;"
  1077. "\n"
  1078. ,
  1079. unique_,
  1080. sizeof(struct fuse_statfs_out),
  1081. arg_->st.blocks,
  1082. arg_->st.bfree,
  1083. arg_->st.bavail,
  1084. arg_->st.files,
  1085. arg_->st.ffree,
  1086. arg_->st.bsize,
  1087. arg_->st.namelen,
  1088. arg_->st.frsize);
  1089. }
  1090. void
  1091. debug_fuse_getxattr_out(const uint64_t unique_,
  1092. const struct fuse_getxattr_out *arg_)
  1093. {
  1094. fprintf(g_OUTPUT,
  1095. "unique=0x%016"PRIx64";"
  1096. " opcode=RESPONSE;"
  1097. " error=0 (Success);"
  1098. " len=%"PRIu64"; || "
  1099. " fuse_getxattr_out:"
  1100. " size=%u;"
  1101. "\n"
  1102. ,
  1103. unique_,
  1104. sizeof(struct fuse_out_header) + sizeof(struct fuse_getxattr_out),
  1105. arg_->size);
  1106. }
  1107. void
  1108. debug_fuse_lk_out(const uint64_t unique_,
  1109. const struct fuse_lk_out *arg_)
  1110. {
  1111. fprintf(g_OUTPUT,
  1112. "unique=0x%016"PRIx64";"
  1113. " opcode=RESPONSE;"
  1114. " error=0 (Success);"
  1115. " len=%"PRIu64"; || "
  1116. " fuse_file_lock:"
  1117. " start=%"PRIu64";"
  1118. " end=%"PRIu64";"
  1119. " type=%u;"
  1120. " pid=%u;"
  1121. "\n"
  1122. ,
  1123. unique_,
  1124. sizeof(struct fuse_out_header) + sizeof(struct fuse_lk_out),
  1125. arg_->lk.start,
  1126. arg_->lk.end,
  1127. arg_->lk.type,
  1128. arg_->lk.pid);
  1129. }
  1130. void
  1131. debug_fuse_bmap_out(const uint64_t unique_,
  1132. const struct fuse_bmap_out *arg_)
  1133. {
  1134. fprintf(g_OUTPUT,
  1135. "unique=0x%016"PRIx64";"
  1136. " opcode=RESPONSE;"
  1137. " error=0 (Success);"
  1138. " len=%"PRIu64"; || "
  1139. " fuse_bmap_out:"
  1140. " block=%"PRIu64";"
  1141. "\n"
  1142. ,
  1143. unique_,
  1144. sizeof(struct fuse_out_header) + sizeof(struct fuse_bmap_out),
  1145. arg_->block);
  1146. }