PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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