12 #include "fuse_config.h" 
   14 #include "fuse_lowlevel.h" 
   16 #include "fuse_misc.h" 
   17 #include "fuse_kernel.h" 
   33 #include <sys/param.h> 
   39 #define FUSE_NODE_SLAB 1 
   45 #ifndef RENAME_EXCHANGE 
   46 #define RENAME_EXCHANGE         (1 << 1)         
   49 #define FUSE_DEFAULT_INTR_SIGNAL SIGUSR1 
   51 #define FUSE_UNKNOWN_INO 0xffffffff 
   52 #define OFFSET_MAX 0x7fffffffffffffffLL 
   54 #define NODE_TABLE_MIN_SIZE 8192 
   67 struct lock_queue_element {
 
   68         struct lock_queue_element *next;
 
   89 #define container_of(ptr, type, member) ({                              \ 
   90                         const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 
   91                         (type *)( (char *)__mptr - offsetof(type,member) );}) 
   93 #define list_entry(ptr, type, member)           \ 
   94         container_of(ptr, type, member) 
   97         struct list_head *next;
 
   98         struct list_head *prev;
 
  102         struct list_head list;  
 
  103         struct list_head freelist;
 
  108         struct fuse_session *se;
 
  109         struct node_table name_table;
 
  110         struct node_table id_table;
 
  111         struct list_head lru_table;
 
  113         unsigned int generation;
 
  114         unsigned int hidectr;
 
  115         pthread_mutex_t lock;
 
  119         struct lock_queue_element *lockq;
 
  121         struct list_head partial_slabs;
 
  122         struct list_head full_slabs;
 
  123         pthread_t prune_thread;
 
  136         struct node *name_next;
 
  137         struct node *id_next;
 
  139         unsigned int generation;
 
  145         struct timespec stat_updated;
 
  146         struct timespec mtime;
 
  149         unsigned int is_hidden : 1;
 
  150         unsigned int cache_valid : 1;
 
  152         char inline_name[32];
 
  155 #define TREELOCK_WRITE -1 
  156 #define TREELOCK_WAIT_OFFSET INT_MIN 
  160         struct list_head lru;
 
  161         struct timespec forget_time;
 
  164 struct fuse_direntry {
 
  167         struct fuse_direntry *next;
 
  171         pthread_mutex_t lock;
 
  175         struct fuse_direntry *first;
 
  176         struct fuse_direntry **last;
 
  186 struct fuse_context_i {
 
  197 static pthread_key_t fuse_context_key;
 
  198 static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER;
 
  199 static int fuse_context_ref;
 
  202 static int fuse_register_module(
const char *name,
 
  204                                 struct fusemod_so *so)
 
  210                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module\n");
 
  213         mod->name = strdup(name);
 
  215                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module name\n");
 
  219         mod->factory = factory;
 
  224         mod->next = fuse_modules;
 
  230 static void fuse_unregister_module(
struct fuse_module *m)
 
  233         for (mp = &fuse_modules; *mp; mp = &(*mp)->next) {
 
  243 static int fuse_load_so_module(
const char *module)
 
  247         struct fusemod_so *so;
 
  250         tmp = malloc(strlen(module) + 64);
 
  252                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
  255         sprintf(tmp, 
"libfusemod_%s.so", module);
 
  256         so = calloc(1, 
sizeof(
struct fusemod_so));
 
  258                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module so\n");
 
  262         so->handle = dlopen(tmp, RTLD_NOW);
 
  263         if (so->handle == NULL) {
 
  264                 fuse_log(FUSE_LOG_ERR, 
"fuse: dlopen(%s) failed: %s\n",
 
  269         sprintf(tmp, 
"fuse_module_%s_factory", module);
 
  271         if (factory == NULL) {
 
  272                 fuse_log(FUSE_LOG_ERR, 
"fuse: symbol <%s> not found in module: %s\n",
 
  276         ret = fuse_register_module(module, *factory, so);
 
  291 static struct fuse_module *fuse_find_module(
const char *module)
 
  294         for (m = fuse_modules; m; m = m->next) {
 
  295                 if (strcmp(module, m->name) == 0) {
 
  303 static struct fuse_module *fuse_get_module(
const char *module)
 
  307         pthread_mutex_lock(&fuse_context_lock);
 
  308         m = fuse_find_module(module);
 
  310                 int err = fuse_load_so_module(module);
 
  312                         m = fuse_find_module(module);
 
  314         pthread_mutex_unlock(&fuse_context_lock);
 
  320         pthread_mutex_lock(&fuse_context_lock);
 
  326         if (!m->ctr && m->so) {
 
  327                 struct fusemod_so *so = m->so;
 
  332                         for (mp = &fuse_modules; *mp;) {
 
  334                                         fuse_unregister_module(*mp);
 
  341         } 
else if (!m->ctr) {
 
  342                 fuse_unregister_module(m);
 
  344         pthread_mutex_unlock(&fuse_context_lock);
 
  347 static void init_list_head(
struct list_head *list)
 
  353 static int list_empty(
const struct list_head *head)
 
  355         return head->next == head;
 
  358 static void list_add(
struct list_head *
new, 
struct list_head *prev,
 
  359                      struct list_head *next)
 
  367 static inline void list_add_head(
struct list_head *
new, 
struct list_head *head)
 
  369         list_add(
new, head, head->next);
 
  372 static inline void list_add_tail(
struct list_head *
new, 
struct list_head *head)
 
  374         list_add(
new, head->prev, head);
 
  377 static inline void list_del(
struct list_head *entry)
 
  379         struct list_head *prev = entry->prev;
 
  380         struct list_head *next = entry->next;
 
  386 static inline int lru_enabled(
struct fuse *f)
 
  388         return f->conf.remember > 0;
 
  391 static struct node_lru *node_lru(
struct node *node)
 
  393         return (
struct node_lru *) node;
 
  396 static size_t get_node_size(
struct fuse *f)
 
  399                 return sizeof(
struct node_lru);
 
  401                 return sizeof(
struct node);
 
  404 #ifdef FUSE_NODE_SLAB 
  405 static struct node_slab *list_to_slab(
struct list_head *head)
 
  407         return (
struct node_slab *) head;
 
  410 static struct node_slab *node_to_slab(
struct fuse *f, 
struct node *node)
 
  412         return (
struct node_slab *) (((uintptr_t) node) & ~((uintptr_t) f->pagesize - 1));
 
  415 static int alloc_slab(
struct fuse *f)
 
  418         struct node_slab *slab;
 
  422         size_t node_size = get_node_size(f);
 
  424         mem = mmap(NULL, f->pagesize, PROT_READ | PROT_WRITE,
 
  425                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
  427         if (mem == MAP_FAILED)
 
  431         init_list_head(&slab->freelist);
 
  433         num = (f->pagesize - 
sizeof(
struct node_slab)) / node_size;
 
  435         start = (
char *) mem + f->pagesize - num * node_size;
 
  436         for (i = 0; i < num; i++) {
 
  439                 n = (
struct list_head *) (start + i * node_size);
 
  440                 list_add_tail(n, &slab->freelist);
 
  442         list_add_tail(&slab->list, &f->partial_slabs);
 
  447 static struct node *alloc_node(
struct fuse *f)
 
  449         struct node_slab *slab;
 
  450         struct list_head *node;
 
  452         if (list_empty(&f->partial_slabs)) {
 
  453                 int res = alloc_slab(f);
 
  457         slab = list_to_slab(f->partial_slabs.next);
 
  459         node = slab->freelist.next;
 
  461         if (list_empty(&slab->freelist)) {
 
  462                 list_del(&slab->list);
 
  463                 list_add_tail(&slab->list, &f->full_slabs);
 
  465         memset(node, 0, 
sizeof(
struct node));
 
  467         return (
struct node *) node;
 
  470 static void free_slab(
struct fuse *f, 
struct node_slab *slab)
 
  474         list_del(&slab->list);
 
  475         res = munmap(slab, f->pagesize);
 
  477                 fuse_log(FUSE_LOG_WARNING, 
"fuse warning: munmap(%p) failed\n",
 
  481 static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  483         struct node_slab *slab = node_to_slab(f, node);
 
  484         struct list_head *n = (
struct list_head *) node;
 
  488                 if (list_empty(&slab->freelist)) {
 
  489                         list_del(&slab->list);
 
  490                         list_add_tail(&slab->list, &f->partial_slabs);
 
  492                 list_add_head(n, &slab->freelist);
 
  498 static struct node *alloc_node(
struct fuse *f)
 
  500         return (
struct node *) calloc(1, get_node_size(f));
 
  503 static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  510 static size_t id_hash(
struct fuse *f, 
fuse_ino_t ino)
 
  512         uint64_t hash = ((uint32_t) ino * 2654435761U) % f->id_table.size;
 
  513         uint64_t oldhash = hash % (f->id_table.size / 2);
 
  515         if (oldhash >= f->id_table.split)
 
  521 static struct node *get_node_nocheck(
struct fuse *f, 
fuse_ino_t nodeid)
 
  523         size_t hash = id_hash(f, nodeid);
 
  526         for (node = f->id_table.array[hash]; node != NULL; node = node->id_next)
 
  527                 if (node->nodeid == nodeid)
 
  533 static struct node *get_node(
struct fuse *f, 
fuse_ino_t nodeid)
 
  535         struct node *node = get_node_nocheck(f, nodeid);
 
  537                 fuse_log(FUSE_LOG_ERR, 
"fuse internal error: node %llu not found\n",
 
  538                         (
unsigned long long) nodeid);
 
  544 static void curr_time(
struct timespec *now);
 
  545 static double diff_timespec(
const struct timespec *t1,
 
  546                            const struct timespec *t2);
 
  548 static void remove_node_lru(
struct node *node)
 
  550         struct node_lru *lnode = node_lru(node);
 
  551         list_del(&lnode->lru);
 
  552         init_list_head(&lnode->lru);
 
  555 static void set_forget_time(
struct fuse *f, 
struct node *node)
 
  557         struct node_lru *lnode = node_lru(node);
 
  559         list_del(&lnode->lru);
 
  560         list_add_tail(&lnode->lru, &f->lru_table);
 
  561         curr_time(&lnode->forget_time);
 
  564 static void free_node(
struct fuse *f, 
struct node *node)
 
  566         if (node->name != node->inline_name)
 
  568         free_node_mem(f, node);
 
  571 static void node_table_reduce(
struct node_table *t)
 
  573         size_t newsize = t->size / 2;
 
  576         if (newsize < NODE_TABLE_MIN_SIZE)
 
  579         newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  580         if (newarray != NULL)
 
  584         t->split = t->size / 2;
 
  587 static void remerge_id(
struct fuse *f)
 
  589         struct node_table *t = &f->id_table;
 
  593                 node_table_reduce(t);
 
  595         for (iter = 8; t->split > 0 && iter; iter--) {
 
  599                 upper = &t->array[t->split + t->size / 2];
 
  603                         for (nodep = &t->array[t->split]; *nodep;
 
  604                              nodep = &(*nodep)->id_next);
 
  613 static void unhash_id(
struct fuse *f, 
struct node *node)
 
  615         struct node **nodep = &f->id_table.array[id_hash(f, node->nodeid)];
 
  617         for (; *nodep != NULL; nodep = &(*nodep)->id_next)
 
  618                 if (*nodep == node) {
 
  619                         *nodep = node->id_next;
 
  622                         if(f->id_table.use < f->id_table.size / 4)
 
  628 static int node_table_resize(
struct node_table *t)
 
  630         size_t newsize = t->size * 2;
 
  633         newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  634         if (newarray == NULL)
 
  638         memset(t->array + t->size, 0, t->size * 
sizeof(
struct node *));
 
  645 static void rehash_id(
struct fuse *f)
 
  647         struct node_table *t = &f->id_table;
 
  652         if (t->split == t->size / 2)
 
  657         for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  658                 struct node *node = *nodep;
 
  659                 size_t newhash = id_hash(f, node->nodeid);
 
  661                 if (newhash != hash) {
 
  663                         *nodep = node->id_next;
 
  664                         node->id_next = t->array[newhash];
 
  665                         t->array[newhash] = node;
 
  667                         next = &node->id_next;
 
  670         if (t->split == t->size / 2)
 
  671                 node_table_resize(t);
 
  674 static void hash_id(
struct fuse *f, 
struct node *node)
 
  676         size_t hash = id_hash(f, node->nodeid);
 
  677         node->id_next = f->id_table.array[hash];
 
  678         f->id_table.array[hash] = node;
 
  681         if (f->id_table.use >= f->id_table.size / 2)
 
  685 static size_t name_hash(
struct fuse *f, 
fuse_ino_t parent,
 
  688         uint64_t hash = parent;
 
  691         for (; *name; name++)
 
  692                 hash = hash * 31 + (
unsigned char) *name;
 
  694         hash %= f->name_table.size;
 
  695         oldhash = hash % (f->name_table.size / 2);
 
  696         if (oldhash >= f->name_table.split)
 
  702 static void unref_node(
struct fuse *f, 
struct node *node);
 
  704 static void remerge_name(
struct fuse *f)
 
  706         struct node_table *t = &f->name_table;
 
  710                 node_table_reduce(t);
 
  712         for (iter = 8; t->split > 0 && iter; iter--) {
 
  716                 upper = &t->array[t->split + t->size / 2];
 
  720                         for (nodep = &t->array[t->split]; *nodep;
 
  721                              nodep = &(*nodep)->name_next);
 
  730 static void unhash_name(
struct fuse *f, 
struct node *node)
 
  733                 size_t hash = name_hash(f, node->parent->nodeid, node->name);
 
  734                 struct node **nodep = &f->name_table.array[hash];
 
  736                 for (; *nodep != NULL; nodep = &(*nodep)->name_next)
 
  737                         if (*nodep == node) {
 
  738                                 *nodep = node->name_next;
 
  739                                 node->name_next = NULL;
 
  740                                 unref_node(f, node->parent);
 
  741                                 if (node->name != node->inline_name)
 
  747                                 if (f->name_table.use < f->name_table.size / 4)
 
  752                         "fuse internal error: unable to unhash node: %llu\n",
 
  753                         (
unsigned long long) node->nodeid);
 
  758 static void rehash_name(
struct fuse *f)
 
  760         struct node_table *t = &f->name_table;
 
  765         if (t->split == t->size / 2)
 
  770         for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  771                 struct node *node = *nodep;
 
  772                 size_t newhash = name_hash(f, node->parent->nodeid, node->name);
 
  774                 if (newhash != hash) {
 
  776                         *nodep = node->name_next;
 
  777                         node->name_next = t->array[newhash];
 
  778                         t->array[newhash] = node;
 
  780                         next = &node->name_next;
 
  783         if (t->split == t->size / 2)
 
  784                 node_table_resize(t);
 
  787 static int hash_name(
struct fuse *f, 
struct node *node, 
fuse_ino_t parentid,
 
  790         size_t hash = name_hash(f, parentid, name);
 
  791         struct node *parent = get_node(f, parentid);
 
  792         if (strlen(name) < 
sizeof(node->inline_name)) {
 
  793                 strcpy(node->inline_name, name);
 
  794                 node->name = node->inline_name;
 
  796                 node->name = strdup(name);
 
  797                 if (node->name == NULL)
 
  802         node->parent = parent;
 
  803         node->name_next = f->name_table.array[hash];
 
  804         f->name_table.array[hash] = node;
 
  807         if (f->name_table.use >= f->name_table.size / 2)
 
  813 static void delete_node(
struct fuse *f, 
struct node *node)
 
  816                 fuse_log(FUSE_LOG_DEBUG, 
"DELETE: %llu\n",
 
  817                         (
unsigned long long) node->nodeid);
 
  819         assert(node->treelock == 0);
 
  820         unhash_name(f, node);
 
  822                 remove_node_lru(node);
 
  827 static void unref_node(
struct fuse *f, 
struct node *node)
 
  829         assert(node->refctr > 0);
 
  832                 delete_node(f, node);
 
  838                 f->ctr = (f->ctr + 1) & 0xffffffff;
 
  841         } 
while (f->ctr == 0 || f->ctr == FUSE_UNKNOWN_INO ||
 
  842                  get_node_nocheck(f, f->ctr) != NULL);
 
  846 static struct node *lookup_node(
struct fuse *f, 
fuse_ino_t parent,
 
  849         size_t hash = name_hash(f, parent, name);
 
  852         for (node = f->name_table.array[hash]; node != NULL; node = node->name_next)
 
  853                 if (node->parent->nodeid == parent &&
 
  854                     strcmp(node->name, name) == 0)
 
  860 static void inc_nlookup(
struct node *node)
 
  867 static struct node *find_node(
struct fuse *f, 
fuse_ino_t parent,
 
  872         pthread_mutex_lock(&f->lock);
 
  874                 node = get_node(f, parent);
 
  876                 node = lookup_node(f, parent, name);
 
  878                 node = alloc_node(f);
 
  882                 node->nodeid = next_id(f);
 
  883                 node->generation = f->generation;
 
  884                 if (f->conf.remember)
 
  887                 if (hash_name(f, node, parent, name) == -1) {
 
  893                 if (lru_enabled(f)) {
 
  894                         struct node_lru *lnode = node_lru(node);
 
  895                         init_list_head(&lnode->lru);
 
  897         } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
  898                 remove_node_lru(node);
 
  902         pthread_mutex_unlock(&f->lock);
 
  906 static int lookup_path_in_cache(
struct fuse *f,
 
  909         char *tmp = strdup(path);
 
  913         pthread_mutex_lock(&f->lock);
 
  918         char *path_element = strtok_r(tmp, 
"/", &save_ptr);
 
  919         while (path_element != NULL) {
 
  920                 struct node *node = lookup_node(f, ino, path_element);
 
  926                 path_element = strtok_r(NULL, 
"/", &save_ptr);
 
  928         pthread_mutex_unlock(&f->lock);
 
  936 static char *add_name(
char **buf, 
unsigned *bufsize, 
char *s, 
const char *name)
 
  938         size_t len = strlen(name);
 
  940         if (s - len <= *buf) {
 
  941                 unsigned pathlen = *bufsize - (s - *buf);
 
  942                 unsigned newbufsize = *bufsize;
 
  945                 while (newbufsize < pathlen + len + 1) {
 
  946                         if (newbufsize >= 0x80000000)
 
  947                                 newbufsize = 0xffffffff;
 
  952                 newbuf = realloc(*buf, newbufsize);
 
  957                 s = newbuf + newbufsize - pathlen;
 
  958                 memmove(s, newbuf + *bufsize - pathlen, pathlen);
 
  959                 *bufsize = newbufsize;
 
  962         memcpy(s, name, len);
 
  969 static void unlock_path(
struct fuse *f, 
fuse_ino_t nodeid, 
struct node *wnode,
 
  975                 assert(wnode->treelock == TREELOCK_WRITE);
 
  979         for (node = get_node(f, nodeid);
 
  980              node != end && node->nodeid != 
FUSE_ROOT_ID; node = node->parent) {
 
  981                 assert(node->treelock != 0);
 
  982                 assert(node->treelock != TREELOCK_WAIT_OFFSET);
 
  983                 assert(node->treelock != TREELOCK_WRITE);
 
  985                 if (node->treelock == TREELOCK_WAIT_OFFSET)
 
  990 static int try_get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
  991                         char **path, 
struct node **wnodep, 
bool need_lock)
 
  993         unsigned bufsize = 256;
 
  997         struct node *wnode = NULL;
 
 1003         buf = malloc(bufsize);
 
 1007         s = buf + bufsize - 1;
 
 1011                 s = add_name(&buf, &bufsize, s, name);
 
 1019                 wnode = lookup_node(f, nodeid, name);
 
 1021                         if (wnode->treelock != 0) {
 
 1022                                 if (wnode->treelock > 0)
 
 1023                                         wnode->treelock += TREELOCK_WAIT_OFFSET;
 
 1027                         wnode->treelock = TREELOCK_WRITE;
 
 1031         for (node = get_node(f, nodeid); node->nodeid != 
FUSE_ROOT_ID;
 
 1032              node = node->parent) {
 
 1034                 if (node->name == NULL || node->parent == NULL)
 
 1038                 s = add_name(&buf, &bufsize, s, node->name);
 
 1044                         if (node->treelock < 0)
 
 1052                 memmove(buf, s, bufsize - (s - buf));
 
 1064                 unlock_path(f, nodeid, wnode, node);
 
 1072 static int try_get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1074                          char **path1, 
char **path2,
 
 1075                          struct node **wnode1, 
struct node **wnode2)
 
 1080         err = try_get_path(f, nodeid1, name1, path1, wnode1, 
true);
 
 1082                 err = try_get_path(f, nodeid2, name2, path2, wnode2, 
true);
 
 1084                         struct node *wn1 = wnode1 ? *wnode1 : NULL;
 
 1086                         unlock_path(f, nodeid1, wn1, NULL);
 
 1093 static void queue_element_wakeup(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1099                 if (get_node(f, qe->nodeid1)->treelock == 0)
 
 1100                         pthread_cond_signal(&qe->cond);
 
 1109                 err = try_get_path(f, qe->nodeid1, qe->name1, qe->path1,
 
 1112                 err = try_get_path2(f, qe->nodeid1, qe->name1, qe->nodeid2,
 
 1113                                     qe->name2, qe->path1, qe->path2, qe->wnode1,
 
 1122         pthread_cond_signal(&qe->cond);
 
 1125 static void wake_up_queued(
struct fuse *f)
 
 1127         struct lock_queue_element *qe;
 
 1129         for (qe = f->lockq; qe != NULL; qe = qe->next)
 
 1130                 queue_element_wakeup(f, qe);
 
 1133 static void debug_path(
struct fuse *f, 
const char *msg, 
fuse_ino_t nodeid,
 
 1134                        const char *name, 
bool wr)
 
 1136         if (f->conf.debug) {
 
 1137                 struct node *wnode = NULL;
 
 1140                         wnode = lookup_node(f, nodeid, name);
 
 1143                         fuse_log(FUSE_LOG_DEBUG, 
"%s %llu (w)\n",
 
 1144                                 msg, (
unsigned long long) wnode->nodeid);
 
 1146                         fuse_log(FUSE_LOG_DEBUG, 
"%s %llu\n",
 
 1147                                 msg, (
unsigned long long) nodeid);
 
 1152 static void queue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1154         struct lock_queue_element **qp;
 
 1157         pthread_cond_init(&qe->cond, NULL);
 
 1159         for (qp = &f->lockq; *qp != NULL; qp = &(*qp)->next);
 
 1163 static void dequeue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1165         struct lock_queue_element **qp;
 
 1167         pthread_cond_destroy(&qe->cond);
 
 1168         for (qp = &f->lockq; *qp != qe; qp = &(*qp)->next);
 
 1172 static int wait_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1177                 pthread_cond_wait(&qe->cond, &f->lock);
 
 1178         } 
while (!qe->done);
 
 1180         dequeue_path(f, qe);
 
 1185 static int get_path_common(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1186                            char **path, 
struct node **wnode)
 
 1190         pthread_mutex_lock(&f->lock);
 
 1191         err = try_get_path(f, nodeid, name, path, wnode, 
true);
 
 1192         if (err == -EAGAIN) {
 
 1193                 struct lock_queue_element qe = {
 
 1199                 debug_path(f, 
"QUEUE PATH", nodeid, name, !!wnode);
 
 1200                 err = wait_path(f, &qe);
 
 1201                 debug_path(f, 
"DEQUEUE PATH", nodeid, name, !!wnode);
 
 1203         pthread_mutex_unlock(&f->lock);
 
 1208 static int get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1210         return get_path_common(f, nodeid, NULL, path, NULL);
 
 1213 static int get_path_nullok(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1217         if (f->conf.nullpath_ok) {
 
 1220                 err = get_path_common(f, nodeid, NULL, path, NULL);
 
 1228 static int get_path_name(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1231         return get_path_common(f, nodeid, name, path, NULL);
 
 1234 static int get_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1235                            char **path, 
struct node **wnode)
 
 1237         return get_path_common(f, nodeid, name, path, wnode);
 
 1240 #if defined(__FreeBSD__) 
 1241 #define CHECK_DIR_LOOP 
 1244 #if defined(CHECK_DIR_LOOP) 
 1245 static int check_dir_loop(
struct fuse *f,
 
 1249         struct node *node, *node1, *node2;
 
 1252         node1 = lookup_node(f, nodeid1, name1);
 
 1253         id1 = node1 ? node1->nodeid : nodeid1;
 
 1255         node2 = lookup_node(f, nodeid2, name2);
 
 1256         id2 = node2 ? node2->nodeid : nodeid2;
 
 1258         for (node = get_node(f, id2); node->nodeid != 
FUSE_ROOT_ID;
 
 1259              node = node->parent) {
 
 1260                 if (node->name == NULL || node->parent == NULL)
 
 1263                 if (node->nodeid != id2 && node->nodeid == id1)
 
 1269                 for (node = get_node(f, id1); node->nodeid != 
FUSE_ROOT_ID;
 
 1270                      node = node->parent) {
 
 1271                         if (node->name == NULL || node->parent == NULL)
 
 1274                         if (node->nodeid != id1 && node->nodeid == id2)
 
 1283 static int get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1285                      char **path1, 
char **path2,
 
 1286                      struct node **wnode1, 
struct node **wnode2)
 
 1290         pthread_mutex_lock(&f->lock);
 
 1292 #if defined(CHECK_DIR_LOOP) 
 1296                 err = check_dir_loop(f, nodeid1, name1, nodeid2, name2);
 
 1302         err = try_get_path2(f, nodeid1, name1, nodeid2, name2,
 
 1303                             path1, path2, wnode1, wnode2);
 
 1304         if (err == -EAGAIN) {
 
 1305                 struct lock_queue_element qe = {
 
 1316                 debug_path(f, 
"QUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1317                 debug_path(f, 
"      PATH2", nodeid2, name2, !!wnode2);
 
 1318                 err = wait_path(f, &qe);
 
 1319                 debug_path(f, 
"DEQUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1320                 debug_path(f, 
"        PATH2", nodeid2, name2, !!wnode2);
 
 1323 #if defined(CHECK_DIR_LOOP) 
 1326         pthread_mutex_unlock(&f->lock);
 
 1331 static void free_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid,
 
 1332                              struct node *wnode, 
char *path)
 
 1334         pthread_mutex_lock(&f->lock);
 
 1335         unlock_path(f, nodeid, wnode, NULL);
 
 1338         pthread_mutex_unlock(&f->lock);
 
 1342 static void free_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char *path)
 
 1345                 free_path_wrlock(f, nodeid, NULL, path);
 
 1349                        struct node *wnode1, 
struct node *wnode2,
 
 1350                        char *path1, 
char *path2)
 
 1352         pthread_mutex_lock(&f->lock);
 
 1353         unlock_path(f, nodeid1, wnode1, NULL);
 
 1354         unlock_path(f, nodeid2, wnode2, NULL);
 
 1356         pthread_mutex_unlock(&f->lock);
 
 1361 static void forget_node(
struct fuse *f, 
fuse_ino_t nodeid, uint64_t nlookup)
 
 1366         pthread_mutex_lock(&f->lock);
 
 1367         node = get_node(f, nodeid);
 
 1373         while (node->nlookup == nlookup && node->treelock) {
 
 1374                 struct lock_queue_element qe = {
 
 1378                 debug_path(f, 
"QUEUE PATH (forget)", nodeid, NULL, 
false);
 
 1382                         pthread_cond_wait(&qe.cond, &f->lock);
 
 1383                 } 
while (node->nlookup == nlookup && node->treelock);
 
 1385                 dequeue_path(f, &qe);
 
 1386                 debug_path(f, 
"DEQUEUE_PATH (forget)", nodeid, NULL, 
false);
 
 1389         assert(node->nlookup >= nlookup);
 
 1390         node->nlookup -= nlookup;
 
 1391         if (!node->nlookup) {
 
 1392                 unref_node(f, node);
 
 1393         } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
 1394                 set_forget_time(f, node);
 
 1396         pthread_mutex_unlock(&f->lock);
 
 1399 static void unlink_node(
struct fuse *f, 
struct node *node)
 
 1401         if (f->conf.remember) {
 
 1402                 assert(node->nlookup > 1);
 
 1405         unhash_name(f, node);
 
 1408 static void remove_node(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 1412         pthread_mutex_lock(&f->lock);
 
 1413         node = lookup_node(f, dir, name);
 
 1415                 unlink_node(f, node);
 
 1416         pthread_mutex_unlock(&f->lock);
 
 1419 static int rename_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1420                        fuse_ino_t newdir, 
const char *newname, 
int hide)
 
 1423         struct node *newnode;
 
 1426         pthread_mutex_lock(&f->lock);
 
 1427         node  = lookup_node(f, olddir, oldname);
 
 1428         newnode  = lookup_node(f, newdir, newname);
 
 1432         if (newnode != NULL) {
 
 1434                         fuse_log(FUSE_LOG_ERR, 
"fuse: hidden file got created during hiding\n");
 
 1438                 unlink_node(f, newnode);
 
 1441         unhash_name(f, node);
 
 1442         if (hash_name(f, node, newdir, newname) == -1) {
 
 1448                 node->is_hidden = 1;
 
 1451         pthread_mutex_unlock(&f->lock);
 
 1455 static int exchange_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1458         struct node *oldnode;
 
 1459         struct node *newnode;
 
 1462         pthread_mutex_lock(&f->lock);
 
 1463         oldnode  = lookup_node(f, olddir, oldname);
 
 1464         newnode  = lookup_node(f, newdir, newname);
 
 1467                 unhash_name(f, oldnode);
 
 1469                 unhash_name(f, newnode);
 
 1473                 if (hash_name(f, oldnode, newdir, newname) == -1)
 
 1477                 if (hash_name(f, newnode, olddir, oldname) == -1)
 
 1482         pthread_mutex_unlock(&f->lock);
 
 1486 static void set_stat(
struct fuse *f, 
fuse_ino_t nodeid, 
struct stat *stbuf)
 
 1488         if (!f->conf.use_ino)
 
 1489                 stbuf->st_ino = nodeid;
 
 1490         if (f->conf.set_mode)
 
 1491                 stbuf->st_mode = (stbuf->st_mode & S_IFMT) |
 
 1492                                  (0777 & ~f->conf.umask);
 
 1493         if (f->conf.set_uid)
 
 1494                 stbuf->st_uid = f->conf.uid;
 
 1495         if (f->conf.set_gid)
 
 1496                 stbuf->st_gid = f->conf.gid;
 
 1504 static void fuse_intr_sighandler(
int sig)
 
 1510 struct fuse_intr_data {
 
 1512         pthread_cond_t cond;
 
 1516 static void fuse_interrupt(
fuse_req_t req, 
void *d_)
 
 1518         struct fuse_intr_data *d = d_;
 
 1519         struct fuse *f = req_fuse(req);
 
 1521         if (d->id == pthread_self())
 
 1524         pthread_mutex_lock(&f->lock);
 
 1525         while (!d->finished) {
 
 1527                 struct timespec timeout;
 
 1529                 pthread_kill(d->id, f->conf.intr_signal);
 
 1530                 gettimeofday(&now, NULL);
 
 1531                 timeout.tv_sec = now.tv_sec + 1;
 
 1532                 timeout.tv_nsec = now.tv_usec * 1000;
 
 1533                 pthread_cond_timedwait(&d->cond, &f->lock, &timeout);
 
 1535         pthread_mutex_unlock(&f->lock);
 
 1538 static void fuse_do_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1539                                      struct fuse_intr_data *d)
 
 1541         pthread_mutex_lock(&f->lock);
 
 1543         pthread_cond_broadcast(&d->cond);
 
 1544         pthread_mutex_unlock(&f->lock);
 
 1546         pthread_cond_destroy(&d->cond);
 
 1549 static void fuse_do_prepare_interrupt(
fuse_req_t req, 
struct fuse_intr_data *d)
 
 1551         d->id = pthread_self();
 
 1552         pthread_cond_init(&d->cond, NULL);
 
 1557 static inline void fuse_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1558                                          struct fuse_intr_data *d)
 
 1561                 fuse_do_finish_interrupt(f, req, d);
 
 1564 static inline void fuse_prepare_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1565                                           struct fuse_intr_data *d)
 
 1568                 fuse_do_prepare_interrupt(req, d);
 
 1572                               char* buf, 
size_t len)
 
 1576         snprintf(buf, len, 
"%llu", (
unsigned long long) fi->
fh);
 
 1580 int fuse_fs_getattr(
struct fuse_fs *fs, 
const char *path, 
struct stat *buf,
 
 1584         if (fs->op.getattr) {
 
 1587                         fuse_log(FUSE_LOG_DEBUG, 
"getattr[%s] %s\n",
 
 1588                                 file_info_string(fi, buf, 
sizeof(buf)),
 
 1591                 return fs->op.getattr(path, buf, fi);
 
 1597 int fuse_fs_rename(
struct fuse_fs *fs, 
const char *oldpath,
 
 1598                    const char *newpath, 
unsigned int flags)
 
 1601         if (fs->op.rename) {
 
 1603                         fuse_log(FUSE_LOG_DEBUG, 
"rename %s %s 0x%x\n", oldpath, newpath,
 
 1606                 return fs->op.rename(oldpath, newpath, flags);
 
 1612 int fuse_fs_unlink(
struct fuse_fs *fs, 
const char *path)
 
 1615         if (fs->op.unlink) {
 
 1617                         fuse_log(FUSE_LOG_DEBUG, 
"unlink %s\n", path);
 
 1619                 return fs->op.unlink(path);
 
 1625 int fuse_fs_rmdir(
struct fuse_fs *fs, 
const char *path)
 
 1630                         fuse_log(FUSE_LOG_DEBUG, 
"rmdir %s\n", path);
 
 1632                 return fs->op.rmdir(path);
 
 1638 int fuse_fs_symlink(
struct fuse_fs *fs, 
const char *linkname, 
const char *path)
 
 1641         if (fs->op.symlink) {
 
 1643                         fuse_log(FUSE_LOG_DEBUG, 
"symlink %s %s\n", linkname, path);
 
 1645                 return fs->op.symlink(linkname, path);
 
 1651 int fuse_fs_link(
struct fuse_fs *fs, 
const char *oldpath, 
const char *newpath)
 
 1656                         fuse_log(FUSE_LOG_DEBUG, 
"link %s %s\n", oldpath, newpath);
 
 1658                 return fs->op.link(oldpath, newpath);
 
 1664 int fuse_fs_release(
struct fuse_fs *fs,  
const char *path,
 
 1668         if (fs->op.release) {
 
 1670                         fuse_log(FUSE_LOG_DEBUG, 
"release%s[%llu] flags: 0x%x\n",
 
 1671                                 fi->
flush ? 
"+flush" : 
"",
 
 1672                                 (
unsigned long long) fi->
fh, fi->
flags);
 
 1674                 return fs->op.release(path, fi);
 
 1680 int fuse_fs_opendir(
struct fuse_fs *fs, 
const char *path,
 
 1684         if (fs->op.opendir) {
 
 1688                         fuse_log(FUSE_LOG_DEBUG, 
"opendir flags: 0x%x %s\n", fi->
flags,
 
 1691                 err = fs->op.opendir(path, fi);
 
 1693                 if (fs->debug && !err)
 
 1694                         fuse_log(FUSE_LOG_DEBUG, 
"   opendir[%llu] flags: 0x%x %s\n",
 
 1695                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1703 int fuse_fs_open(
struct fuse_fs *fs, 
const char *path,
 
 1711                         fuse_log(FUSE_LOG_DEBUG, 
"open flags: 0x%x %s\n", fi->
flags,
 
 1714                 err = fs->op.open(path, fi);
 
 1716                 if (fs->debug && !err)
 
 1717                         fuse_log(FUSE_LOG_DEBUG, 
"   open[%llu] flags: 0x%x %s\n",
 
 1718                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1726 static void fuse_free_buf(
struct fuse_bufvec *buf)
 
 1731                 for (i = 0; i < buf->
count; i++)
 
 1738 int fuse_fs_read_buf(
struct fuse_fs *fs, 
const char *path,
 
 1739                      struct fuse_bufvec **bufp, 
size_t size, off_t off,
 
 1743         if (fs->op.read || fs->op.read_buf) {
 
 1748                                 "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1749                                 (
unsigned long long) fi->
fh,
 
 1750                                 size, (
unsigned long long) off, fi->
flags);
 
 1752                 if (fs->op.read_buf) {
 
 1753                         res = fs->op.read_buf(path, bufp, size, off, fi);
 
 1767                         *
buf = FUSE_BUFVEC_INIT(size);
 
 1771                         res = fs->op.read(path, mem, size, 
off, fi);
 
 1776                 if (fs->debug && res >= 0)
 
 1777                         fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %zu bytes from %llu\n",
 
 1778                                 (
unsigned long long) fi->
fh,
 
 1780                                 (
unsigned long long) 
off);
 
 1782                         fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1793 int fuse_fs_read(
struct fuse_fs *fs, 
const char *path, 
char *mem, 
size_t size,
 
 1797         if (fs->op.read || fs->op.read_buf) {
 
 1802                                 "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1803                                 (
unsigned long long) fi->
fh,
 
 1804                                 size, (
unsigned long long) 
off, fi->
flags);
 
 1806                 if (fs->op.read_buf) {
 
 1809                         res = fs->op.read_buf(path, &
buf, size, 
off, fi);
 
 1818                         res = fs->op.read(path, mem, size, 
off, fi);
 
 1821                 if (fs->debug && res >= 0)
 
 1822                         fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %u bytes from %llu\n",
 
 1823                                 (
unsigned long long) fi->
fh,
 
 1825                                 (
unsigned long long) 
off);
 
 1826                 if (res >= 0 && res > (
int) size)
 
 1827                         fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1835 int fuse_fs_write_buf(
struct fuse_fs *fs, 
const char *path,
 
 1840         if (fs->op.write_buf || fs->op.write) {
 
 1844                 assert(
buf->idx == 0 && 
buf->off == 0);
 
 1847                                 "write%s[%llu] %zu bytes to %llu flags: 0x%x\n",
 
 1849                                 (
unsigned long long) fi->
fh,
 
 1851                                 (
unsigned long long) 
off,
 
 1854                 if (fs->op.write_buf) {
 
 1855                         res = fs->op.write_buf(path, 
buf, 
off, fi);
 
 1861                         if (
buf->count == 1 &&
 
 1863                                 flatbuf = &
buf->buf[0];
 
 1876                                 flatbuf = &tmp.
buf[0];
 
 1879                         res = fs->op.write(path, flatbuf->
mem, flatbuf->
size,
 
 1885                 if (fs->debug && res >= 0)
 
 1886                         fuse_log(FUSE_LOG_DEBUG, 
"   write%s[%llu] %u bytes to %llu\n",
 
 1888                                 (
unsigned long long) fi->
fh, res,
 
 1889                                 (
unsigned long long) 
off);
 
 1890                 if (res > (
int) size)
 
 1891                         fuse_log(FUSE_LOG_ERR, 
"fuse: wrote too many bytes\n");
 
 1899 int fuse_fs_write(
struct fuse_fs *fs, 
const char *path, 
const char *mem,
 
 1904         bufv.
buf[0].
mem = (
void *) mem;
 
 1906         return fuse_fs_write_buf(fs, path, &bufv, 
off, fi);
 
 1909 int fuse_fs_fsync(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1915                         fuse_log(FUSE_LOG_DEBUG, 
"fsync[%llu] datasync: %i\n",
 
 1916                                 (
unsigned long long) fi->
fh, datasync);
 
 1918                 return fs->op.fsync(path, datasync, fi);
 
 1924 int fuse_fs_fsyncdir(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1928         if (fs->op.fsyncdir) {
 
 1930                         fuse_log(FUSE_LOG_DEBUG, 
"fsyncdir[%llu] datasync: %i\n",
 
 1931                                 (
unsigned long long) fi->
fh, datasync);
 
 1933                 return fs->op.fsyncdir(path, datasync, fi);
 
 1939 int fuse_fs_flush(
struct fuse_fs *fs, 
const char *path,
 
 1945                         fuse_log(FUSE_LOG_DEBUG, 
"flush[%llu]\n",
 
 1946                                 (
unsigned long long) fi->
fh);
 
 1948                 return fs->op.flush(path, fi);
 
 1954 int fuse_fs_statfs(
struct fuse_fs *fs, 
const char *path, 
struct statvfs *
buf)
 
 1957         if (fs->op.statfs) {
 
 1959                         fuse_log(FUSE_LOG_DEBUG, 
"statfs %s\n", path);
 
 1961                 return fs->op.statfs(path, 
buf);
 
 1963                 buf->f_namemax = 255;
 
 1969 int fuse_fs_releasedir(
struct fuse_fs *fs, 
const char *path,
 
 1973         if (fs->op.releasedir) {
 
 1975                         fuse_log(FUSE_LOG_DEBUG, 
"releasedir[%llu] flags: 0x%x\n",
 
 1976                                 (
unsigned long long) fi->
fh, fi->
flags);
 
 1978                 return fs->op.releasedir(path, fi);
 
 1984 int fuse_fs_readdir(
struct fuse_fs *fs, 
const char *path, 
void *
buf,
 
 1990         if (fs->op.readdir) {
 
 1992                         fuse_log(FUSE_LOG_DEBUG, 
"readdir%s[%llu] from %llu\n",
 
 1994                                 (
unsigned long long) fi->
fh,
 
 1995                                 (
unsigned long long) 
off);
 
 1998                 return fs->op.readdir(path, 
buf, filler, 
off, fi, flags);
 
 2004 int fuse_fs_create(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2008         if (fs->op.create) {
 
 2013                                 "create flags: 0x%x %s 0%o umask=0%03o\n",
 
 2014                                 fi->
flags, path, mode,
 
 2017                 err = fs->op.create(path, mode, fi);
 
 2019                 if (fs->debug && !err)
 
 2020                         fuse_log(FUSE_LOG_DEBUG, 
"   create[%llu] flags: 0x%x %s\n",
 
 2021                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 2029 int fuse_fs_lock(
struct fuse_fs *fs, 
const char *path,
 
 2035                         fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s %s start: %llu len: %llu pid: %llu\n",
 
 2036                                 (
unsigned long long) fi->
fh,
 
 2037                                 (cmd == F_GETLK ? 
"F_GETLK" :
 
 2038                                  (cmd == F_SETLK ? 
"F_SETLK" :
 
 2039                                   (cmd == F_SETLKW ? 
"F_SETLKW" : 
"???"))),
 
 2040                                 (lock->l_type == F_RDLCK ? 
"F_RDLCK" :
 
 2041                                  (lock->l_type == F_WRLCK ? 
"F_WRLCK" :
 
 2042                                   (lock->l_type == F_UNLCK ? 
"F_UNLCK" :
 
 2044                                 (
unsigned long long) lock->l_start,
 
 2045                                 (
unsigned long long) lock->l_len,
 
 2046                                 (
unsigned long long) lock->l_pid);
 
 2048                 return fs->op.lock(path, fi, cmd, lock);
 
 2054 int fuse_fs_flock(
struct fuse_fs *fs, 
const char *path,
 
 2060                         int xop = op & ~LOCK_NB;
 
 2062                         fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s%s\n",
 
 2063                                 (
unsigned long long) fi->
fh,
 
 2064                                 xop == LOCK_SH ? 
"LOCK_SH" :
 
 2065                                 (xop == LOCK_EX ? 
"LOCK_EX" :
 
 2066                                  (xop == LOCK_UN ? 
"LOCK_UN" : 
"???")),
 
 2067                                 (op & LOCK_NB) ? 
"|LOCK_NB" : 
"");
 
 2069                 return fs->op.flock(path, fi, op);
 
 2075 int fuse_fs_chown(
struct fuse_fs *fs, 
const char *path, uid_t uid,
 
 2082                         fuse_log(FUSE_LOG_DEBUG, 
"chown[%s] %s %lu %lu\n",
 
 2083                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2084                                 path, (
unsigned long) uid, (
unsigned long) gid);
 
 2086                 return fs->op.chown(path, uid, gid, fi);
 
 2092 int fuse_fs_truncate(
struct fuse_fs *fs, 
const char *path, off_t size,
 
 2096         if (fs->op.truncate) {
 
 2099                         fuse_log(FUSE_LOG_DEBUG, 
"truncate[%s] %llu\n",
 
 2100                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2101                                 (
unsigned long long) size);
 
 2103                 return fs->op.truncate(path, size, fi);
 
 2109 int fuse_fs_utimens(
struct fuse_fs *fs, 
const char *path,
 
 2113         if (fs->op.utimens) {
 
 2116                         fuse_log(FUSE_LOG_DEBUG, 
"utimens[%s] %s %li.%09lu %li.%09lu\n",
 
 2117                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2118                                 path, tv[0].tv_sec, tv[0].tv_nsec,
 
 2119                                 tv[1].tv_sec, tv[1].tv_nsec);
 
 2121                 return fs->op.utimens(path, tv, fi);
 
 2127 int fuse_fs_access(
struct fuse_fs *fs, 
const char *path, 
int mask)
 
 2130         if (fs->op.access) {
 
 2132                         fuse_log(FUSE_LOG_DEBUG, 
"access %s 0%o\n", path, mask);
 
 2134                 return fs->op.access(path, mask);
 
 2140 int fuse_fs_readlink(
struct fuse_fs *fs, 
const char *path, 
char *
buf,
 
 2144         if (fs->op.readlink) {
 
 2146                         fuse_log(FUSE_LOG_DEBUG, 
"readlink %s %lu\n", path,
 
 2147                                 (
unsigned long) len);
 
 2149                 return fs->op.readlink(path, 
buf, len);
 
 2155 int fuse_fs_mknod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2161                         fuse_log(FUSE_LOG_DEBUG, 
"mknod %s 0%o 0x%llx umask=0%03o\n",
 
 2162                                 path, mode, (
unsigned long long) rdev,
 
 2165                 return fs->op.mknod(path, mode, rdev);
 
 2171 int fuse_fs_mkdir(
struct fuse_fs *fs, 
const char *path, mode_t mode)
 
 2176                         fuse_log(FUSE_LOG_DEBUG, 
"mkdir %s 0%o umask=0%03o\n",
 
 2179                 return fs->op.mkdir(path, mode);
 
 2185 int fuse_fs_setxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2186                      const char *value, 
size_t size, 
int flags)
 
 2189         if (fs->op.setxattr) {
 
 2191                         fuse_log(FUSE_LOG_DEBUG, 
"setxattr %s %s %lu 0x%x\n",
 
 2192                                 path, name, (
unsigned long) size, flags);
 
 2194                 return fs->op.setxattr(path, name, value, size, flags);
 
 2200 int fuse_fs_getxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2201                      char *value, 
size_t size)
 
 2204         if (fs->op.getxattr) {
 
 2206                         fuse_log(FUSE_LOG_DEBUG, 
"getxattr %s %s %lu\n",
 
 2207                                 path, name, (
unsigned long) size);
 
 2209                 return fs->op.getxattr(path, name, value, size);
 
 2215 int fuse_fs_listxattr(
struct fuse_fs *fs, 
const char *path, 
char *list,
 
 2219         if (fs->op.listxattr) {
 
 2221                         fuse_log(FUSE_LOG_DEBUG, 
"listxattr %s %lu\n",
 
 2222                                 path, (
unsigned long) size);
 
 2224                 return fs->op.listxattr(path, list, size);
 
 2230 int fuse_fs_bmap(
struct fuse_fs *fs, 
const char *path, 
size_t blocksize,
 
 2236                         fuse_log(FUSE_LOG_DEBUG, 
"bmap %s blocksize: %lu index: %llu\n",
 
 2237                                 path, (
unsigned long) blocksize,
 
 2238                                 (
unsigned long long) *
idx);
 
 2240                 return fs->op.bmap(path, blocksize, 
idx);
 
 2246 int fuse_fs_removexattr(
struct fuse_fs *fs, 
const char *path, 
const char *name)
 
 2249         if (fs->op.removexattr) {
 
 2251                         fuse_log(FUSE_LOG_DEBUG, 
"removexattr %s %s\n", path, name);
 
 2253                 return fs->op.removexattr(path, name);
 
 2259 int fuse_fs_ioctl(
struct fuse_fs *fs, 
const char *path, 
unsigned int cmd,
 
 2266                         fuse_log(FUSE_LOG_DEBUG, 
"ioctl[%llu] 0x%x flags: 0x%x\n",
 
 2267                                 (
unsigned long long) fi->
fh, cmd, flags);
 
 2269                 return fs->op.ioctl(path, cmd, arg, fi, flags, data);
 
 2274 int fuse_fs_poll(
struct fuse_fs *fs, 
const char *path,
 
 2283                         fuse_log(FUSE_LOG_DEBUG, 
"poll[%llu] ph: %p, events 0x%x\n",
 
 2284                                 (
unsigned long long) fi->
fh, ph,
 
 2287                 res = fs->op.poll(path, fi, ph, reventsp);
 
 2289                 if (fs->debug && !res)
 
 2290                         fuse_log(FUSE_LOG_DEBUG, 
"   poll[%llu] revents: 0x%x\n",
 
 2291                                 (
unsigned long long) fi->
fh, *reventsp);
 
 2298 int fuse_fs_fallocate(
struct fuse_fs *fs, 
const char *path, 
int mode,
 
 2302         if (fs->op.fallocate) {
 
 2304                         fuse_log(FUSE_LOG_DEBUG, 
"fallocate %s mode %x, offset: %llu, length: %llu\n",
 
 2307                                 (
unsigned long long) offset,
 
 2308                                 (
unsigned long long) length);
 
 2310                 return fs->op.fallocate(path, mode, offset, length, fi);
 
 2315 ssize_t fuse_fs_copy_file_range(
struct fuse_fs *fs, 
const char *path_in,
 
 2317                                 const char *path_out,
 
 2319                                 size_t len, 
int flags)
 
 2322         if (fs->op.copy_file_range) {
 
 2324                         fuse_log(FUSE_LOG_DEBUG, 
"copy_file_range from %s:%llu to " 
 2325                                         "%s:%llu, length: %llu\n",
 
 2327                                 (
unsigned long long) off_in,
 
 2329                                 (
unsigned long long) off_out,
 
 2330                                 (
unsigned long long) len);
 
 2332                 return fs->op.copy_file_range(path_in, fi_in, off_in, path_out,
 
 2333                                               fi_out, off_out, len, flags);
 
 2338 off_t fuse_fs_lseek(
struct fuse_fs *fs, 
const char *path, off_t 
off, 
int whence,
 
 2345                         fuse_log(FUSE_LOG_DEBUG, 
"lseek[%s] %llu %d\n",
 
 2346                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2347                                 (
unsigned long long) 
off, whence);
 
 2349                 return fs->op.lseek(path, 
off, whence, fi);
 
 2355 static int is_open(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 2359         pthread_mutex_lock(&f->lock);
 
 2360         node = lookup_node(f, dir, name);
 
 2361         if (node && node->open_count > 0)
 
 2363         pthread_mutex_unlock(&f->lock);
 
 2367 static char *hidden_name(
struct fuse *f, 
fuse_ino_t dir, 
const char *oldname,
 
 2368                          char *newname, 
size_t bufsize)
 
 2372         struct node *newnode;
 
 2378                 pthread_mutex_lock(&f->lock);
 
 2379                 node = lookup_node(f, dir, oldname);
 
 2381                         pthread_mutex_unlock(&f->lock);
 
 2386                         snprintf(newname, bufsize, 
".fuse_hidden%08x%08x",
 
 2387                                  (
unsigned int) node->nodeid, f->hidectr);
 
 2388                         newnode = lookup_node(f, dir, newname);
 
 2391                 res = try_get_path(f, dir, newname, &newpath, NULL, 
false);
 
 2392                 pthread_mutex_unlock(&f->lock);
 
 2396                 memset(&buf, 0, 
sizeof(buf));
 
 2397                 res = fuse_fs_getattr(f->fs, newpath, &buf, NULL);
 
 2402         } 
while(res == 0 && --failctr);
 
 2407 static int hide_node(
struct fuse *f, 
const char *oldpath,
 
 2414         newpath = hidden_name(f, dir, oldname, newname, 
sizeof(newname));
 
 2416                 err = fuse_fs_rename(f->fs, oldpath, newpath, 0);
 
 2418                         err = rename_node(f, dir, oldname, dir, newname, 1);
 
 2424 static int mtime_eq(
const struct stat *stbuf, 
const struct timespec *ts)
 
 2426         return stbuf->st_mtime == ts->tv_sec &&
 
 2427                 ST_MTIM_NSEC(stbuf) == ts->tv_nsec;
 
 2430 #ifndef CLOCK_MONOTONIC 
 2431 #define CLOCK_MONOTONIC CLOCK_REALTIME 
 2434 static void curr_time(
struct timespec *now)
 
 2436         static clockid_t clockid = CLOCK_MONOTONIC;
 
 2437         int res = clock_gettime(clockid, now);
 
 2438         if (res == -1 && errno == EINVAL) {
 
 2439                 clockid = CLOCK_REALTIME;
 
 2440                 res = clock_gettime(clockid, now);
 
 2443                 perror(
"fuse: clock_gettime");
 
 2448 static void update_stat(
struct node *node, 
const struct stat *stbuf)
 
 2450         if (node->cache_valid && (!mtime_eq(stbuf, &node->mtime) ||
 
 2451                                   stbuf->st_size != node->size))
 
 2452                 node->cache_valid = 0;
 
 2453         node->mtime.tv_sec = stbuf->st_mtime;
 
 2454         node->mtime.tv_nsec = ST_MTIM_NSEC(stbuf);
 
 2455         node->size = stbuf->st_size;
 
 2456         curr_time(&node->stat_updated);
 
 2459 static int do_lookup(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 2464         node = find_node(f, nodeid, name);
 
 2468         e->
ino = node->nodeid;
 
 2472         if (f->conf.auto_cache) {
 
 2473                 pthread_mutex_lock(&f->lock);
 
 2474                 update_stat(node, &e->
attr);
 
 2475                 pthread_mutex_unlock(&f->lock);
 
 2477         set_stat(f, e->
ino, &e->
attr);
 
 2481 static int lookup_path(
struct fuse *f, 
fuse_ino_t nodeid,
 
 2482                        const char *name, 
const char *path,
 
 2488         res = fuse_fs_getattr(f->fs, path, &e->
attr, fi);
 
 2490                 res = do_lookup(f, nodeid, name, e);
 
 2491                 if (res == 0 && f->conf.debug) {
 
 2492                         fuse_log(FUSE_LOG_DEBUG, 
"   NODEID: %llu\n",
 
 2493                                 (
unsigned long long) e->
ino);
 
 2499 static struct fuse_context_i *fuse_get_context_internal(
void)
 
 2501         return (
struct fuse_context_i *) pthread_getspecific(fuse_context_key);
 
 2504 static struct fuse_context_i *fuse_create_context(
struct fuse *f)
 
 2506         struct fuse_context_i *c = fuse_get_context_internal();
 
 2508                 c = (
struct fuse_context_i *)
 
 2509                         calloc(1, 
sizeof(
struct fuse_context_i));
 
 2515                         fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate thread specific data\n");
 
 2518                 pthread_setspecific(fuse_context_key, c);
 
 2520                 memset(c, 0, 
sizeof(*c));
 
 2527 static void fuse_freecontext(
void *data)
 
 2532 static int fuse_create_context_key(
void)
 
 2535         pthread_mutex_lock(&fuse_context_lock);
 
 2536         if (!fuse_context_ref) {
 
 2537                 err = pthread_key_create(&fuse_context_key, fuse_freecontext);
 
 2539                         fuse_log(FUSE_LOG_ERR, 
"fuse: failed to create thread specific key: %s\n",
 
 2541                         pthread_mutex_unlock(&fuse_context_lock);
 
 2546         pthread_mutex_unlock(&fuse_context_lock);
 
 2550 static void fuse_delete_context_key(
void)
 
 2552         pthread_mutex_lock(&fuse_context_lock);
 
 2554         if (!fuse_context_ref) {
 
 2555                 free(pthread_getspecific(fuse_context_key));
 
 2556                 pthread_key_delete(fuse_context_key);
 
 2558         pthread_mutex_unlock(&fuse_context_lock);
 
 2561 static struct fuse *req_fuse_prepare(
fuse_req_t req)
 
 2563         struct fuse_context_i *c = fuse_create_context(req_fuse(req));
 
 2566         c->ctx.uid = ctx->
uid;
 
 2567         c->ctx.gid = ctx->
gid;
 
 2568         c->ctx.pid = ctx->
pid;
 
 2569         c->ctx.umask = ctx->
umask;
 
 2573 static inline void reply_err(
fuse_req_t req, 
int err)
 
 2583                 struct fuse *f = req_fuse(req);
 
 2587                                 forget_node(f, e->
ino, 1);
 
 2590                 reply_err(req, err);
 
 2593 void fuse_fs_init(
struct fuse_fs *fs, 
struct fuse_conn_info *conn,
 
 2597         if (!fs->op.write_buf)
 
 2604                 fs->user_data = fs->op.init(conn, cfg);
 
 2607 static void fuse_lib_init(
void *data, 
struct fuse_conn_info *conn)
 
 2609         struct fuse *f = (
struct fuse *) data;
 
 2611         fuse_create_context(f);
 
 2614         fuse_fs_init(f->fs, conn, &f->conf);
 
 2617 void fuse_fs_destroy(
struct fuse_fs *fs)
 
 2621                 fs->op.destroy(fs->user_data);
 
 2624 static void fuse_lib_destroy(
void *data)
 
 2626         struct fuse *f = (
struct fuse *) data;
 
 2628         fuse_create_context(f);
 
 2629         fuse_fs_destroy(f->fs);
 
 2635         struct fuse *f = req_fuse_prepare(req);
 
 2639         struct node *dot = NULL;
 
 2641         if (name[0] == 
'.') {
 
 2642                 int len = strlen(name);
 
 2644                 if (len == 1 || (name[1] == 
'.' && len == 2)) {
 
 2645                         pthread_mutex_lock(&f->lock);
 
 2648                                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOT\n");
 
 2649                                 dot = get_node_nocheck(f, parent);
 
 2651                                         pthread_mutex_unlock(&f->lock);
 
 2652                                         reply_entry(req, &e, -ESTALE);
 
 2658                                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOTDOT\n");
 
 2659                                 parent = get_node(f, parent)->parent->nodeid;
 
 2661                         pthread_mutex_unlock(&f->lock);
 
 2666         err = get_path_name(f, parent, name, &path);
 
 2668                 struct fuse_intr_data d;
 
 2670                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP %s\n", path);
 
 2671                 fuse_prepare_interrupt(f, req, &d);
 
 2672                 err = lookup_path(f, parent, name, path, &e, NULL);
 
 2673                 if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
 
 2678                 fuse_finish_interrupt(f, req, &d);
 
 2679                 free_path(f, parent, path);
 
 2682                 pthread_mutex_lock(&f->lock);
 
 2684                 pthread_mutex_unlock(&f->lock);
 
 2686         reply_entry(req, &e, err);
 
 2689 static void do_forget(
struct fuse *f, 
fuse_ino_t ino, uint64_t nlookup)
 
 2692                 fuse_log(FUSE_LOG_DEBUG, 
"FORGET %llu/%llu\n", (
unsigned long long)ino,
 
 2693                         (
unsigned long long) nlookup);
 
 2694         forget_node(f, ino, nlookup);
 
 2699         do_forget(req_fuse(req), ino, nlookup);
 
 2703 static void fuse_lib_forget_multi(
fuse_req_t req, 
size_t count,
 
 2704                                   struct fuse_forget_data *forgets)
 
 2706         struct fuse *f = req_fuse(req);
 
 2709         for (i = 0; i < count; i++)
 
 2710                 do_forget(f, forgets[i].ino, forgets[i].nlookup);
 
 2719         struct fuse *f = req_fuse_prepare(req);
 
 2724         memset(&buf, 0, 
sizeof(buf));
 
 2727                 err = get_path_nullok(f, ino, &path);
 
 2729                 err = get_path(f, ino, &path);
 
 2731                 struct fuse_intr_data d;
 
 2732                 fuse_prepare_interrupt(f, req, &d);
 
 2733                 err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2734                 fuse_finish_interrupt(f, req, &d);
 
 2735                 free_path(f, ino, path);
 
 2740                 pthread_mutex_lock(&f->lock);
 
 2741                 node = get_node(f, ino);
 
 2742                 if (node->is_hidden && buf.st_nlink > 0)
 
 2744                 if (f->conf.auto_cache)
 
 2745                         update_stat(node, &buf);
 
 2746                 pthread_mutex_unlock(&f->lock);
 
 2747                 set_stat(f, ino, &buf);
 
 2750                 reply_err(req, err);
 
 2753 int fuse_fs_chmod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2760                         fuse_log(FUSE_LOG_DEBUG, 
"chmod[%s] %s %llo\n",
 
 2761                                 file_info_string(fi, buf, 
sizeof(buf)),
 
 2762                                 path, (
unsigned long long) mode);
 
 2764                 return fs->op.chmod(path, mode, fi);
 
 2773         struct fuse *f = req_fuse_prepare(req);
 
 2778         memset(&buf, 0, 
sizeof(buf));
 
 2780                 err = get_path_nullok(f, ino, &path);
 
 2782                 err = get_path(f, ino, &path);
 
 2784                 struct fuse_intr_data d;
 
 2785                 fuse_prepare_interrupt(f, req, &d);
 
 2787                 if (!err && (valid & FUSE_SET_ATTR_MODE))
 
 2788                         err = fuse_fs_chmod(f->fs, path, attr->st_mode, fi);
 
 2789                 if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) {
 
 2790                         uid_t uid = (valid & FUSE_SET_ATTR_UID) ?
 
 2791                                 attr->st_uid : (uid_t) -1;
 
 2792                         gid_t gid = (valid & FUSE_SET_ATTR_GID) ?
 
 2793                                 attr->st_gid : (gid_t) -1;
 
 2794                         err = fuse_fs_chown(f->fs, path, uid, gid, fi);
 
 2796                 if (!err && (valid & FUSE_SET_ATTR_SIZE)) {
 
 2797                         err = fuse_fs_truncate(f->fs, path,
 
 2800 #ifdef HAVE_UTIMENSAT 
 2802                     (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))) {
 
 2803                         struct timespec tv[2];
 
 2807                         tv[0].tv_nsec = UTIME_OMIT;
 
 2808                         tv[1].tv_nsec = UTIME_OMIT;
 
 2810                         if (valid & FUSE_SET_ATTR_ATIME_NOW)
 
 2811                                 tv[0].tv_nsec = UTIME_NOW;
 
 2812                         else if (valid & FUSE_SET_ATTR_ATIME)
 
 2813                                 tv[0] = attr->st_atim;
 
 2815                         if (valid & FUSE_SET_ATTR_MTIME_NOW)
 
 2816                                 tv[1].tv_nsec = UTIME_NOW;
 
 2817                         else if (valid & FUSE_SET_ATTR_MTIME)
 
 2818                                 tv[1] = attr->st_mtim;
 
 2820                         err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2824                     (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) ==
 
 2825                     (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) {
 
 2826                         struct timespec tv[2];
 
 2827                         tv[0].tv_sec = attr->st_atime;
 
 2828                         tv[0].tv_nsec = ST_ATIM_NSEC(attr);
 
 2829                         tv[1].tv_sec = attr->st_mtime;
 
 2830                         tv[1].tv_nsec = ST_MTIM_NSEC(attr);
 
 2831                         err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2834                         err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2836                 fuse_finish_interrupt(f, req, &d);
 
 2837                 free_path(f, ino, path);
 
 2840                 if (f->conf.auto_cache) {
 
 2841                         pthread_mutex_lock(&f->lock);
 
 2842                         update_stat(get_node(f, ino), &buf);
 
 2843                         pthread_mutex_unlock(&f->lock);
 
 2845                 set_stat(f, ino, &buf);
 
 2848                 reply_err(req, err);
 
 2853         struct fuse *f = req_fuse_prepare(req);
 
 2857         err = get_path(f, ino, &path);
 
 2859                 struct fuse_intr_data d;
 
 2861                 fuse_prepare_interrupt(f, req, &d);
 
 2862                 err = fuse_fs_access(f->fs, path, mask);
 
 2863                 fuse_finish_interrupt(f, req, &d);
 
 2864                 free_path(f, ino, path);
 
 2866         reply_err(req, err);
 
 2871         struct fuse *f = req_fuse_prepare(req);
 
 2872         char linkname[PATH_MAX + 1];
 
 2876         err = get_path(f, ino, &path);
 
 2878                 struct fuse_intr_data d;
 
 2879                 fuse_prepare_interrupt(f, req, &d);
 
 2880                 err = fuse_fs_readlink(f->fs, path, linkname, 
sizeof(linkname));
 
 2881                 fuse_finish_interrupt(f, req, &d);
 
 2882                 free_path(f, ino, path);
 
 2885                 linkname[PATH_MAX] = 
'\0';
 
 2888                 reply_err(req, err);
 
 2892                            mode_t mode, dev_t rdev)
 
 2894         struct fuse *f = req_fuse_prepare(req);
 
 2899         err = get_path_name(f, parent, name, &path);
 
 2901                 struct fuse_intr_data d;
 
 2903                 fuse_prepare_interrupt(f, req, &d);
 
 2905                 if (S_ISREG(mode)) {
 
 2908                         memset(&fi, 0, 
sizeof(fi));
 
 2909                         fi.
flags = O_CREAT | O_EXCL | O_WRONLY;
 
 2910                         err = fuse_fs_create(f->fs, path, mode, &fi);
 
 2912                                 err = lookup_path(f, parent, name, path, &e,
 
 2914                                 fuse_fs_release(f->fs, path, &fi);
 
 2917                 if (err == -ENOSYS) {
 
 2918                         err = fuse_fs_mknod(f->fs, path, mode, rdev);
 
 2920                                 err = lookup_path(f, parent, name, path, &e,
 
 2923                 fuse_finish_interrupt(f, req, &d);
 
 2924                 free_path(f, parent, path);
 
 2926         reply_entry(req, &e, err);
 
 2932         struct fuse *f = req_fuse_prepare(req);
 
 2937         err = get_path_name(f, parent, name, &path);
 
 2939                 struct fuse_intr_data d;
 
 2941                 fuse_prepare_interrupt(f, req, &d);
 
 2942                 err = fuse_fs_mkdir(f->fs, path, mode);
 
 2944                         err = lookup_path(f, parent, name, path, &e, NULL);
 
 2945                 fuse_finish_interrupt(f, req, &d);
 
 2946                 free_path(f, parent, path);
 
 2948         reply_entry(req, &e, err);
 
 2954         struct fuse *f = req_fuse_prepare(req);
 
 2959         err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 2961                 struct fuse_intr_data d;
 
 2963                 fuse_prepare_interrupt(f, req, &d);
 
 2964                 if (!f->conf.hard_remove && is_open(f, parent, name)) {
 
 2965                         err = hide_node(f, path, parent, name);
 
 2968                                 if (!is_open(f, parent, wnode->name)) {
 
 2972                                         if (try_get_path(f, wnode->nodeid, NULL, &unlinkpath, NULL, 
false) == 0) {
 
 2973                                                 err = fuse_fs_unlink(f->fs, unlinkpath);
 
 2975                                                         remove_node(f, parent, wnode->name);
 
 2981                         err = fuse_fs_unlink(f->fs, path);
 
 2983                                 remove_node(f, parent, name);
 
 2985                 fuse_finish_interrupt(f, req, &d);
 
 2986                 free_path_wrlock(f, parent, wnode, path);
 
 2988         reply_err(req, err);
 
 2993         struct fuse *f = req_fuse_prepare(req);
 
 2998         err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 3000                 struct fuse_intr_data d;
 
 3002                 fuse_prepare_interrupt(f, req, &d);
 
 3003                 err = fuse_fs_rmdir(f->fs, path);
 
 3004                 fuse_finish_interrupt(f, req, &d);
 
 3006                         remove_node(f, parent, name);
 
 3007                 free_path_wrlock(f, parent, wnode, path);
 
 3009         reply_err(req, err);
 
 3012 static void fuse_lib_symlink(
fuse_req_t req, 
const char *linkname,
 
 3015         struct fuse *f = req_fuse_prepare(req);
 
 3020         err = get_path_name(f, parent, name, &path);
 
 3022                 struct fuse_intr_data d;
 
 3024                 fuse_prepare_interrupt(f, req, &d);
 
 3025                 err = fuse_fs_symlink(f->fs, linkname, path);
 
 3027                         err = lookup_path(f, parent, name, path, &e, NULL);
 
 3028                 fuse_finish_interrupt(f, req, &d);
 
 3029                 free_path(f, parent, path);
 
 3031         reply_entry(req, &e, err);
 
 3036                             const char *newname, 
unsigned int flags)
 
 3038         struct fuse *f = req_fuse_prepare(req);
 
 3041         struct node *wnode1;
 
 3042         struct node *wnode2;
 
 3045         err = get_path2(f, olddir, oldname, newdir, newname,
 
 3046                         &oldpath, &newpath, &wnode1, &wnode2);
 
 3048                 struct fuse_intr_data d;
 
 3050                 fuse_prepare_interrupt(f, req, &d);
 
 3051                 if (!f->conf.hard_remove && !(flags & RENAME_EXCHANGE) &&
 
 3052                     is_open(f, newdir, newname))
 
 3053                         err = hide_node(f, newpath, newdir, newname);
 
 3055                         err = fuse_fs_rename(f->fs, oldpath, newpath, flags);
 
 3057                                 if (flags & RENAME_EXCHANGE) {
 
 3058                                         err = exchange_node(f, olddir, oldname,
 
 3061                                         err = rename_node(f, olddir, oldname,
 
 3062                                                           newdir, newname, 0);
 
 3066                 fuse_finish_interrupt(f, req, &d);
 
 3067                 free_path2(f, olddir, newdir, wnode1, wnode2, oldpath, newpath);
 
 3069         reply_err(req, err);
 
 3073                           const char *newname)
 
 3075         struct fuse *f = req_fuse_prepare(req);
 
 3081         err = get_path2(f, 
ino, NULL, newparent, newname,
 
 3082                         &oldpath, &newpath, NULL, NULL);
 
 3084                 struct fuse_intr_data d;
 
 3086                 fuse_prepare_interrupt(f, req, &d);
 
 3087                 err = fuse_fs_link(f->fs, oldpath, newpath);
 
 3089                         err = lookup_path(f, newparent, newname, newpath,
 
 3091                 fuse_finish_interrupt(f, req, &d);
 
 3092                 free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
 
 3094         reply_entry(req, &e, err);
 
 3097 static void fuse_do_release(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3101         int unlink_hidden = 0;
 
 3103         fuse_fs_release(f->fs, path, fi);
 
 3105         pthread_mutex_lock(&f->lock);
 
 3106         node = get_node(f, ino);
 
 3107         assert(node->open_count > 0);
 
 3109         if (node->is_hidden && !node->open_count) {
 
 3111                 node->is_hidden = 0;
 
 3113         pthread_mutex_unlock(&f->lock);
 
 3117                         fuse_fs_unlink(f->fs, path);
 
 3118                 } 
else if (f->conf.nullpath_ok) {
 
 3121                         if (get_path(f, ino, &unlinkpath) == 0)
 
 3122                                 fuse_fs_unlink(f->fs, unlinkpath);
 
 3124                         free_path(f, ino, unlinkpath);
 
 3130                             const char *name, mode_t mode,
 
 3133         struct fuse *f = req_fuse_prepare(req);
 
 3134         struct fuse_intr_data d;
 
 3139         err = get_path_name(f, parent, name, &path);
 
 3141                 fuse_prepare_interrupt(f, req, &d);
 
 3142                 err = fuse_fs_create(f->fs, path, mode, fi);
 
 3144                         err = lookup_path(f, parent, name, path, &e, fi);
 
 3146                                 fuse_fs_release(f->fs, path, fi);
 
 3147                         else if (!S_ISREG(e.
attr.st_mode)) {
 
 3149                                 fuse_fs_release(f->fs, path, fi);
 
 3150                                 forget_node(f, e.
ino, 1);
 
 3152                                 if (f->conf.direct_io)
 
 3154                                 if (f->conf.kernel_cache)
 
 3157                                     f->conf.parallel_direct_writes)
 
 3161                 fuse_finish_interrupt(f, req, &d);
 
 3164                 pthread_mutex_lock(&f->lock);
 
 3165                 get_node(f, e.
ino)->open_count++;
 
 3166                 pthread_mutex_unlock(&f->lock);
 
 3170                         fuse_do_release(f, e.
ino, path, fi);
 
 3171                         forget_node(f, e.
ino, 1);
 
 3174                 reply_err(req, err);
 
 3177         free_path(f, parent, path);
 
 3180 static double diff_timespec(
const struct timespec *t1,
 
 3181                             const struct timespec *t2)
 
 3183         return (t1->tv_sec - t2->tv_sec) +
 
 3184                 ((double) t1->tv_nsec - (
double) t2->tv_nsec) / 1000000000.0;
 
 3187 static void open_auto_cache(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3192         pthread_mutex_lock(&f->lock);
 
 3193         node = get_node(f, ino);
 
 3194         if (node->cache_valid) {
 
 3195                 struct timespec now;
 
 3198                 if (diff_timespec(&now, &node->stat_updated) >
 
 3199                     f->conf.ac_attr_timeout) {
 
 3202                         pthread_mutex_unlock(&f->lock);
 
 3203                         err = fuse_fs_getattr(f->fs, path, &stbuf, fi);
 
 3204                         pthread_mutex_lock(&f->lock);
 
 3206                                 update_stat(node, &stbuf);
 
 3208                                 node->cache_valid = 0;
 
 3211         if (node->cache_valid)
 
 3214         node->cache_valid = 1;
 
 3215         pthread_mutex_unlock(&f->lock);
 
 3221         struct fuse *f = req_fuse_prepare(req);
 
 3222         struct fuse_intr_data d;
 
 3226         err = get_path(f, ino, &path);
 
 3228                 fuse_prepare_interrupt(f, req, &d);
 
 3229                 err = fuse_fs_open(f->fs, path, fi);
 
 3231                         if (f->conf.direct_io)
 
 3233                         if (f->conf.kernel_cache)
 
 3236                         if (f->conf.auto_cache)
 
 3237                                 open_auto_cache(f, ino, path, fi);
 
 3239                         if (f->conf.no_rofd_flush &&
 
 3240                             (fi->
flags & O_ACCMODE) == O_RDONLY)
 
 3243                         if (fi->
direct_io && f->conf.parallel_direct_writes)
 
 3247                 fuse_finish_interrupt(f, req, &d);
 
 3250                 pthread_mutex_lock(&f->lock);
 
 3251                 get_node(f, ino)->open_count++;
 
 3252                 pthread_mutex_unlock(&f->lock);
 
 3256                         fuse_do_release(f, ino, path, fi);
 
 3259                 reply_err(req, err);
 
 3261         free_path(f, ino, path);
 
 3267         struct fuse *f = req_fuse_prepare(req);
 
 3272         res = get_path_nullok(f, ino, &path);
 
 3274                 struct fuse_intr_data d;
 
 3276                 fuse_prepare_interrupt(f, req, &d);
 
 3277                 res = fuse_fs_read_buf(f->fs, path, &buf, size, off, fi);
 
 3278                 fuse_finish_interrupt(f, req, &d);
 
 3279                 free_path(f, ino, path);
 
 3285                 reply_err(req, res);
 
 3294         struct fuse *f = req_fuse_prepare(req);
 
 3298         res = get_path_nullok(f, ino, &path);
 
 3300                 struct fuse_intr_data d;
 
 3302                 fuse_prepare_interrupt(f, req, &d);
 
 3303                 res = fuse_fs_write_buf(f->fs, path, buf, off, fi);
 
 3304                 fuse_finish_interrupt(f, req, &d);
 
 3305                 free_path(f, ino, path);
 
 3311                 reply_err(req, res);
 
 3317         struct fuse *f = req_fuse_prepare(req);
 
 3321         err = get_path_nullok(f, ino, &path);
 
 3323                 struct fuse_intr_data d;
 
 3325                 fuse_prepare_interrupt(f, req, &d);
 
 3326                 err = fuse_fs_fsync(f->fs, path, datasync, fi);
 
 3327                 fuse_finish_interrupt(f, req, &d);
 
 3328                 free_path(f, ino, path);
 
 3330         reply_err(req, err);
 
 3333 static struct fuse_dh *get_dirhandle(
const struct fuse_file_info *llfi,
 
 3336         struct fuse_dh *dh = (
struct fuse_dh *) (uintptr_t) llfi->
fh;
 
 3345         struct fuse *f = req_fuse_prepare(req);
 
 3346         struct fuse_intr_data d;
 
 3352         dh = (
struct fuse_dh *) malloc(
sizeof(
struct fuse_dh));
 
 3354                 reply_err(req, -ENOMEM);
 
 3357         memset(dh, 0, 
sizeof(
struct fuse_dh));
 
 3359         dh->contents = NULL;
 
 3364         pthread_mutex_init(&dh->lock, NULL);
 
 3366         llfi->
fh = (uintptr_t) dh;
 
 3368         memset(&fi, 0, 
sizeof(fi));
 
 3371         err = get_path(f, ino, &path);
 
 3373                 fuse_prepare_interrupt(f, req, &d);
 
 3374                 err = fuse_fs_opendir(f->fs, path, &fi);
 
 3375                 fuse_finish_interrupt(f, req, &d);
 
 3382                         fuse_fs_releasedir(f->fs, path, &fi);
 
 3383                         pthread_mutex_destroy(&dh->lock);
 
 3387                 reply_err(req, err);
 
 3388                 pthread_mutex_destroy(&dh->lock);
 
 3391         free_path(f, ino, path);
 
 3394 static int extend_contents(
struct fuse_dh *dh, 
unsigned minsize)
 
 3396         if (minsize > dh->size) {
 
 3398                 unsigned newsize = dh->size;
 
 3401                 while (newsize < minsize) {
 
 3402                         if (newsize >= 0x80000000)
 
 3403                                 newsize = 0xffffffff;
 
 3408                 newptr = (
char *) realloc(dh->contents, newsize);
 
 3410                         dh->error = -ENOMEM;
 
 3413                 dh->contents = newptr;
 
 3419 static int fuse_add_direntry_to_dh(
struct fuse_dh *dh, 
const char *name,
 
 3422         struct fuse_direntry *de;
 
 3424         de = malloc(
sizeof(
struct fuse_direntry));
 
 3426                 dh->error = -ENOMEM;
 
 3429         de->name = strdup(name);
 
 3431                 dh->error = -ENOMEM;
 
 3439         dh->last = &de->next;
 
 3450         pthread_mutex_lock(&f->lock);
 
 3451         node = lookup_node(f, parent, name);
 
 3454         pthread_mutex_unlock(&f->lock);
 
 3459 static int fill_dir(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3462         struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3473                 memset(&stbuf, 0, 
sizeof(stbuf));
 
 3474                 stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3477         if (!dh->fuse->conf.use_ino) {
 
 3478                 stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3479                 if (dh->fuse->conf.readdir_ino) {
 
 3480                         stbuf.st_ino = (ino_t)
 
 3481                                 lookup_nodeid(dh->fuse, dh->nodeid, name);
 
 3498                 if (extend_contents(dh, dh->needlen) == -1)
 
 3503                                           dh->needlen - dh->len, name,
 
 3505                 if (newlen > dh->needlen)
 
 3512                 if (fuse_add_direntry_to_dh(dh, name, &stbuf) == -1)
 
 3518 static int is_dot_or_dotdot(
const char *name)
 
 3520         return name[0] == 
'.' && (name[1] == 
'\0' ||
 
 3521                                   (name[1] == 
'.' && name[2] == 
'\0'));
 
 3524 static int fill_dir_plus(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3527         struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3532         struct fuse *f = dh->fuse;
 
 3543                 if (!is_dot_or_dotdot(name)) {
 
 3544                         res = do_lookup(f, dh->nodeid, name, &e);
 
 3551                 e.
attr.st_ino = FUSE_UNKNOWN_INO;
 
 3553                         e.
attr.st_mode = statp->st_mode;
 
 3554                         if (f->conf.use_ino)
 
 3555                                 e.
attr.st_ino = statp->st_ino;
 
 3557                 if (!f->conf.use_ino && f->conf.readdir_ino) {
 
 3558                         e.
attr.st_ino = (ino_t)
 
 3559                                 lookup_nodeid(f, dh->nodeid, name);
 
 3575                 if (extend_contents(dh, dh->needlen) == -1)
 
 3580                                                dh->needlen - dh->len, name,
 
 3582                 if (newlen > dh->needlen)
 
 3588                 if (fuse_add_direntry_to_dh(dh, name, &e.
attr) == -1)
 
 3595 static void free_direntries(
struct fuse_direntry *de)
 
 3598                 struct fuse_direntry *next = de->next;
 
 3606                         size_t size, off_t off, 
struct fuse_dh *dh,
 
 3613         if (f->fs->op.readdir)
 
 3614                 err = get_path_nullok(f, ino, &path);
 
 3616                 err = get_path(f, ino, &path);
 
 3618                 struct fuse_intr_data d;
 
 3622                         filler = fill_dir_plus;
 
 3624                 free_direntries(dh->first);
 
 3626                 dh->last = &dh->first;
 
 3632                 fuse_prepare_interrupt(f, req, &d);
 
 3633                 err = fuse_fs_readdir(f->fs, path, dh, filler, off, fi, flags);
 
 3634                 fuse_finish_interrupt(f, req, &d);
 
 3640                 free_path(f, ino, path);
 
 3645 static int readdir_fill_from_list(
fuse_req_t req, 
struct fuse_dh *dh,
 
 3649         struct fuse_direntry *de = dh->first;
 
 3653         if (extend_contents(dh, dh->needlen) == -1)
 
 3656         for (pos = 0; pos < off; pos++) {
 
 3663                 char *p = dh->contents + dh->len;
 
 3664                 unsigned rem = dh->needlen - dh->len;
 
 3678                                                     de->name, &de->stat, pos);
 
 3680                 newlen = dh->len + thislen;
 
 3681                 if (newlen > dh->needlen)
 
 3693         struct fuse *f = req_fuse_prepare(req);
 
 3695         struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3698         pthread_mutex_lock(&dh->lock);
 
 3705                 err = readdir_fill(f, req, ino, size, off, dh, &fi, flags);
 
 3707                         reply_err(req, err);
 
 3713                 err = readdir_fill_from_list(req, dh, off, flags);
 
 3715                         reply_err(req, err);
 
 3721         pthread_mutex_unlock(&dh->lock);
 
 3727         fuse_readdir_common(req, ino, size, off, llfi, 0);
 
 3739         struct fuse *f = req_fuse_prepare(req);
 
 3740         struct fuse_intr_data d;
 
 3742         struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3745         get_path_nullok(f, ino, &path);
 
 3747         fuse_prepare_interrupt(f, req, &d);
 
 3748         fuse_fs_releasedir(f->fs, path, &fi);
 
 3749         fuse_finish_interrupt(f, req, &d);
 
 3750         free_path(f, ino, path);
 
 3752         pthread_mutex_lock(&dh->lock);
 
 3753         pthread_mutex_unlock(&dh->lock);
 
 3754         pthread_mutex_destroy(&dh->lock);
 
 3755         free_direntries(dh->first);
 
 3764         struct fuse *f = req_fuse_prepare(req);
 
 3769         get_dirhandle(llfi, &fi);
 
 3771         err = get_path_nullok(f, ino, &path);
 
 3773                 struct fuse_intr_data d;
 
 3774                 fuse_prepare_interrupt(f, req, &d);
 
 3775                 err = fuse_fs_fsyncdir(f->fs, path, datasync, &fi);
 
 3776                 fuse_finish_interrupt(f, req, &d);
 
 3777                 free_path(f, ino, path);
 
 3779         reply_err(req, err);
 
 3784         struct fuse *f = req_fuse_prepare(req);
 
 3789         memset(&buf, 0, 
sizeof(buf));
 
 3791                 err = get_path(f, ino, &path);
 
 3794                 struct fuse_intr_data d;
 
 3795                 fuse_prepare_interrupt(f, req, &d);
 
 3796                 err = fuse_fs_statfs(f->fs, path ? path : 
"/", &buf);
 
 3797                 fuse_finish_interrupt(f, req, &d);
 
 3798                 free_path(f, ino, path);
 
 3804                 reply_err(req, err);
 
 3808                               const char *value, 
size_t size, 
int flags)
 
 3810         struct fuse *f = req_fuse_prepare(req);
 
 3814         err = get_path(f, ino, &path);
 
 3816                 struct fuse_intr_data d;
 
 3817                 fuse_prepare_interrupt(f, req, &d);
 
 3818                 err = fuse_fs_setxattr(f->fs, path, name, value, size, flags);
 
 3819                 fuse_finish_interrupt(f, req, &d);
 
 3820                 free_path(f, ino, path);
 
 3822         reply_err(req, err);
 
 3826                            const char *name, 
char *value, 
size_t size)
 
 3831         err = get_path(f, ino, &path);
 
 3833                 struct fuse_intr_data d;
 
 3834                 fuse_prepare_interrupt(f, req, &d);
 
 3835                 err = fuse_fs_getxattr(f->fs, path, name, value, size);
 
 3836                 fuse_finish_interrupt(f, req, &d);
 
 3837                 free_path(f, ino, path);
 
 3845         struct fuse *f = req_fuse_prepare(req);
 
 3849                 char *value = (
char *) malloc(size);
 
 3850                 if (value == NULL) {
 
 3851                         reply_err(req, -ENOMEM);
 
 3854                 res = common_getxattr(f, req, ino, name, value, size);
 
 3858                         reply_err(req, res);
 
 3861                 res = common_getxattr(f, req, ino, name, NULL, 0);
 
 3865                         reply_err(req, res);
 
 3870                             char *list, 
size_t size)
 
 3875         err = get_path(f, ino, &path);
 
 3877                 struct fuse_intr_data d;
 
 3878                 fuse_prepare_interrupt(f, req, &d);
 
 3879                 err = fuse_fs_listxattr(f->fs, path, list, size);
 
 3880                 fuse_finish_interrupt(f, req, &d);
 
 3881                 free_path(f, ino, path);
 
 3888         struct fuse *f = req_fuse_prepare(req);
 
 3892                 char *list = (
char *) malloc(size);
 
 3894                         reply_err(req, -ENOMEM);
 
 3897                 res = common_listxattr(f, req, ino, list, size);
 
 3901                         reply_err(req, res);
 
 3904                 res = common_listxattr(f, req, ino, NULL, 0);
 
 3908                         reply_err(req, res);
 
 3915         struct fuse *f = req_fuse_prepare(req);
 
 3919         err = get_path(f, ino, &path);
 
 3921                 struct fuse_intr_data d;
 
 3922                 fuse_prepare_interrupt(f, req, &d);
 
 3923                 err = fuse_fs_removexattr(f->fs, path, name);
 
 3924                 fuse_finish_interrupt(f, req, &d);
 
 3925                 free_path(f, ino, path);
 
 3927         reply_err(req, err);
 
 3930 static struct lock *locks_conflict(
struct node *node, 
const struct lock *lock)
 
 3934         for (l = node->locks; l; l = l->next)
 
 3935                 if (l->owner != lock->owner &&
 
 3936                     lock->start <= l->end && l->start <= lock->end &&
 
 3937                     (l->type == F_WRLCK || lock->type == F_WRLCK))
 
 3943 static void delete_lock(
struct lock **lockp)
 
 3945         struct lock *l = *lockp;
 
 3950 static void insert_lock(
struct lock **pos, 
struct lock *lock)
 
 3956 static int locks_insert(
struct node *node, 
struct lock *lock)
 
 3959         struct lock *newl1 = NULL;
 
 3960         struct lock *newl2 = NULL;
 
 3962         if (lock->type != F_UNLCK || lock->start != 0 ||
 
 3963             lock->end != OFFSET_MAX) {
 
 3964                 newl1 = malloc(
sizeof(
struct lock));
 
 3965                 newl2 = malloc(
sizeof(
struct lock));
 
 3967                 if (!newl1 || !newl2) {
 
 3974         for (lp = &node->locks; *lp;) {
 
 3975                 struct lock *l = *lp;
 
 3976                 if (l->owner != lock->owner)
 
 3979                 if (lock->type == l->type) {
 
 3980                         if (l->end < lock->start - 1)
 
 3982                         if (lock->end < l->start - 1)
 
 3984                         if (l->start <= lock->start && lock->end <= l->end)
 
 3986                         if (l->start < lock->start)
 
 3987                                 lock->start = l->start;
 
 3988                         if (lock->end < l->end)
 
 3992                         if (l->end < lock->start)
 
 3994                         if (lock->end < l->start)
 
 3996                         if (lock->start <= l->start && l->end <= lock->end)
 
 3998                         if (l->end <= lock->end) {
 
 3999                                 l->end = lock->start - 1;
 
 4002                         if (lock->start <= l->start) {
 
 4003                                 l->start = lock->end + 1;
 
 4007                         newl2->start = lock->end + 1;
 
 4008                         l->end = lock->start - 1;
 
 4009                         insert_lock(&l->next, newl2);
 
 4019         if (lock->type != F_UNLCK) {
 
 4021                 insert_lock(lp, newl1);
 
 4030 static void flock_to_lock(
struct flock *flock, 
struct lock *lock)
 
 4032         memset(lock, 0, 
sizeof(
struct lock));
 
 4033         lock->type = flock->l_type;
 
 4034         lock->start = flock->l_start;
 
 4036                 flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX;
 
 4037         lock->pid = flock->l_pid;
 
 4040 static void lock_to_flock(
struct lock *lock, 
struct flock *flock)
 
 4042         flock->l_type = lock->type;
 
 4043         flock->l_start = lock->start;
 
 4045                 (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1;
 
 4046         flock->l_pid = lock->pid;
 
 4052         struct fuse_intr_data d;
 
 4058         fuse_prepare_interrupt(f, req, &d);
 
 4059         memset(&lock, 0, 
sizeof(lock));
 
 4060         lock.l_type = F_UNLCK;
 
 4061         lock.l_whence = SEEK_SET;
 
 4062         err = fuse_fs_flush(f->fs, path, fi);
 
 4063         errlock = fuse_fs_lock(f->fs, path, fi, F_SETLK, &lock);
 
 4064         fuse_finish_interrupt(f, req, &d);
 
 4066         if (errlock != -ENOSYS) {
 
 4067                 flock_to_lock(&lock, &l);
 
 4069                 pthread_mutex_lock(&f->lock);
 
 4070                 locks_insert(get_node(f, ino), &l);
 
 4071                 pthread_mutex_unlock(&f->lock);
 
 4084         struct fuse *f = req_fuse_prepare(req);
 
 4085         struct fuse_intr_data d;
 
 4089         get_path_nullok(f, ino, &path);
 
 4091                 err = fuse_flush_common(f, req, ino, path, fi);
 
 4096         fuse_prepare_interrupt(f, req, &d);
 
 4097         fuse_do_release(f, ino, path, fi);
 
 4098         fuse_finish_interrupt(f, req, &d);
 
 4099         free_path(f, ino, path);
 
 4101         reply_err(req, err);
 
 4107         struct fuse *f = req_fuse_prepare(req);
 
 4111         get_path_nullok(f, ino, &path);
 
 4112         err = fuse_flush_common(f, req, ino, path, fi);
 
 4113         free_path(f, ino, path);
 
 4115         reply_err(req, err);
 
 4122         struct fuse *f = req_fuse_prepare(req);
 
 4126         err = get_path_nullok(f, ino, &path);
 
 4128                 struct fuse_intr_data d;
 
 4129                 fuse_prepare_interrupt(f, req, &d);
 
 4130                 err = fuse_fs_lock(f->fs, path, fi, cmd, lock);
 
 4131                 fuse_finish_interrupt(f, req, &d);
 
 4132                 free_path(f, ino, path);
 
 4142         struct lock *conflict;
 
 4143         struct fuse *f = req_fuse(req);
 
 4145         flock_to_lock(lock, &l);
 
 4147         pthread_mutex_lock(&f->lock);
 
 4148         conflict = locks_conflict(get_node(f, ino), &l);
 
 4150                 lock_to_flock(conflict, lock);
 
 4151         pthread_mutex_unlock(&f->lock);
 
 4153                 err = fuse_lock_common(req, ino, fi, lock, F_GETLK);
 
 4160                 reply_err(req, err);
 
 4167         int err = fuse_lock_common(req, ino, fi, lock,
 
 4168                                    sleep ? F_SETLKW : F_SETLK);
 
 4170                 struct fuse *f = req_fuse(req);
 
 4172                 flock_to_lock(lock, &l);
 
 4174                 pthread_mutex_lock(&f->lock);
 
 4175                 locks_insert(get_node(f, ino), &l);
 
 4176                 pthread_mutex_unlock(&f->lock);
 
 4178         reply_err(req, err);
 
 4184         struct fuse *f = req_fuse_prepare(req);
 
 4188         err = get_path_nullok(f, ino, &path);
 
 4190                 struct fuse_intr_data d;
 
 4191                 fuse_prepare_interrupt(f, req, &d);
 
 4192                 err = fuse_fs_flock(f->fs, path, fi, op);
 
 4193                 fuse_finish_interrupt(f, req, &d);
 
 4194                 free_path(f, ino, path);
 
 4196         reply_err(req, err);
 
 4202         struct fuse *f = req_fuse_prepare(req);
 
 4203         struct fuse_intr_data d;
 
 4207         err = get_path(f, ino, &path);
 
 4209                 fuse_prepare_interrupt(f, req, &d);
 
 4210                 err = fuse_fs_bmap(f->fs, path, blocksize, &idx);
 
 4211                 fuse_finish_interrupt(f, req, &d);
 
 4212                 free_path(f, ino, path);
 
 4217                 reply_err(req, err);
 
 4222                            unsigned int flags, 
const void *in_buf,
 
 4223                            size_t in_bufsz, 
size_t out_bufsz)
 
 4225         struct fuse *f = req_fuse_prepare(req);
 
 4226         struct fuse_intr_data d;
 
 4228         char *path, *out_buf = NULL;
 
 4232         if (
flags & FUSE_IOCTL_UNRESTRICTED)
 
 4235         if (
flags & FUSE_IOCTL_DIR)
 
 4236                 get_dirhandle(llfi, &fi);
 
 4242                 out_buf = malloc(out_bufsz);
 
 4247         assert(!in_bufsz || !out_bufsz || in_bufsz == out_bufsz);
 
 4248         if (out_buf && in_bufsz)
 
 4249                 memcpy(out_buf, in_buf, in_bufsz);
 
 4251         err = get_path_nullok(f, ino, &path);
 
 4255         fuse_prepare_interrupt(f, req, &d);
 
 4257         err = fuse_fs_ioctl(f->fs, path, cmd, arg, &fi, 
flags,
 
 4258                             out_buf ? out_buf : (
void *)in_buf);
 
 4260         fuse_finish_interrupt(f, req, &d);
 
 4261         free_path(f, ino, path);
 
 4268         reply_err(req, err);
 
 4276         struct fuse *f = req_fuse_prepare(req);
 
 4277         struct fuse_intr_data d;
 
 4280         unsigned revents = 0;
 
 4282         err = get_path_nullok(f, ino, &path);
 
 4284                 fuse_prepare_interrupt(f, req, &d);
 
 4285                 err = fuse_fs_poll(f->fs, path, fi, ph, &revents);
 
 4286                 fuse_finish_interrupt(f, req, &d);
 
 4287                 free_path(f, ino, path);
 
 4292                 reply_err(req, err);
 
 4298         struct fuse *f = req_fuse_prepare(req);
 
 4299         struct fuse_intr_data d;
 
 4303         err = get_path_nullok(f, ino, &path);
 
 4305                 fuse_prepare_interrupt(f, req, &d);
 
 4306                 err = fuse_fs_fallocate(f->fs, path, mode, offset, length, fi);
 
 4307                 fuse_finish_interrupt(f, req, &d);
 
 4308                 free_path(f, ino, path);
 
 4310         reply_err(req, err);
 
 4319         struct fuse *f = req_fuse_prepare(req);
 
 4320         struct fuse_intr_data d;
 
 4321         char *path_in, *path_out;
 
 4325         err = get_path_nullok(f, nodeid_in, &path_in);
 
 4327                 reply_err(req, err);
 
 4331         err = get_path_nullok(f, nodeid_out, &path_out);
 
 4333                 free_path(f, nodeid_in, path_in);
 
 4334                 reply_err(req, err);
 
 4338         fuse_prepare_interrupt(f, req, &d);
 
 4339         res = fuse_fs_copy_file_range(f->fs, path_in, fi_in, off_in, path_out,
 
 4340                                       fi_out, off_out, len, flags);
 
 4341         fuse_finish_interrupt(f, req, &d);
 
 4346                 reply_err(req, res);
 
 4348         free_path(f, nodeid_in, path_in);
 
 4349         free_path(f, nodeid_out, path_out);
 
 4355         struct fuse *f = req_fuse_prepare(req);
 
 4356         struct fuse_intr_data d;
 
 4361         err = get_path(f, ino, &path);
 
 4363                 reply_err(req, err);
 
 4367         fuse_prepare_interrupt(f, req, &d);
 
 4368         res = fuse_fs_lseek(f->fs, path, off, whence, fi);
 
 4369         fuse_finish_interrupt(f, req, &d);
 
 4370         free_path(f, ino, path);
 
 4374                 reply_err(req, res);
 
 4377 static int clean_delay(
struct fuse *f)
 
 4385         int max_sleep = 3600;
 
 4386         int sleep_time = f->conf.remember / 10;
 
 4388         if (sleep_time > max_sleep)
 
 4390         if (sleep_time < min_sleep)
 
 4397         struct node_lru *lnode;
 
 4398         struct list_head *curr, *next;
 
 4400         struct timespec now;
 
 4402         pthread_mutex_lock(&f->lock);
 
 4406         for (curr = f->lru_table.next; curr != &f->lru_table; curr = next) {
 
 4410                 lnode = list_entry(curr, 
struct node_lru, lru);
 
 4411                 node = &lnode->node;
 
 4413                 age = diff_timespec(&now, &lnode->forget_time);
 
 4414                 if (age <= f->conf.remember)
 
 4417                 assert(node->nlookup == 1);
 
 4420                 if (node->refctr > 1)
 
 4424                 unhash_name(f, node);
 
 4425                 unref_node(f, node);
 
 4427         pthread_mutex_unlock(&f->lock);
 
 4429         return clean_delay(f);
 
 4433         .
init = fuse_lib_init,
 
 4434         .destroy = fuse_lib_destroy,
 
 4435         .lookup = fuse_lib_lookup,
 
 4436         .forget = fuse_lib_forget,
 
 4437         .forget_multi = fuse_lib_forget_multi,
 
 4438         .getattr = fuse_lib_getattr,
 
 4439         .setattr = fuse_lib_setattr,
 
 4440         .access = fuse_lib_access,
 
 4441         .readlink = fuse_lib_readlink,
 
 4442         .mknod = fuse_lib_mknod,
 
 4443         .mkdir = fuse_lib_mkdir,
 
 4444         .unlink = fuse_lib_unlink,
 
 4445         .rmdir = fuse_lib_rmdir,
 
 4446         .symlink = fuse_lib_symlink,
 
 4447         .rename = fuse_lib_rename,
 
 4448         .link = fuse_lib_link,
 
 4449         .create = fuse_lib_create,
 
 4450         .open = fuse_lib_open,
 
 4451         .read = fuse_lib_read,
 
 4452         .write_buf = fuse_lib_write_buf,
 
 4453         .flush = fuse_lib_flush,
 
 4454         .release = fuse_lib_release,
 
 4455         .fsync = fuse_lib_fsync,
 
 4456         .opendir = fuse_lib_opendir,
 
 4457         .readdir = fuse_lib_readdir,
 
 4458         .readdirplus = fuse_lib_readdirplus,
 
 4459         .releasedir = fuse_lib_releasedir,
 
 4460         .fsyncdir = fuse_lib_fsyncdir,
 
 4461         .statfs = fuse_lib_statfs,
 
 4462         .setxattr = fuse_lib_setxattr,
 
 4463         .getxattr = fuse_lib_getxattr,
 
 4464         .listxattr = fuse_lib_listxattr,
 
 4465         .removexattr = fuse_lib_removexattr,
 
 4466         .getlk = fuse_lib_getlk,
 
 4467         .setlk = fuse_lib_setlk,
 
 4468         .flock = fuse_lib_flock,
 
 4469         .bmap = fuse_lib_bmap,
 
 4470         .ioctl = fuse_lib_ioctl,
 
 4471         .poll = fuse_lib_poll,
 
 4472         .fallocate = fuse_lib_fallocate,
 
 4473         .copy_file_range = fuse_lib_copy_file_range,
 
 4474         .lseek = fuse_lib_lseek,
 
 4477 int fuse_notify_poll(
struct fuse_pollhandle *ph)
 
 4487 static int fuse_session_loop_remember(
struct fuse *f)
 
 4489         struct fuse_session *se = f->se;
 
 4491         struct timespec now;
 
 4493         struct pollfd fds = {
 
 4502         next_clean = now.tv_sec;
 
 4507                 if (now.tv_sec < next_clean)
 
 4508                         timeout = next_clean - now.tv_sec;
 
 4512                 res = poll(&fds, 1, timeout * 1000);
 
 4518                 } 
else if (res > 0) {
 
 4519                         res = fuse_session_receive_buf_int(se, &fbuf, NULL);
 
 4526                         fuse_session_process_buf_int(se, &fbuf, NULL);
 
 4530                         next_clean = now.tv_sec + timeout;
 
 4536         return res < 0 ? -1 : 0;
 
 4545                 return fuse_session_loop_remember(f);
 
 4550 FUSE_SYMVER(
"fuse_loop_mt_312", 
"fuse_loop_mt@@FUSE_3.12")
 
 4565 int fuse_loop_mt_32(
struct fuse *f, 
struct fuse_loop_config_v1 *config_v1);
 
 4566 FUSE_SYMVER(
"fuse_loop_mt_32", 
"fuse_loop_mt@FUSE_3.2")
 
 4567 int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config_v1 *config_v1)
 
 4575         int res = fuse_loop_mt_312(f, config);
 
 4582 int fuse_loop_mt_31(
struct fuse *f, 
int clone_fd);
 
 4583 FUSE_SYMVER(
"fuse_loop_mt_31", 
"fuse_loop_mt@FUSE_3.0")
 
 4584 int fuse_loop_mt_31(struct fuse *f, 
int clone_fd)
 
 4594         err = fuse_loop_mt_312(f, config);
 
 4608         struct fuse_context_i *c = fuse_get_context_internal();
 
 4618         struct fuse_context_i *c = fuse_get_context_internal();
 
 4627         struct fuse_context_i *c = fuse_get_context_internal();
 
 4637         int err = lookup_path_in_cache(f, path, &ino);
 
 4645 #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } 
 4647 static const struct fuse_opt fuse_lib_opts[] = {
 
 4650         FUSE_LIB_OPT(
"debug",                 debug, 1),
 
 4651         FUSE_LIB_OPT(
"-d",                    debug, 1),
 
 4652         FUSE_LIB_OPT(
"kernel_cache",          kernel_cache, 1),
 
 4653         FUSE_LIB_OPT(
"auto_cache",            auto_cache, 1),
 
 4654         FUSE_LIB_OPT(
"noauto_cache",          auto_cache, 0),
 
 4655         FUSE_LIB_OPT(
"no_rofd_flush",         no_rofd_flush, 1),
 
 4656         FUSE_LIB_OPT(
"umask=",                set_mode, 1),
 
 4657         FUSE_LIB_OPT(
"umask=%o",              umask, 0),
 
 4658         FUSE_LIB_OPT(
"uid=",                  set_uid, 1),
 
 4659         FUSE_LIB_OPT(
"uid=%d",                uid, 0),
 
 4660         FUSE_LIB_OPT(
"gid=",                  set_gid, 1),
 
 4661         FUSE_LIB_OPT(
"gid=%d",                gid, 0),
 
 4662         FUSE_LIB_OPT(
"entry_timeout=%lf",     entry_timeout, 0),
 
 4663         FUSE_LIB_OPT(
"attr_timeout=%lf",      attr_timeout, 0),
 
 4664         FUSE_LIB_OPT(
"ac_attr_timeout=%lf",   ac_attr_timeout, 0),
 
 4665         FUSE_LIB_OPT(
"ac_attr_timeout=",      ac_attr_timeout_set, 1),
 
 4666         FUSE_LIB_OPT(
"negative_timeout=%lf",  negative_timeout, 0),
 
 4667         FUSE_LIB_OPT(
"noforget",              remember, -1),
 
 4668         FUSE_LIB_OPT(
"remember=%u",           remember, 0),
 
 4669         FUSE_LIB_OPT(
"modules=%s",            modules, 0),
 
 4670         FUSE_LIB_OPT(
"parallel_direct_write=%d", parallel_direct_writes, 0),
 
 4674 static int fuse_lib_opt_proc(
void *data, 
const char *arg, 
int key,
 
 4677         (void) arg; (void) outargs; (void) data; (void) key;
 
 4684 static const struct fuse_opt fuse_help_opts[] = {
 
 4685         FUSE_LIB_OPT(
"modules=%s", modules, 1),
 
 4690 static void print_module_help(
const char *name,
 
 4697         printf(
"\nOptions for %s module:\n", name);
 
 4707 "    -o kernel_cache        cache files in kernel\n" 
 4708 "    -o [no]auto_cache      enable caching based on modification times (off)\n" 
 4709 "    -o no_rofd_flush       disable flushing of read-only fd on close (off)\n" 
 4710 "    -o umask=M             set file permissions (octal)\n" 
 4711 "    -o uid=N               set file owner\n" 
 4712 "    -o gid=N               set file group\n" 
 4713 "    -o entry_timeout=T     cache timeout for names (1.0s)\n" 
 4714 "    -o negative_timeout=T  cache timeout for deleted names (0.0s)\n" 
 4715 "    -o attr_timeout=T      cache timeout for attributes (1.0s)\n" 
 4716 "    -o ac_attr_timeout=T   auto cache timeout for attributes (attr_timeout)\n" 
 4717 "    -o noforget            never forget cached inodes\n" 
 4718 "    -o remember=T          remember cached inodes for T seconds (0s)\n" 
 4719 "    -o modules=M1[:M2...]  names of modules to push onto filesystem stack\n");
 
 4726         print_module_help(
"subdir", &fuse_module_subdir_factory);
 
 4728         print_module_help(
"iconv", &fuse_module_iconv_factory);
 
 4735                            fuse_lib_opt_proc) == -1
 
 4744         for (module = conf.modules; module; module = next) {
 
 4746                 for (p = module; *p && *p != 
':'; p++);
 
 4747                 next = *p ? p + 1 : NULL;
 
 4750                 m = fuse_get_module(module);
 
 4752                         print_module_help(module, &m->factory);
 
 4758 static int fuse_init_intr_signal(
int signum, 
int *installed)
 
 4760         struct sigaction old_sa;
 
 4762         if (sigaction(signum, NULL, &old_sa) == -1) {
 
 4763                 perror(
"fuse: cannot get old signal handler");
 
 4767         if (old_sa.sa_handler == SIG_DFL) {
 
 4768                 struct sigaction sa;
 
 4770                 memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4771                 sa.sa_handler = fuse_intr_sighandler;
 
 4772                 sigemptyset(&sa.sa_mask);
 
 4774                 if (sigaction(signum, &sa, NULL) == -1) {
 
 4775                         perror(
"fuse: cannot set interrupt signal handler");
 
 4783 static void fuse_restore_intr_signal(
int signum)
 
 4785         struct sigaction sa;
 
 4787         memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4788         sa.sa_handler = SIG_DFL;
 
 4789         sigaction(signum, &sa, NULL);
 
 4793 static int fuse_push_module(
struct fuse *f, 
const char *module,
 
 4796         struct fuse_fs *fs[2] = { f->fs, NULL };
 
 4797         struct fuse_fs *newfs;
 
 4803         newfs = m->factory(args, fs);
 
 4818                 fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not not work\n");
 
 4822         fs = (
struct fuse_fs *) calloc(1, 
sizeof(
struct fuse_fs));
 
 4824                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse_fs object\n");
 
 4828         fs->user_data = user_data;
 
 4830                 memcpy(&fs->op, op, op_size);
 
 4834 static int node_table_init(
struct node_table *t)
 
 4836         t->size = NODE_TABLE_MIN_SIZE;
 
 4837         t->array = (
struct node **) calloc(1, 
sizeof(
struct node *) * t->size);
 
 4838         if (t->array == NULL) {
 
 4839                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 4848 static void *fuse_prune_nodes(
void *fuse)
 
 4850         struct fuse *f = fuse;
 
 4863                 return fuse_start_thread(&f->prune_thread, fuse_prune_nodes, f);
 
 4870         if (lru_enabled(f)) {
 
 4871                 pthread_mutex_lock(&f->lock);
 
 4872                 pthread_cancel(f->prune_thread);
 
 4873                 pthread_mutex_unlock(&f->lock);
 
 4874                 pthread_join(f->prune_thread, NULL);
 
 4879 FUSE_SYMVER(
"fuse_new_31", 
"fuse_new@@FUSE_3.1")
 
 4882                       size_t op_size, 
void *user_data)
 
 4889         f = (
struct fuse *) calloc(1, 
sizeof(
struct fuse));
 
 4891                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse object\n");
 
 4895         f->conf.entry_timeout = 1.0;
 
 4896         f->conf.attr_timeout = 1.0;
 
 4897         f->conf.negative_timeout = 0.0;
 
 4898         f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL;
 
 4902                            fuse_lib_opt_proc) == -1)
 
 4905         pthread_mutex_lock(&fuse_context_lock);
 
 4906         static int builtin_modules_registered = 0;
 
 4908         if (builtin_modules_registered == 0) {
 
 4910                 fuse_register_module(
"subdir", fuse_module_subdir_factory, NULL);
 
 4912                 fuse_register_module(
"iconv", fuse_module_iconv_factory, NULL);
 
 4914                 builtin_modules_registered= 1;
 
 4916         pthread_mutex_unlock(&fuse_context_lock);
 
 4918         if (fuse_create_context_key() == -1)
 
 4923                 goto out_delete_context_key;
 
 4933         f->pagesize = getpagesize();
 
 4934         init_list_head(&f->partial_slabs);
 
 4935         init_list_head(&f->full_slabs);
 
 4936         init_list_head(&f->lru_table);
 
 4938         if (f->conf.modules) {
 
 4942                 for (module = f->conf.modules; module; module = next) {
 
 4944                         for (p = module; *p && *p != 
':'; p++);
 
 4945                         next = *p ? p + 1 : NULL;
 
 4948                             fuse_push_module(f, module, args) == -1)
 
 4953         if (!f->conf.ac_attr_timeout_set)
 
 4954                 f->conf.ac_attr_timeout = f->conf.attr_timeout;
 
 4956 #if defined(__FreeBSD__) || defined(__NetBSD__) 
 4961         f->conf.readdir_ino = 1;
 
 4968         if (f->conf.debug) {
 
 4969                 fuse_log(FUSE_LOG_DEBUG, 
"nullpath_ok: %i\n", f->conf.nullpath_ok);
 
 4973         f->fs->debug = f->conf.debug;
 
 4976         if (node_table_init(&f->name_table) == -1)
 
 4977                 goto out_free_session;
 
 4979         if (node_table_init(&f->id_table) == -1)
 
 4980                 goto out_free_name_table;
 
 4982         pthread_mutex_init(&f->lock, NULL);
 
 4984         root = alloc_node(f);
 
 4986                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 4987                 goto out_free_id_table;
 
 4989         if (lru_enabled(f)) {
 
 4990                 struct node_lru *lnode = node_lru(root);
 
 4991                 init_list_head(&lnode->lru);
 
 4994         strcpy(root->inline_name, 
"/");
 
 4995         root->name = root->inline_name;
 
 4998             fuse_init_intr_signal(f->conf.intr_signal,
 
 4999                                   &f->intr_installed) == -1)
 
 5002         root->parent = NULL;
 
 5012         free(f->id_table.array);
 
 5013 out_free_name_table:
 
 5014         free(f->name_table.array);
 
 5019         free(f->conf.modules);
 
 5020 out_delete_context_key:
 
 5021         fuse_delete_context_key();
 
 5030                          size_t op_size, 
void *private_data);
 
 5031 FUSE_SYMVER(
"fuse_new_30", 
"fuse_new@FUSE_3.0")
 
 5032 struct fuse *fuse_new_30(struct 
fuse_args *args,
 
 5034                          size_t op_size, 
void *user_data)
 
 5038         memset(&conf, 0, 
sizeof(conf));
 
 5041                 FUSE_LIB_OPT(
"-h", show_help, 1),
 
 5042                 FUSE_LIB_OPT(
"--help", show_help, 1),
 
 5047                            fuse_lib_opt_proc) == -1)
 
 5061         if (f->conf.intr && f->intr_installed)
 
 5062                 fuse_restore_intr_signal(f->conf.intr_signal);
 
 5065                 fuse_create_context(f);
 
 5067                 for (i = 0; i < f->id_table.size; i++) {
 
 5070                         for (node = f->id_table.array[i]; node != NULL;
 
 5071                              node = node->id_next) {
 
 5072                                 if (node->is_hidden) {
 
 5074                                         if (try_get_path(f, node->nodeid, NULL, &path, NULL, 
false) == 0) {
 
 5075                                                 fuse_fs_unlink(f->fs, path);
 
 5082         for (i = 0; i < f->id_table.size; i++) {
 
 5086                 for (node = f->id_table.array[i]; node != NULL; node = next) {
 
 5087                         next = node->id_next;
 
 5092         assert(list_empty(&f->partial_slabs));
 
 5093         assert(list_empty(&f->full_slabs));
 
 5095         while (fuse_modules) {
 
 5096                 fuse_put_module(fuse_modules);
 
 5098         free(f->id_table.array);
 
 5099         free(f->name_table.array);
 
 5100         pthread_mutex_destroy(&f->lock);
 
 5103         free(f->conf.modules);
 
 5105         fuse_delete_context_key();
 
 5108 int fuse_mount(
struct fuse *f, 
const char *mountpoint) {
 
 5119         return FUSE_VERSION;
 
 5124         return PACKAGE_VERSION;
 
struct fuse_session * fuse_get_session(struct fuse *f)
int fuse_getgroups(int size, gid_t list[])
int fuse_mount(struct fuse *f, const char *mountpoint)
int fuse_interrupted(void)
void fuse_destroy(struct fuse *f)
int fuse_start_cleanup_thread(struct fuse *fuse)
int fuse_invalidate_path(struct fuse *f, const char *path)
struct fuse * fuse_new_31(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *user_data)
int fuse_loop(struct fuse *f)
struct fuse_fs * fuse_fs_new(const struct fuse_operations *op, size_t op_size, void *private_data)
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
void fuse_exit(struct fuse *f)
int fuse_clean_cache(struct fuse *fuse)
struct fuse_context * fuse_get_context(void)
void fuse_lib_help(struct fuse_args *args)
void fuse_unmount(struct fuse *f)
struct fuse_fs *(* fuse_module_factory_t)(struct fuse_args *args, struct fuse_fs *fs[])
void fuse_stop_cleanup_thread(struct fuse *fuse)
void fuse_loop_cfg_convert(struct fuse_loop_config *config, struct fuse_loop_config_v1 *v1_conf)
#define FUSE_CAP_SPLICE_READ
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
#define FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_POSIX_LOCKS
struct fuse_loop_config * fuse_loop_cfg_create(void)
void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config, unsigned int value)
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
void fuse_loop_cfg_destroy(struct fuse_loop_config *config)
const char * fuse_pkgversion(void)
#define FUSE_CAP_FLOCK_LOCKS
void fuse_log(enum fuse_log_level level, const char *fmt,...)
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
void fuse_session_exit(struct fuse_session *se)
int fuse_reply_poll(fuse_req_t req, unsigned revents)
int fuse_reply_err(fuse_req_t req, int err)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
struct fuse_req * fuse_req_t
size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct fuse_entry_param *e, off_t off)
int fuse_session_exited(struct fuse_session *se)
int fuse_req_interrupted(fuse_req_t req)
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
int fuse_reply_readlink(fuse_req_t req, const char *link)
int fuse_session_loop(struct fuse_session *se)
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
void fuse_session_unmount(struct fuse_session *se)
void fuse_reply_none(fuse_req_t req)
void fuse_lowlevel_help(void)
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
int fuse_reply_write(fuse_req_t req, size_t count)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
void * fuse_req_userdata(fuse_req_t req)
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
void fuse_session_reset(struct fuse_session *se)
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
int fuse_reply_lseek(fuse_req_t req, off_t off)
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
int fuse_reply_xattr(fuse_req_t req, size_t count)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_opt_free_args(struct fuse_args *args)
#define FUSE_OPT_KEY(templ, key)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_OPT_KEY_KEEP
#define FUSE_ARGS_INIT(argc, argv)
enum fuse_buf_flags flags
unsigned int parallel_direct_writes
void(* getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock)
void(* init)(void *userdata, struct fuse_conn_info *conn)
void(* setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock, int sleep)