/core/10.4/fusefs/fuse.h

http://macfuse.googlecode.com/ · C++ Header · 209 lines · 156 code · 41 blank · 12 comment · 5 complexity · 1d690f6500b9dbebdf8f9b72332287be MD5 · raw file

  1. /*
  2. * Copyright (C) 2006-2008 Google. All Rights Reserved.
  3. * Amit Singh <singh@>
  4. */
  5. #ifndef _MACFUSE_H_
  6. #define _MACFUSE_H_
  7. #include <sys/param.h>
  8. #include <sys/types.h>
  9. #include <sys/event.h>
  10. #include <kern/thread_call.h>
  11. #include <libkern/OSMalloc.h>
  12. #include <libkern/locks.h>
  13. #include <IOKit/IOLib.h>
  14. #ifndef _FUSE_KERNEL_H_
  15. #define _FUSE_KERNEL_H_
  16. #include "fuse_kernel.h"
  17. #endif
  18. #include <fuse_param.h>
  19. #include <fuse_sysctl.h>
  20. #include <fuse_version.h>
  21. #define FUSE_COUNT_MEMORY 1
  22. // #define FUSE_DEBUG 1
  23. // #define FUSE_KDEBUG 1
  24. // #define FUSE_KTRACE_OP 1
  25. // #define FUSE_TRACE 1
  26. // #define FUSE_TRACE_LK 1
  27. // #define FUSE_TRACE_MSLEEP 1
  28. // #define FUSE_TRACE_OP 1
  29. // #define FUSE_TRACE_VNCACHE 1
  30. #define FUSEFS_SIGNATURE 0x55464553 // 'FUSE'
  31. #ifdef FUSE_TRACE
  32. #define fuse_trace_printf(fmt, ...) IOLog(fmt, ## __VA_ARGS__)
  33. #define fuse_trace_printf_func() IOLog("%s\n", __FUNCTION__)
  34. #else
  35. #define fuse_trace_printf(fmt, ...) {}
  36. #define fuse_trace_printf_func() {}
  37. #endif
  38. #ifdef FUSE_TRACE_OP
  39. #define fuse_trace_printf_vfsop() IOLog("%s\n", __FUNCTION__)
  40. #define fuse_trace_printf_vnop_novp() IOLog("%s\n", __FUNCTION__)
  41. #define fuse_trace_printf_vnop() IOLog("%s vp=%p\n", __FUNCTION__, vp)
  42. #else
  43. #define fuse_trace_printf_vfsop() {}
  44. #define fuse_trace_printf_vnop() {}
  45. #define fuse_trace_printf_vnop_novp() {}
  46. #endif
  47. #ifdef FUSE_TRACE_MSLEEP
  48. static __inline__ int
  49. fuse_msleep(void *chan, lck_mtx_t *mtx, int pri, const char *wmesg,
  50. struct timespec *ts)
  51. {
  52. int ret;
  53. IOLog("0: msleep(%p, %s)\n", (chan), (wmesg));
  54. ret = msleep(chan, mtx, pri, wmesg, ts);
  55. IOLog("1: msleep(%p, %s)\n", (chan), (wmesg));
  56. return ret;
  57. }
  58. #define fuse_wakeup(chan) \
  59. { \
  60. IOLog("1: wakeup(%p)\n", (chan)); \
  61. wakeup((chan)); \
  62. IOLog("0: wakeup(%p)\n", (chan)); \
  63. }
  64. #define fuse_wakeup_one(chan) \
  65. { \
  66. IOLog("1: wakeup_one(%p)\n", (chan)); \
  67. wakeup_one((chan)); \
  68. IOLog("0: wakeup_one(%p)\n", (chan)); \
  69. }
  70. #else
  71. #define fuse_msleep(chan, mtx, pri, wmesg, ts) \
  72. msleep((chan), (mtx), (pri), (wmesg), (ts))
  73. #define fuse_wakeup(chan) wakeup((chan))
  74. #define fuse_wakeup_one(chan) wakeup_one((chan))
  75. #endif
  76. #ifdef FUSE_KTRACE_OP
  77. #undef fuse_trace_printf_vfsop
  78. #undef fuse_trace_printf_vnop
  79. #define fuse_trace_printf_vfsop() kprintf("%s\n", __FUNCTION__)
  80. #define fuse_trace_printf_vnop() kprintf("%s\n", __FUNCTION__)
  81. #endif
  82. #ifdef FUSE_DEBUG
  83. #define debug_printf(fmt, ...) \
  84. IOLog("%s[%s:%d]: " fmt, __FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__)
  85. #else
  86. #define debug_printf(fmt, ...) {}
  87. #endif
  88. #ifdef FUSE_KDEBUG
  89. #undef debug_printf
  90. #define debug_printf(fmt, ...) \
  91. IOLog("%s[%s:%d]: " fmt, __FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__);\
  92. kprintf("%s[%s:%d]: " fmt, __FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__)
  93. #define kdebug_printf(fmt, ...) debug_printf(fmt, ## __VA_ARGS__)
  94. #else
  95. #define kdebug_printf(fmt, ...) {}
  96. #endif
  97. #define FUSE_ASSERT(a) \
  98. { \
  99. if (!(a)) { \
  100. IOLog("File "__FILE__", line %d: assertion ' %s ' failed.\n", \
  101. __LINE__, #a); \
  102. } \
  103. }
  104. #define E_NONE 0
  105. #define fuse_round_page_32(x) \
  106. (((uint32_t)(x) + 0x1000 - 1) & ~(0x1000 - 1))
  107. #define FUSE_ZERO_SIZE 0x0000000000000000ULL
  108. #define FUSE_ROOT_SIZE 0xFFFFFFFFFFFFFFFFULL
  109. extern OSMallocTag fuse_malloc_tag;
  110. #ifdef FUSE_COUNT_MEMORY
  111. #define FUSE_OSAddAtomic(amount, value) OSAddAtomic((amount), (value))
  112. extern int32_t fuse_memory_allocated;
  113. static __inline__
  114. void *
  115. FUSE_OSMalloc(size_t size, OSMallocTag tag)
  116. {
  117. void *addr = OSMalloc((uint32_t)size, tag);
  118. if (!addr) {
  119. panic("MacFUSE: memory allocation failed (size=%lu)", size);
  120. }
  121. FUSE_OSAddAtomic((UInt32)size, (SInt32 *)&fuse_memory_allocated);
  122. return addr;
  123. }
  124. static __inline__
  125. void
  126. FUSE_OSFree(void *addr, size_t size, OSMallocTag tag)
  127. {
  128. OSFree(addr, (uint32_t)size, tag);
  129. FUSE_OSAddAtomic(-(UInt32)(size), (SInt32 *)&fuse_memory_allocated);
  130. }
  131. #else
  132. #define FUSE_OSAddAtomic(amount, value) {}
  133. #define FUSE_OSMalloc(size, tag) OSMalloc((uint32_t)(size), (tag))
  134. #define FUSE_OSFree(addr, size, tag) OSFree((addr), (size), (tag))
  135. #endif /* FUSE_COUNT_MEMORY */
  136. static __inline__
  137. void *
  138. FUSE_OSRealloc_nocopy(void *oldptr, size_t oldsize, size_t newsize)
  139. {
  140. void *data;
  141. data = FUSE_OSMalloc(newsize, fuse_malloc_tag);
  142. if (!data) {
  143. panic("MacFUSE: OSMalloc failed in realloc");
  144. }
  145. FUSE_OSFree(oldptr, oldsize, fuse_malloc_tag);
  146. FUSE_OSAddAtomic(1, (SInt32 *)&fuse_realloc_count);
  147. return data;
  148. }
  149. static __inline__
  150. void *
  151. FUSE_OSRealloc_nocopy_canfail(void *oldptr, size_t oldsize, size_t newsize)
  152. {
  153. void *data;
  154. data = FUSE_OSMalloc(newsize, fuse_malloc_tag);
  155. if (!data) {
  156. goto out;
  157. } else {
  158. FUSE_OSFree(oldptr, oldsize, fuse_malloc_tag);
  159. FUSE_OSAddAtomic(1, (SInt32 *)&fuse_realloc_count);
  160. }
  161. out:
  162. return data;
  163. }
  164. typedef enum fuse_op_waitfor {
  165. FUSE_OP_BACKGROUNDED = 0,
  166. FUSE_OP_FOREGROUNDED = 1,
  167. } fuse_op_waitfor_t;
  168. #endif /* _MACFUSE_H_ */