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.

1297 lines
28 KiB

9 months ago
9 months ago
  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 uint64_t offset_)
  133. {
  134. switch(1ULL << 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. FUSE_INIT_FLAG_CASE(SUBMOUNTS);
  164. FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV_V2);
  165. FUSE_INIT_FLAG_CASE(SETXATTR_EXT);
  166. FUSE_INIT_FLAG_CASE(INIT_EXT);
  167. FUSE_INIT_FLAG_CASE(INIT_RESERVED);
  168. FUSE_INIT_FLAG_CASE(SECURITY_CTX);
  169. FUSE_INIT_FLAG_CASE(HAS_INODE_DAX);
  170. FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
  171. FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
  172. FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
  173. FUSE_INIT_FLAG_CASE(PASSTHROUGH);
  174. }
  175. return NULL;
  176. }
  177. #undef FUSE_INIT_FLAG_CASE
  178. static
  179. void
  180. debug_open_flags(const uint32_t flags_)
  181. {
  182. fprintf(stderr,"%s, ",open_accmode_to_str(flags_));
  183. for(int i = 0; i < (sizeof(flags_) * 8); i++)
  184. {
  185. const char *str;
  186. if(!(flags_ & (1 << i)))
  187. continue;
  188. str = open_flag_to_str(i);
  189. if(str == NULL)
  190. continue;
  191. fprintf(stderr,"%s, ",str);
  192. }
  193. }
  194. #define FOPEN_FLAG_CASE(X) case FOPEN_##X: return #X
  195. static
  196. const
  197. char*
  198. fuse_fopen_flag_to_str(const uint32_t offset_)
  199. {
  200. switch(1 << offset_)
  201. {
  202. FOPEN_FLAG_CASE(DIRECT_IO);
  203. FOPEN_FLAG_CASE(KEEP_CACHE);
  204. FOPEN_FLAG_CASE(NONSEEKABLE);
  205. FOPEN_FLAG_CASE(CACHE_DIR);
  206. FOPEN_FLAG_CASE(STREAM);
  207. }
  208. return NULL;
  209. }
  210. #undef FOPEN_FLAG_CASE
  211. void
  212. debug_fuse_open_out(const struct fuse_open_out *arg_)
  213. {
  214. fprintf(stderr,
  215. "fuse_open_out:"
  216. " fh=0x%"PRIx64";"
  217. " open_flags=0x%X (",
  218. arg_->fh,
  219. arg_->open_flags);
  220. for(int i = 0; i < (sizeof(arg_->open_flags) * 8); i++)
  221. {
  222. const char *str;
  223. if(!(arg_->open_flags & (1 << i)))
  224. continue;
  225. str = fuse_fopen_flag_to_str(i);
  226. if(str == NULL)
  227. continue;
  228. fprintf(stderr,"%s,",str);
  229. }
  230. fprintf(stderr,");\n");
  231. }
  232. static
  233. void
  234. debug_fuse_lookup(const void *arg_)
  235. {
  236. const char *name = arg_;
  237. fprintf(g_OUTPUT,
  238. "fuse_lookup:"
  239. " name=%s;"
  240. "\n"
  241. ,
  242. name);
  243. }
  244. static
  245. void
  246. debug_fuse_getattr_in(const void *arg_)
  247. {
  248. const struct fuse_getattr_in *arg = arg_;
  249. fprintf(g_OUTPUT,
  250. "fuse_getattr_in:"
  251. " getattr_flags=0x%08X;"
  252. " fh=0x%"PRIx64";\n",
  253. arg->getattr_flags,
  254. arg->fh);
  255. }
  256. static
  257. void
  258. debug_fuse_setattr_in(const void *arg_)
  259. {
  260. const struct fuse_setattr_in *arg = arg_;
  261. fprintf(g_OUTPUT,
  262. "fuse_setattr_in:"
  263. " valid=%u;"
  264. " fh=0x%"PRIx64";"
  265. " size=%zu;"
  266. " lock_owner=%zu;"
  267. " atime=%zu;"
  268. " atimensec=%u;"
  269. " mtime=%zu;"
  270. " mtimensec=%u;"
  271. " ctime=%zu;"
  272. " ctimensec=%u;"
  273. " mode=%o;"
  274. " uid=%u;"
  275. " gid=%u;"
  276. "\n"
  277. ,
  278. arg->valid,
  279. arg->fh,
  280. arg->size,
  281. arg->lock_owner,
  282. arg->atime,
  283. arg->atimensec,
  284. arg->mtime,
  285. arg->mtimensec,
  286. arg->ctime,
  287. arg->ctimensec,
  288. arg->mode,
  289. arg->uid,
  290. arg->gid);
  291. }
  292. static
  293. void
  294. debug_fuse_access_in(const void *arg_)
  295. {
  296. const struct fuse_access_in *arg = arg_;
  297. fprintf(g_OUTPUT,
  298. "fuse_access_in:"
  299. " mask=0x%08X;"
  300. "\n"
  301. ,
  302. arg->mask);
  303. }
  304. static
  305. void
  306. debug_fuse_mknod_in(const void *arg_)
  307. {
  308. const struct fuse_mknod_in *arg = arg_;
  309. fprintf(g_OUTPUT,
  310. "fuse_mknod_in:"
  311. " mode=%o;"
  312. " rdev=0x%08X;"
  313. " umask=%o;"
  314. "\n"
  315. ,
  316. arg->mode,
  317. arg->rdev,
  318. arg->umask);
  319. }
  320. static
  321. void
  322. debug_fuse_mkdir_in(const void *arg_)
  323. {
  324. const struct fuse_mkdir_in *arg = arg_;
  325. fprintf(g_OUTPUT,
  326. "fuse_mkdir_in:"
  327. " mode=%o;"
  328. " umask=%o;"
  329. " name=%s;"
  330. "\n"
  331. ,
  332. arg->mode,
  333. arg->umask,
  334. PARAM(arg));
  335. }
  336. static
  337. void
  338. debug_fuse_unlink(const void *arg_)
  339. {
  340. const char *name = arg_;
  341. fprintf(g_OUTPUT,
  342. "fuse_unlink:"
  343. " name=%s;"
  344. "\n"
  345. ,
  346. name);
  347. }
  348. static
  349. void
  350. debug_fuse_rmdir(const void *arg_)
  351. {
  352. const char *name = arg_;
  353. fprintf(g_OUTPUT,
  354. "fuse_mkdir:"
  355. " name=%s;"
  356. "\n"
  357. ,
  358. name);
  359. }
  360. static
  361. void
  362. debug_fuse_symlink(const void *arg_)
  363. {
  364. const char *name;
  365. const char *linkname;
  366. name = arg_;
  367. linkname = (name + (strlen(name) + 1));
  368. fprintf(g_OUTPUT,
  369. "fuse_mkdir:"
  370. " linkname=%s;"
  371. " name=%s;"
  372. "\n"
  373. ,
  374. linkname,
  375. name);
  376. }
  377. static
  378. void
  379. debug_fuse_rename_in(const void *arg_)
  380. {
  381. const char *oldname;
  382. const char *newname;
  383. const struct fuse_rename_in *arg = arg_;
  384. oldname = PARAM(arg);
  385. newname = (oldname + strlen(oldname) + 1);
  386. fprintf(g_OUTPUT,
  387. "fuse_rename_in:"
  388. " oldname=%s;"
  389. " newdir=%zu;"
  390. " newname=%s;"
  391. "\n"
  392. ,
  393. oldname,
  394. arg->newdir,
  395. newname);
  396. }
  397. static
  398. void
  399. debug_fuse_link_in(const void *arg_)
  400. {
  401. const char *name;
  402. const struct fuse_link_in *arg = arg_;
  403. name = PARAM(arg);
  404. fprintf(g_OUTPUT,
  405. "fuse_link_in:"
  406. " oldnodeid=%zu;"
  407. " name=%s;"
  408. "\n"
  409. ,
  410. arg->oldnodeid,
  411. name);
  412. }
  413. static
  414. void
  415. debug_fuse_create_in(const void *arg_)
  416. {
  417. const char *name;
  418. const struct fuse_create_in *arg = arg_;
  419. name = PARAM(arg);
  420. fprintf(g_OUTPUT,
  421. "fuse_create_in:"
  422. " mode=%o;"
  423. " umask=%o;"
  424. " name=%s;"
  425. " flags=0x%X (",
  426. arg->mode,
  427. arg->umask,
  428. name,
  429. arg->flags);
  430. debug_open_flags(arg->flags);
  431. fprintf(g_OUTPUT,");\n");
  432. }
  433. static
  434. void
  435. debug_fuse_open_in(const void *arg_)
  436. {
  437. const struct fuse_open_in *arg = arg_;
  438. fprintf(g_OUTPUT,
  439. "fuse_open_in:"
  440. " flags=0x%08X (",
  441. arg->flags);
  442. debug_open_flags(arg->flags);
  443. fprintf(g_OUTPUT,");\n");
  444. }
  445. static
  446. void
  447. debug_fuse_read_in(const void *arg_)
  448. {
  449. const struct fuse_read_in *arg = arg_;
  450. fprintf(g_OUTPUT,
  451. "fuse_read_in:"
  452. " fh=0x%"PRIx64";"
  453. " offset=%zu;"
  454. " size=%u;"
  455. " read_flags=%X;"
  456. " lock_owner=0x%"PRIx64";"
  457. " flags=0x%X ("
  458. ,
  459. arg->fh,
  460. arg->offset,
  461. arg->size,
  462. arg->read_flags,
  463. arg->lock_owner,
  464. arg->flags);
  465. debug_open_flags(arg->flags);
  466. fprintf(g_OUTPUT,");\n");
  467. }
  468. static
  469. void
  470. debug_fuse_write_in(const void *arg_)
  471. {
  472. const struct fuse_write_in *arg = arg_;
  473. fprintf(g_OUTPUT,
  474. "fuse_write_in:"
  475. " fh=0x%"PRIx64";"
  476. " offset=%zu;"
  477. " size=%u;"
  478. " lock_owner=0x%"PRIx64";"
  479. " flags=0x%X ("
  480. ,
  481. arg->fh,
  482. arg->offset,
  483. arg->size,
  484. arg->lock_owner,
  485. arg->flags);
  486. debug_open_flags(arg->flags);
  487. fprintf(g_OUTPUT,
  488. "); write_flags=0x%X (",
  489. arg->write_flags);
  490. for(int i = 0; i < (sizeof(arg->write_flags) * 8); i++)
  491. {
  492. const char *str;
  493. if(!(arg->write_flags & (1 << i)))
  494. continue;
  495. str = fuse_write_flag_to_str(i);
  496. if(str == NULL)
  497. continue;
  498. fprintf(g_OUTPUT,"%s,",str);
  499. }
  500. fprintf(g_OUTPUT,");\n");
  501. }
  502. static
  503. void
  504. debug_fuse_flush_in(const void *arg_)
  505. {
  506. const struct fuse_flush_in *arg = arg_;
  507. fprintf(g_OUTPUT,
  508. "fuse_flush_in:"
  509. " fh=0x%"PRIx64";"
  510. " lock_owner=0x%"PRIx64";"
  511. "\n"
  512. ,
  513. arg->fh,
  514. arg->lock_owner);
  515. }
  516. static
  517. void
  518. debug_fuse_release_in(const void *arg_)
  519. {
  520. const struct fuse_release_in *arg = arg_;
  521. fprintf(g_OUTPUT,
  522. "fuse_release_in:"
  523. " fh=0x%"PRIx64";"
  524. " release_flags=0x%X;"
  525. " lock_owner=0x%"PRIx64";"
  526. " flags=0x%X ("
  527. ,
  528. arg->fh,
  529. arg->release_flags,
  530. arg->lock_owner,
  531. arg->flags);
  532. debug_open_flags(arg->flags);
  533. fprintf(g_OUTPUT,");\n");
  534. }
  535. static
  536. void
  537. debug_fuse_fsync_in(const void *arg_)
  538. {
  539. const struct fuse_fsync_in *arg = arg_;
  540. fprintf(g_OUTPUT,
  541. "fuse_fsync_in:"
  542. " fh=0x%"PRIx64";"
  543. " fsync_flags=0x%X;"
  544. "\n"
  545. ,
  546. arg->fh,
  547. arg->fsync_flags);
  548. }
  549. static
  550. void
  551. debug_fuse_setxattr_in(const void *arg_)
  552. {
  553. const char *name;
  554. const char *value;
  555. const struct fuse_setxattr_in *arg = arg_;
  556. name = PARAM(arg);
  557. value = (name + strlen(name) + 1);
  558. fprintf(g_OUTPUT,
  559. "fuse_setxattr_in:"
  560. " size=%u;"
  561. " flags=0x%X;"
  562. " name=%s;"
  563. " value=%s;"
  564. "\n"
  565. ,
  566. arg->size,
  567. arg->flags,
  568. name,
  569. value);
  570. }
  571. static
  572. void
  573. debug_fuse_getxattr_in(const void *arg_)
  574. {
  575. const char *name;
  576. const struct fuse_getxattr_in *arg = arg_;
  577. name = PARAM(arg);
  578. fprintf(g_OUTPUT,
  579. "fuse_getxattr_in:"
  580. " size=%u;"
  581. " name=%s;"
  582. "\n"
  583. ,
  584. arg->size,
  585. name);
  586. }
  587. static
  588. void
  589. debug_fuse_listxattr(const void *arg_)
  590. {
  591. const struct fuse_getxattr_in *arg = arg_;
  592. fprintf(g_OUTPUT,
  593. "fuse_listxattr:"
  594. " size=%u;"
  595. "\n"
  596. ,
  597. arg->size);
  598. }
  599. static
  600. void
  601. debug_fuse_removexattr(const void *arg_)
  602. {
  603. const char *name = arg_;
  604. fprintf(g_OUTPUT,
  605. "fuse_removexattr:"
  606. " name=%s;"
  607. "\n"
  608. ,
  609. name);
  610. }
  611. static
  612. void
  613. debug_fuse_fallocate_in(const void *arg_)
  614. {
  615. const struct fuse_fallocate_in *arg = arg_;
  616. fprintf(g_OUTPUT,
  617. "fuse_fallocate_in:"
  618. " fh=0x%"PRIx64";"
  619. " offset=%zu;"
  620. " length=%zu;"
  621. " mode=%o;"
  622. "\n"
  623. ,
  624. arg->fh,
  625. arg->offset,
  626. arg->length,
  627. arg->mode);
  628. }
  629. void
  630. debug_fuse_init_in(const struct fuse_init_in *arg_)
  631. {
  632. uint64_t flags;
  633. flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
  634. fprintf(g_OUTPUT,
  635. "FUSE_INIT_IN: "
  636. " major=%u;"
  637. " minor=%u;"
  638. " max_readahead=%u;"
  639. " flags=0x%016lx (",
  640. arg_->major,
  641. arg_->minor,
  642. arg_->max_readahead,
  643. flags);
  644. for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
  645. {
  646. const char *str;
  647. if(!(flags & (1ULL << i)))
  648. continue;
  649. str = fuse_flag_to_str(i);
  650. if(str == NULL)
  651. continue;
  652. fprintf(g_OUTPUT,"%s, ",str);
  653. }
  654. fprintf(g_OUTPUT,")\n");
  655. }
  656. void
  657. debug_fuse_init_out(const uint64_t unique_,
  658. const struct fuse_init_out *arg_,
  659. const uint64_t argsize_)
  660. {
  661. uint64_t flags;
  662. const struct fuse_init_out *arg = arg_;
  663. flags = (((uint64_t)arg->flags) | ((uint64_t)arg->flags2) << 32);
  664. fprintf(g_OUTPUT,
  665. /* "unique=0x%016"PRIx64";" */
  666. /* " opcode=RESPONSE;" */
  667. /* " error=0 (Success);" */
  668. /* " len=%"PRIu64"; || " */
  669. "FUSE_INIT_OUT:"
  670. " major=%u;"
  671. " minor=%u;"
  672. " max_readahead=%u;"
  673. " flags=0x%016lx ("
  674. ,
  675. /* unique_, */
  676. /* sizeof(struct fuse_out_header) + argsize_, */
  677. arg->major,
  678. arg->minor,
  679. arg->max_readahead,
  680. flags);
  681. for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
  682. {
  683. const char *str;
  684. if(!(flags & (1ULL << i)))
  685. continue;
  686. str = fuse_flag_to_str(i);
  687. if(str == NULL)
  688. continue;
  689. fprintf(g_OUTPUT,"%s, ",str);
  690. }
  691. fprintf(g_OUTPUT,
  692. "); max_background=%u;"
  693. " congestion_threshold=%u;"
  694. " max_write=%u;"
  695. " time_gran=%u;"
  696. " max_pages=%u;"
  697. " map_alignment=%u;"
  698. " max_stack_depth=%u;"
  699. "\n",
  700. arg->max_background,
  701. arg->congestion_threshold,
  702. arg->max_write,
  703. arg->time_gran,
  704. arg->max_pages,
  705. arg->map_alignment,
  706. arg->max_stack_depth);
  707. }
  708. static
  709. void
  710. debug_fuse_attr(const struct fuse_attr *attr_)
  711. {
  712. fprintf(g_OUTPUT,
  713. "attr:"
  714. " ino=0x%016"PRIx64";"
  715. " size=%"PRIu64";"
  716. " blocks=%"PRIu64";"
  717. " atime=%"PRIu64";"
  718. " atimensec=%u;"
  719. " mtime=%"PRIu64";"
  720. " mtimensec=%u;"
  721. " ctime=%"PRIu64";"
  722. " ctimesec=%u;"
  723. " mode=%o;"
  724. " nlink=%u;"
  725. " uid=%u;"
  726. " gid=%u;"
  727. " rdev=%u;"
  728. " blksize=%u;"
  729. ,
  730. attr_->ino,
  731. attr_->size,
  732. attr_->blocks,
  733. attr_->atime,
  734. attr_->atimensec,
  735. attr_->mtime,
  736. attr_->mtimensec,
  737. attr_->ctime,
  738. attr_->ctimensec,
  739. attr_->mode,
  740. attr_->nlink,
  741. attr_->uid,
  742. attr_->gid,
  743. attr_->rdev,
  744. attr_->blksize);
  745. }
  746. static
  747. void
  748. debug_fuse_entry(const struct fuse_entry_out *entry_)
  749. {
  750. fprintf(g_OUTPUT,
  751. " fuse_entry_out:"
  752. " nodeid=0x%016"PRIx64";"
  753. " generation=0x%016"PRIx64";"
  754. " entry_valid=%"PRIu64";"
  755. " entry_valid_nsec=%u;"
  756. " attr_valid=%"PRIu64";"
  757. " attr_valid_nsec=%u;"
  758. " ",
  759. entry_->nodeid,
  760. entry_->generation,
  761. entry_->entry_valid,
  762. entry_->entry_valid_nsec,
  763. entry_->attr_valid,
  764. entry_->attr_valid_nsec);
  765. debug_fuse_attr(&entry_->attr);
  766. }
  767. void
  768. debug_fuse_entry_out(const uint64_t unique_,
  769. const struct fuse_entry_out *arg_,
  770. const uint64_t argsize_)
  771. {
  772. fprintf(g_OUTPUT,
  773. "unique=0x%016"PRIx64";"
  774. " opcode=RESPONSE;"
  775. " error=0 (Success);"
  776. " len=%"PRIu64"; || "
  777. ,
  778. unique_,
  779. sizeof(struct fuse_out_header) + argsize_);
  780. debug_fuse_entry(arg_);
  781. }
  782. void
  783. debug_fuse_attr_out(const uint64_t unique_,
  784. const struct fuse_attr_out *arg_,
  785. const uint64_t argsize_)
  786. {
  787. fprintf(g_OUTPUT,
  788. "unique=0x%016"PRIx64";"
  789. " opcode=RESPONSE;"
  790. " error=0 (Success);"
  791. " len=%"PRIu64"; || "
  792. "fuse_attr_out:"
  793. " attr_valid=%zu;"
  794. " attr_valid_nsec=%u;"
  795. " ino=%zu;"
  796. " size=%zu;"
  797. " blocks=%zu;"
  798. " atime=%zu;"
  799. " atimensec=%u;"
  800. " mtime=%zu;"
  801. " mtimensec=%u;"
  802. " ctime=%zu;"
  803. " ctimensec=%u;"
  804. " mode=%o;"
  805. " nlink=%u;"
  806. " uid=%u;"
  807. " gid=%u;"
  808. " rdev=%u;"
  809. " blksize=%u;"
  810. "\n",
  811. unique_,
  812. sizeof(struct fuse_out_header) + argsize_,
  813. arg_->attr_valid,
  814. arg_->attr_valid_nsec,
  815. arg_->attr.ino,
  816. arg_->attr.size,
  817. arg_->attr.blocks,
  818. arg_->attr.atime,
  819. arg_->attr.atimensec,
  820. arg_->attr.mtime,
  821. arg_->attr.mtimensec,
  822. arg_->attr.ctime,
  823. arg_->attr.ctimensec,
  824. arg_->attr.mode,
  825. arg_->attr.nlink,
  826. arg_->attr.uid,
  827. arg_->attr.gid,
  828. arg_->attr.rdev,
  829. arg_->attr.blksize);
  830. }
  831. static
  832. void
  833. debug_fuse_interrupt_in(const void *arg_)
  834. {
  835. const struct fuse_interrupt_in *arg = arg_;
  836. fprintf(g_OUTPUT,
  837. "fuse_interrupt_in:"
  838. " unique=0x%016"PRIx64";"
  839. "\n"
  840. ,
  841. arg->unique);
  842. }
  843. static
  844. const
  845. char*
  846. opcode_name(enum fuse_opcode op_)
  847. {
  848. static const char *names[] =
  849. {
  850. [FUSE_LOOKUP] = "LOOKUP",
  851. [FUSE_FORGET] = "FORGET",
  852. [FUSE_GETATTR] = "GETATTR",
  853. [FUSE_SETATTR] = "SETATTR",
  854. [FUSE_READLINK] = "READLINK",
  855. [FUSE_SYMLINK] = "SYMLINK",
  856. [FUSE_MKNOD] = "MKNOD",
  857. [FUSE_MKDIR] = "MKDIR",
  858. [FUSE_UNLINK] = "UNLINK",
  859. [FUSE_RMDIR] = "RMDIR",
  860. [FUSE_RENAME] = "RENAME",
  861. [FUSE_LINK] = "LINK",
  862. [FUSE_OPEN] = "OPEN",
  863. [FUSE_READ] = "READ",
  864. [FUSE_WRITE] = "WRITE",
  865. [FUSE_STATFS] = "STATFS",
  866. [FUSE_RELEASE] = "RELEASE",
  867. [FUSE_FSYNC] = "FSYNC",
  868. [FUSE_SETXATTR] = "SETXATTR",
  869. [FUSE_GETXATTR] = "GETXATTR",
  870. [FUSE_LISTXATTR] = "LISTXATTR",
  871. [FUSE_REMOVEXATTR] = "REMOVEXATTR",
  872. [FUSE_FLUSH] = "FLUSH",
  873. [FUSE_INIT] = "INIT",
  874. [FUSE_OPENDIR] = "OPENDIR",
  875. [FUSE_READDIR] = "READDIR",
  876. [FUSE_RELEASEDIR] = "RELEASEDIR",
  877. [FUSE_FSYNCDIR] = "FSYNCDIR",
  878. [FUSE_GETLK] = "GETLK",
  879. [FUSE_SETLK] = "SETLK",
  880. [FUSE_SETLKW] = "SETLKW",
  881. [FUSE_ACCESS] = "ACCESS",
  882. [FUSE_CREATE] = "CREATE",
  883. [FUSE_INTERRUPT] = "INTERRUPT",
  884. [FUSE_BMAP] = "BMAP",
  885. [FUSE_DESTROY] = "DESTROY",
  886. [FUSE_IOCTL] = "IOCTL",
  887. [FUSE_POLL] = "POLL",
  888. [FUSE_NOTIFY_REPLY] = "NOTIFY_REPLY",
  889. [FUSE_BATCH_FORGET] = "BATCH_FORGET",
  890. [FUSE_FALLOCATE] = "FALLOCATE",
  891. [FUSE_READDIRPLUS] = "READDIRPLUS",
  892. [FUSE_RENAME2] = "RENAME2",
  893. [FUSE_LSEEK] = "LSEEK",
  894. [FUSE_COPY_FILE_RANGE] = "COPY_FILE_RANGE",
  895. [FUSE_SETUPMAPPING] = "SETUPMAPPING",
  896. [FUSE_REMOVEMAPPING] = "REMOVEMAPPING"
  897. };
  898. if(op_ >= (sizeof(names) / sizeof(names[0])))
  899. return "::UNKNOWN::";
  900. return names[op_];
  901. }
  902. void
  903. debug_fuse_in_header(const struct fuse_in_header *hdr_)
  904. {
  905. const void *arg = &hdr_[1];
  906. fprintf(stderr,
  907. "unique=0x%016"PRIx64";"
  908. " opcode=%s (%u);"
  909. " nodeid=%zu;"
  910. " uid=%u;"
  911. " gid=%u;"
  912. " pid=%u; || ",
  913. hdr_->unique,
  914. opcode_name(hdr_->opcode),
  915. hdr_->opcode,
  916. hdr_->nodeid,
  917. hdr_->uid,
  918. hdr_->gid,
  919. hdr_->pid);
  920. switch(hdr_->opcode)
  921. {
  922. case FUSE_LOOKUP:
  923. debug_fuse_lookup(arg);
  924. break;
  925. case FUSE_INIT:
  926. debug_fuse_init_in(arg);
  927. break;
  928. case FUSE_GETATTR:
  929. debug_fuse_getattr_in(arg);
  930. break;
  931. case FUSE_SETATTR:
  932. debug_fuse_setattr_in(arg);
  933. break;
  934. case FUSE_ACCESS:
  935. debug_fuse_access_in(arg);
  936. break;
  937. case FUSE_MKNOD:
  938. debug_fuse_mknod_in(arg);
  939. break;
  940. case FUSE_MKDIR:
  941. debug_fuse_mkdir_in(arg);
  942. break;
  943. case FUSE_UNLINK:
  944. debug_fuse_unlink(arg);
  945. break;
  946. case FUSE_RMDIR:
  947. debug_fuse_rmdir(arg);
  948. break;
  949. case FUSE_SYMLINK:
  950. debug_fuse_symlink(arg);
  951. break;
  952. case FUSE_RENAME:
  953. debug_fuse_rename_in(arg);
  954. break;
  955. case FUSE_LINK:
  956. debug_fuse_link_in(arg);
  957. break;
  958. case FUSE_CREATE:
  959. debug_fuse_create_in(arg);
  960. break;
  961. case FUSE_OPEN:
  962. debug_fuse_open_in(arg);
  963. break;
  964. case FUSE_OPENDIR:
  965. debug_fuse_open_in(arg);
  966. break;
  967. case FUSE_READ:
  968. debug_fuse_read_in(arg);
  969. break;
  970. case FUSE_READDIR:
  971. debug_fuse_read_in(arg);
  972. break;
  973. case FUSE_READDIRPLUS:
  974. debug_fuse_read_in(arg);
  975. break;
  976. case FUSE_WRITE:
  977. debug_fuse_write_in(arg);
  978. break;
  979. case FUSE_RELEASE:
  980. debug_fuse_release_in(arg);
  981. break;
  982. case FUSE_RELEASEDIR:
  983. debug_fuse_release_in(arg);
  984. break;
  985. case FUSE_FSYNCDIR:
  986. debug_fuse_fsync_in(arg);
  987. break;
  988. case FUSE_GETXATTR:
  989. debug_fuse_getxattr_in(arg);
  990. break;
  991. case FUSE_LISTXATTR:
  992. debug_fuse_listxattr(arg);
  993. break;
  994. case FUSE_SETXATTR:
  995. debug_fuse_setxattr_in(arg);
  996. break;
  997. case FUSE_REMOVEXATTR:
  998. debug_fuse_removexattr(arg);
  999. break;
  1000. case FUSE_FALLOCATE:
  1001. debug_fuse_fallocate_in(arg);
  1002. break;
  1003. case FUSE_FLUSH:
  1004. debug_fuse_flush_in(arg);
  1005. break;
  1006. case FUSE_INTERRUPT:
  1007. debug_fuse_interrupt_in(arg);
  1008. break;
  1009. default:
  1010. fprintf(g_OUTPUT,"FIXME\n");
  1011. break;
  1012. }
  1013. }
  1014. void
  1015. debug_fuse_out_header(const struct fuse_out_header *hdr_)
  1016. {
  1017. fprintf(g_OUTPUT,
  1018. "unique=0x%016"PRIx64";"
  1019. " opcode=RESPONSE;"
  1020. " error=%d (%s);"
  1021. " len=%"PRIu64";"
  1022. ,
  1023. hdr_->unique,
  1024. hdr_->error,
  1025. strerror(-hdr_->error),
  1026. sizeof(struct fuse_out_header));
  1027. }
  1028. void
  1029. debug_fuse_entry_open_out(const uint64_t unique_,
  1030. const struct fuse_entry_out *entry_,
  1031. const struct fuse_open_out *open_)
  1032. {
  1033. fprintf(g_OUTPUT,
  1034. "unique=0x%016"PRIx64";"
  1035. " opcode=RESPONSE;"
  1036. " error=0 (Success);"
  1037. " len=%"PRIu64"; || "
  1038. ,
  1039. unique_,
  1040. sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out));
  1041. debug_fuse_entry(entry_);
  1042. }
  1043. void
  1044. debug_fuse_readlink(const uint64_t unique_,
  1045. const char *linkname_)
  1046. {
  1047. fprintf(g_OUTPUT,
  1048. "unique=0x%016"PRIx64";"
  1049. " opcode=RESPONSE;"
  1050. " error=0 (Success);"
  1051. " len=%"PRIu64"; || "
  1052. "readlink: linkname=%s"
  1053. "\n"
  1054. ,
  1055. unique_,
  1056. (sizeof(struct fuse_out_header) + strlen(linkname_)),
  1057. linkname_);
  1058. }
  1059. void
  1060. debug_fuse_write_out(const uint64_t unique_,
  1061. const struct fuse_write_out *arg_)
  1062. {
  1063. fprintf(g_OUTPUT,
  1064. "unique=0x%016"PRIx64";"
  1065. " opcode=RESPONSE;"
  1066. " error=0 (Success);"
  1067. " len=%"PRIu64"; || "
  1068. " fuse_write_out:"
  1069. " size=%u"
  1070. "\n"
  1071. ,
  1072. unique_,
  1073. sizeof(struct fuse_write_out),
  1074. arg_->size);
  1075. }
  1076. void
  1077. debug_fuse_statfs_out(const uint64_t unique_,
  1078. const struct fuse_statfs_out *arg_)
  1079. {
  1080. fprintf(g_OUTPUT,
  1081. "unique=0x%016"PRIx64";"
  1082. " opcode=RESPONSE;"
  1083. " error=0 (Success);"
  1084. " len=%"PRIu64"; || "
  1085. " fuse_statfs_out:"
  1086. " blocks=%"PRIu64";"
  1087. " bfree=%"PRIu64";"
  1088. " bavail=%"PRIu64";"
  1089. " files=%"PRIu64";"
  1090. " ffree=%"PRIu64";"
  1091. " bsize=%u;"
  1092. " namelen=%u;"
  1093. " frsize=%u;"
  1094. "\n"
  1095. ,
  1096. unique_,
  1097. sizeof(struct fuse_statfs_out),
  1098. arg_->st.blocks,
  1099. arg_->st.bfree,
  1100. arg_->st.bavail,
  1101. arg_->st.files,
  1102. arg_->st.ffree,
  1103. arg_->st.bsize,
  1104. arg_->st.namelen,
  1105. arg_->st.frsize);
  1106. }
  1107. void
  1108. debug_fuse_getxattr_out(const uint64_t unique_,
  1109. const struct fuse_getxattr_out *arg_)
  1110. {
  1111. fprintf(g_OUTPUT,
  1112. "unique=0x%016"PRIx64";"
  1113. " opcode=RESPONSE;"
  1114. " error=0 (Success);"
  1115. " len=%"PRIu64"; || "
  1116. " fuse_getxattr_out:"
  1117. " size=%u;"
  1118. "\n"
  1119. ,
  1120. unique_,
  1121. sizeof(struct fuse_out_header) + sizeof(struct fuse_getxattr_out),
  1122. arg_->size);
  1123. }
  1124. void
  1125. debug_fuse_lk_out(const uint64_t unique_,
  1126. const struct fuse_lk_out *arg_)
  1127. {
  1128. fprintf(g_OUTPUT,
  1129. "unique=0x%016"PRIx64";"
  1130. " opcode=RESPONSE;"
  1131. " error=0 (Success);"
  1132. " len=%"PRIu64"; || "
  1133. " fuse_file_lock:"
  1134. " start=%"PRIu64";"
  1135. " end=%"PRIu64";"
  1136. " type=%u;"
  1137. " pid=%u;"
  1138. "\n"
  1139. ,
  1140. unique_,
  1141. sizeof(struct fuse_out_header) + sizeof(struct fuse_lk_out),
  1142. arg_->lk.start,
  1143. arg_->lk.end,
  1144. arg_->lk.type,
  1145. arg_->lk.pid);
  1146. }
  1147. void
  1148. debug_fuse_bmap_out(const uint64_t unique_,
  1149. const struct fuse_bmap_out *arg_)
  1150. {
  1151. fprintf(g_OUTPUT,
  1152. "unique=0x%016"PRIx64";"
  1153. " opcode=RESPONSE;"
  1154. " error=0 (Success);"
  1155. " len=%"PRIu64"; || "
  1156. " fuse_bmap_out:"
  1157. " block=%"PRIu64";"
  1158. "\n"
  1159. ,
  1160. unique_,
  1161. sizeof(struct fuse_out_header) + sizeof(struct fuse_bmap_out),
  1162. arg_->block);
  1163. }