18 #include "fuse_lowlevel.h" 
   20 #include "fuse_misc.h" 
   21 #include "fuse_kernel.h" 
   37 #include <sys/param.h> 
   43 #define FUSE_NODE_SLAB 1 
   49 #ifndef RENAME_EXCHANGE 
   50 #define RENAME_EXCHANGE         (1 << 1)         
   53 #define FUSE_DEFAULT_INTR_SIGNAL SIGUSR1 
   55 #define FUSE_UNKNOWN_INO 0xffffffff 
   56 #define OFFSET_MAX 0x7fffffffffffffffLL 
   58 #define NODE_TABLE_MIN_SIZE 8192 
   71 struct lock_queue_element {
 
   72         struct lock_queue_element *next;
 
   93 #define container_of(ptr, type, member) ({                              \ 
   94                         const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 
   95                         (type *)( (char *)__mptr - offsetof(type,member) );}) 
   97 #define list_entry(ptr, type, member)           \ 
   98         container_of(ptr, type, member) 
  101         struct list_head *next;
 
  102         struct list_head *prev;
 
  106         struct list_head list;  
 
  107         struct list_head freelist;
 
  112         struct fuse_session *se;
 
  113         struct node_table name_table;
 
  114         struct node_table id_table;
 
  115         struct list_head lru_table;
 
  117         unsigned int generation;
 
  118         unsigned int hidectr;
 
  119         pthread_mutex_t lock;
 
  123         struct lock_queue_element *lockq;
 
  125         struct list_head partial_slabs;
 
  126         struct list_head full_slabs;
 
  127         pthread_t prune_thread;
 
  140         struct node *name_next;
 
  141         struct node *id_next;
 
  143         unsigned int generation;
 
  149         struct timespec stat_updated;
 
  150         struct timespec mtime;
 
  153         unsigned int is_hidden : 1;
 
  154         unsigned int cache_valid : 1;
 
  156         char inline_name[32];
 
  159 #define TREELOCK_WRITE -1 
  160 #define TREELOCK_WAIT_OFFSET INT_MIN 
  164         struct list_head lru;
 
  165         struct timespec forget_time;
 
  168 struct fuse_direntry {
 
  171         struct fuse_direntry *next;
 
  175         pthread_mutex_t lock;
 
  179         struct fuse_direntry *first;
 
  180         struct fuse_direntry **last;
 
  190 struct fuse_context_i {
 
  201 static pthread_key_t fuse_context_key;
 
  202 static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER;
 
  203 static int fuse_context_ref;
 
  206 static int fuse_register_module(
const char *name,
 
  208                                 struct fusemod_so *so)
 
  214                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module\n");
 
  217         mod->name = strdup(name);
 
  219                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module name\n");
 
  223         mod->factory = factory;
 
  228         mod->next = fuse_modules;
 
  234 static void fuse_unregister_module(
struct fuse_module *m)
 
  237         for (mp = &fuse_modules; *mp; mp = &(*mp)->next) {
 
  247 static int fuse_load_so_module(
const char *module)
 
  251         struct fusemod_so *so;
 
  254         tmp = malloc(strlen(module) + 64);
 
  256                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
  259         sprintf(tmp, 
"libfusemod_%s.so", module);
 
  260         so = calloc(1, 
sizeof(
struct fusemod_so));
 
  262                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module so\n");
 
  266         so->handle = dlopen(tmp, RTLD_NOW);
 
  267         if (so->handle == NULL) {
 
  268                 fuse_log(FUSE_LOG_ERR, 
"fuse: dlopen(%s) failed: %s\n",
 
  273         sprintf(tmp, 
"fuse_module_%s_factory", module);
 
  275         if (factory == NULL) {
 
  276                 fuse_log(FUSE_LOG_ERR, 
"fuse: symbol <%s> not found in module: %s\n",
 
  280         ret = fuse_register_module(module, *factory, so);
 
  295 static struct fuse_module *fuse_find_module(
const char *module)
 
  298         for (m = fuse_modules; m; m = m->next) {
 
  299                 if (strcmp(module, m->name) == 0) {
 
  307 static struct fuse_module *fuse_get_module(
const char *module)
 
  311         pthread_mutex_lock(&fuse_context_lock);
 
  312         m = fuse_find_module(module);
 
  314                 int err = fuse_load_so_module(module);
 
  316                         m = fuse_find_module(module);
 
  318         pthread_mutex_unlock(&fuse_context_lock);
 
  324         pthread_mutex_lock(&fuse_context_lock);
 
  330         if (!m->ctr && m->so) {
 
  331                 struct fusemod_so *so = m->so;
 
  336                         for (mp = &fuse_modules; *mp;) {
 
  338                                         fuse_unregister_module(*mp);
 
  345         } 
else if (!m->ctr) {
 
  346                 fuse_unregister_module(m);
 
  348         pthread_mutex_unlock(&fuse_context_lock);
 
  351 static void init_list_head(
struct list_head *list)
 
  357 static int list_empty(
const struct list_head *head)
 
  359         return head->next == head;
 
  362 static void list_add(
struct list_head *
new, 
struct list_head *prev,
 
  363                      struct list_head *next)
 
  371 static inline void list_add_head(
struct list_head *
new, 
struct list_head *head)
 
  373         list_add(
new, head, head->next);
 
  376 static inline void list_add_tail(
struct list_head *
new, 
struct list_head *head)
 
  378         list_add(
new, head->prev, head);
 
  381 static inline void list_del(
struct list_head *entry)
 
  383         struct list_head *prev = entry->prev;
 
  384         struct list_head *next = entry->next;
 
  390 static inline int lru_enabled(
struct fuse *f)
 
  392         return f->conf.remember > 0;
 
  395 static struct node_lru *node_lru(
struct node *node)
 
  397         return (
struct node_lru *) node;
 
  400 static size_t get_node_size(
struct fuse *f)
 
  403                 return sizeof(
struct node_lru);
 
  405                 return sizeof(
struct node);
 
  408 #ifdef FUSE_NODE_SLAB 
  409 static struct node_slab *list_to_slab(
struct list_head *head)
 
  411         return (
struct node_slab *) head;
 
  414 static struct node_slab *node_to_slab(
struct fuse *f, 
struct node *node)
 
  416         return (
struct node_slab *) (((uintptr_t) node) & ~((uintptr_t) f->pagesize - 1));
 
  419 static int alloc_slab(
struct fuse *f)
 
  422         struct node_slab *slab;
 
  426         size_t node_size = get_node_size(f);
 
  428         mem = mmap(NULL, f->pagesize, PROT_READ | PROT_WRITE,
 
  429                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
  431         if (mem == MAP_FAILED)
 
  435         init_list_head(&slab->freelist);
 
  437         num = (f->pagesize - 
sizeof(
struct node_slab)) / node_size;
 
  439         start = (
char *) mem + f->pagesize - num * node_size;
 
  440         for (i = 0; i < num; i++) {
 
  443                 n = (
struct list_head *) (start + i * node_size);
 
  444                 list_add_tail(n, &slab->freelist);
 
  446         list_add_tail(&slab->list, &f->partial_slabs);
 
  451 static struct node *alloc_node(
struct fuse *f)
 
  453         struct node_slab *slab;
 
  454         struct list_head *node;
 
  456         if (list_empty(&f->partial_slabs)) {
 
  457                 int res = alloc_slab(f);
 
  461         slab = list_to_slab(f->partial_slabs.next);
 
  463         node = slab->freelist.next;
 
  465         if (list_empty(&slab->freelist)) {
 
  466                 list_del(&slab->list);
 
  467                 list_add_tail(&slab->list, &f->full_slabs);
 
  469         memset(node, 0, 
sizeof(
struct node));
 
  471         return (
struct node *) node;
 
  474 static void free_slab(
struct fuse *f, 
struct node_slab *slab)
 
  478         list_del(&slab->list);
 
  479         res = munmap(slab, f->pagesize);
 
  481                 fuse_log(FUSE_LOG_WARNING, 
"fuse warning: munmap(%p) failed\n",
 
  485 static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  487         struct node_slab *slab = node_to_slab(f, node);
 
  488         struct list_head *n = (
struct list_head *) node;
 
  492                 if (list_empty(&slab->freelist)) {
 
  493                         list_del(&slab->list);
 
  494                         list_add_tail(&slab->list, &f->partial_slabs);
 
  496                 list_add_head(n, &slab->freelist);
 
  502 static struct node *alloc_node(
struct fuse *f)
 
  504         return (
struct node *) calloc(1, get_node_size(f));
 
  507 static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  514 static size_t id_hash(
struct fuse *f, 
fuse_ino_t ino)
 
  516         uint64_t hash = ((uint32_t) ino * 2654435761U) % f->id_table.size;
 
  517         uint64_t oldhash = hash % (f->id_table.size / 2);
 
  519         if (oldhash >= f->id_table.split)
 
  525 static struct node *get_node_nocheck(
struct fuse *f, 
fuse_ino_t nodeid)
 
  527         size_t hash = id_hash(f, nodeid);
 
  530         for (node = f->id_table.array[hash]; node != NULL; node = node->id_next)
 
  531                 if (node->nodeid == nodeid)
 
  537 static struct node *get_node(
struct fuse *f, 
fuse_ino_t nodeid)
 
  539         struct node *node = get_node_nocheck(f, nodeid);
 
  541                 fuse_log(FUSE_LOG_ERR, 
"fuse internal error: node %llu not found\n",
 
  542                         (
unsigned long long) nodeid);
 
  548 static void curr_time(
struct timespec *now);
 
  549 static double diff_timespec(
const struct timespec *t1,
 
  550                            const struct timespec *t2);
 
  552 static void remove_node_lru(
struct node *node)
 
  554         struct node_lru *lnode = node_lru(node);
 
  555         list_del(&lnode->lru);
 
  556         init_list_head(&lnode->lru);
 
  559 static void set_forget_time(
struct fuse *f, 
struct node *node)
 
  561         struct node_lru *lnode = node_lru(node);
 
  563         list_del(&lnode->lru);
 
  564         list_add_tail(&lnode->lru, &f->lru_table);
 
  565         curr_time(&lnode->forget_time);
 
  568 static void free_node(
struct fuse *f, 
struct node *node)
 
  570         if (node->name != node->inline_name)
 
  572         free_node_mem(f, node);
 
  575 static void node_table_reduce(
struct node_table *t)
 
  577         size_t newsize = t->size / 2;
 
  580         if (newsize < NODE_TABLE_MIN_SIZE)
 
  583         newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  584         if (newarray != NULL)
 
  588         t->split = t->size / 2;
 
  591 static void remerge_id(
struct fuse *f)
 
  593         struct node_table *t = &f->id_table;
 
  597                 node_table_reduce(t);
 
  599         for (iter = 8; t->split > 0 && iter; iter--) {
 
  603                 upper = &t->array[t->split + t->size / 2];
 
  607                         for (nodep = &t->array[t->split]; *nodep;
 
  608                              nodep = &(*nodep)->id_next);
 
  617 static void unhash_id(
struct fuse *f, 
struct node *node)
 
  619         struct node **nodep = &f->id_table.array[id_hash(f, node->nodeid)];
 
  621         for (; *nodep != NULL; nodep = &(*nodep)->id_next)
 
  622                 if (*nodep == node) {
 
  623                         *nodep = node->id_next;
 
  626                         if(f->id_table.use < f->id_table.size / 4)
 
  632 static int node_table_resize(
struct node_table *t)
 
  634         size_t newsize = t->size * 2;
 
  637         newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  638         if (newarray == NULL)
 
  642         memset(t->array + t->size, 0, t->size * 
sizeof(
struct node *));
 
  649 static void rehash_id(
struct fuse *f)
 
  651         struct node_table *t = &f->id_table;
 
  656         if (t->split == t->size / 2)
 
  661         for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  662                 struct node *node = *nodep;
 
  663                 size_t newhash = id_hash(f, node->nodeid);
 
  665                 if (newhash != hash) {
 
  667                         *nodep = node->id_next;
 
  668                         node->id_next = t->array[newhash];
 
  669                         t->array[newhash] = node;
 
  671                         next = &node->id_next;
 
  674         if (t->split == t->size / 2)
 
  675                 node_table_resize(t);
 
  678 static void hash_id(
struct fuse *f, 
struct node *node)
 
  680         size_t hash = id_hash(f, node->nodeid);
 
  681         node->id_next = f->id_table.array[hash];
 
  682         f->id_table.array[hash] = node;
 
  685         if (f->id_table.use >= f->id_table.size / 2)
 
  689 static size_t name_hash(
struct fuse *f, 
fuse_ino_t parent,
 
  692         uint64_t hash = parent;
 
  695         for (; *name; name++)
 
  696                 hash = hash * 31 + (
unsigned char) *name;
 
  698         hash %= f->name_table.size;
 
  699         oldhash = hash % (f->name_table.size / 2);
 
  700         if (oldhash >= f->name_table.split)
 
  706 static void unref_node(
struct fuse *f, 
struct node *node);
 
  708 static void remerge_name(
struct fuse *f)
 
  710         struct node_table *t = &f->name_table;
 
  714                 node_table_reduce(t);
 
  716         for (iter = 8; t->split > 0 && iter; iter--) {
 
  720                 upper = &t->array[t->split + t->size / 2];
 
  724                         for (nodep = &t->array[t->split]; *nodep;
 
  725                              nodep = &(*nodep)->name_next);
 
  734 static void unhash_name(
struct fuse *f, 
struct node *node)
 
  737                 size_t hash = name_hash(f, node->parent->nodeid, node->name);
 
  738                 struct node **nodep = &f->name_table.array[hash];
 
  740                 for (; *nodep != NULL; nodep = &(*nodep)->name_next)
 
  741                         if (*nodep == node) {
 
  742                                 *nodep = node->name_next;
 
  743                                 node->name_next = NULL;
 
  744                                 unref_node(f, node->parent);
 
  745                                 if (node->name != node->inline_name)
 
  751                                 if (f->name_table.use < f->name_table.size / 4)
 
  756                         "fuse internal error: unable to unhash node: %llu\n",
 
  757                         (
unsigned long long) node->nodeid);
 
  762 static void rehash_name(
struct fuse *f)
 
  764         struct node_table *t = &f->name_table;
 
  769         if (t->split == t->size / 2)
 
  774         for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  775                 struct node *node = *nodep;
 
  776                 size_t newhash = name_hash(f, node->parent->nodeid, node->name);
 
  778                 if (newhash != hash) {
 
  780                         *nodep = node->name_next;
 
  781                         node->name_next = t->array[newhash];
 
  782                         t->array[newhash] = node;
 
  784                         next = &node->name_next;
 
  787         if (t->split == t->size / 2)
 
  788                 node_table_resize(t);
 
  791 static int hash_name(
struct fuse *f, 
struct node *node, 
fuse_ino_t parentid,
 
  794         size_t hash = name_hash(f, parentid, name);
 
  795         struct node *parent = get_node(f, parentid);
 
  796         if (strlen(name) < 
sizeof(node->inline_name)) {
 
  797                 strcpy(node->inline_name, name);
 
  798                 node->name = node->inline_name;
 
  800                 node->name = strdup(name);
 
  801                 if (node->name == NULL)
 
  806         node->parent = parent;
 
  807         node->name_next = f->name_table.array[hash];
 
  808         f->name_table.array[hash] = node;
 
  811         if (f->name_table.use >= f->name_table.size / 2)
 
  817 static void delete_node(
struct fuse *f, 
struct node *node)
 
  820                 fuse_log(FUSE_LOG_DEBUG, 
"DELETE: %llu\n",
 
  821                         (
unsigned long long) node->nodeid);
 
  823         assert(node->treelock == 0);
 
  824         unhash_name(f, node);
 
  826                 remove_node_lru(node);
 
  831 static void unref_node(
struct fuse *f, 
struct node *node)
 
  833         assert(node->refctr > 0);
 
  836                 delete_node(f, node);
 
  842                 f->ctr = (f->ctr + 1) & 0xffffffff;
 
  845         } 
while (f->ctr == 0 || f->ctr == FUSE_UNKNOWN_INO ||
 
  846                  get_node_nocheck(f, f->ctr) != NULL);
 
  850 static struct node *lookup_node(
struct fuse *f, 
fuse_ino_t parent,
 
  853         size_t hash = name_hash(f, parent, name);
 
  856         for (node = f->name_table.array[hash]; node != NULL; node = node->name_next)
 
  857                 if (node->parent->nodeid == parent &&
 
  858                     strcmp(node->name, name) == 0)
 
  864 static void inc_nlookup(
struct node *node)
 
  871 static struct node *find_node(
struct fuse *f, 
fuse_ino_t parent,
 
  876         pthread_mutex_lock(&f->lock);
 
  878                 node = get_node(f, parent);
 
  880                 node = lookup_node(f, parent, name);
 
  882                 node = alloc_node(f);
 
  886                 node->nodeid = next_id(f);
 
  887                 node->generation = f->generation;
 
  888                 if (f->conf.remember)
 
  891                 if (hash_name(f, node, parent, name) == -1) {
 
  897                 if (lru_enabled(f)) {
 
  898                         struct node_lru *lnode = node_lru(node);
 
  899                         init_list_head(&lnode->lru);
 
  901         } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
  902                 remove_node_lru(node);
 
  906         pthread_mutex_unlock(&f->lock);
 
  910 static int lookup_path_in_cache(
struct fuse *f,
 
  913         char *tmp = strdup(path);
 
  917         pthread_mutex_lock(&f->lock);
 
  922         char *path_element = strtok_r(tmp, 
"/", &save_ptr);
 
  923         while (path_element != NULL) {
 
  924                 struct node *node = lookup_node(f, ino, path_element);
 
  930                 path_element = strtok_r(NULL, 
"/", &save_ptr);
 
  932         pthread_mutex_unlock(&f->lock);
 
  940 static char *add_name(
char **buf, 
unsigned *bufsize, 
char *s, 
const char *name)
 
  942         size_t len = strlen(name);
 
  944         if (s - len <= *buf) {
 
  945                 unsigned pathlen = *bufsize - (s - *buf);
 
  946                 unsigned newbufsize = *bufsize;
 
  949                 while (newbufsize < pathlen + len + 1) {
 
  950                         if (newbufsize >= 0x80000000)
 
  951                                 newbufsize = 0xffffffff;
 
  956                 newbuf = realloc(*buf, newbufsize);
 
  961                 s = newbuf + newbufsize - pathlen;
 
  962                 memmove(s, newbuf + *bufsize - pathlen, pathlen);
 
  963                 *bufsize = newbufsize;
 
  966         memcpy(s, name, len);
 
  973 static void unlock_path(
struct fuse *f, 
fuse_ino_t nodeid, 
struct node *wnode,
 
  979                 assert(wnode->treelock == TREELOCK_WRITE);
 
  983         for (node = get_node(f, nodeid);
 
  984              node != end && node->nodeid != 
FUSE_ROOT_ID; node = node->parent) {
 
  985                 assert(node->treelock != 0);
 
  986                 assert(node->treelock != TREELOCK_WAIT_OFFSET);
 
  987                 assert(node->treelock != TREELOCK_WRITE);
 
  989                 if (node->treelock == TREELOCK_WAIT_OFFSET)
 
  994 static int try_get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
  995                         char **path, 
struct node **wnodep, 
bool need_lock)
 
  997         unsigned bufsize = 256;
 
 1001         struct node *wnode = NULL;
 
 1007         buf = malloc(bufsize);
 
 1011         s = buf + bufsize - 1;
 
 1015                 s = add_name(&buf, &bufsize, s, name);
 
 1023                 wnode = lookup_node(f, nodeid, name);
 
 1025                         if (wnode->treelock != 0) {
 
 1026                                 if (wnode->treelock > 0)
 
 1027                                         wnode->treelock += TREELOCK_WAIT_OFFSET;
 
 1031                         wnode->treelock = TREELOCK_WRITE;
 
 1035         for (node = get_node(f, nodeid); node->nodeid != 
FUSE_ROOT_ID;
 
 1036              node = node->parent) {
 
 1038                 if (node->name == NULL || node->parent == NULL)
 
 1042                 s = add_name(&buf, &bufsize, s, node->name);
 
 1048                         if (node->treelock < 0)
 
 1056                 memmove(buf, s, bufsize - (s - buf));
 
 1068                 unlock_path(f, nodeid, wnode, node);
 
 1076 static int try_get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1078                          char **path1, 
char **path2,
 
 1079                          struct node **wnode1, 
struct node **wnode2)
 
 1084         err = try_get_path(f, nodeid1, name1, path1, wnode1, 
true);
 
 1086                 err = try_get_path(f, nodeid2, name2, path2, wnode2, 
true);
 
 1088                         struct node *wn1 = wnode1 ? *wnode1 : NULL;
 
 1090                         unlock_path(f, nodeid1, wn1, NULL);
 
 1097 static void queue_element_wakeup(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1103                 if (get_node(f, qe->nodeid1)->treelock == 0)
 
 1104                         pthread_cond_signal(&qe->cond);
 
 1113                 err = try_get_path(f, qe->nodeid1, qe->name1, qe->path1,
 
 1116                 err = try_get_path2(f, qe->nodeid1, qe->name1, qe->nodeid2,
 
 1117                                     qe->name2, qe->path1, qe->path2, qe->wnode1,
 
 1126         pthread_cond_signal(&qe->cond);
 
 1129 static void wake_up_queued(
struct fuse *f)
 
 1131         struct lock_queue_element *qe;
 
 1133         for (qe = f->lockq; qe != NULL; qe = qe->next)
 
 1134                 queue_element_wakeup(f, qe);
 
 1137 static void debug_path(
struct fuse *f, 
const char *msg, 
fuse_ino_t nodeid,
 
 1138                        const char *name, 
bool wr)
 
 1140         if (f->conf.debug) {
 
 1141                 struct node *wnode = NULL;
 
 1144                         wnode = lookup_node(f, nodeid, name);
 
 1147                         fuse_log(FUSE_LOG_DEBUG, 
"%s %llu (w)\n",
 
 1148                                 msg, (
unsigned long long) wnode->nodeid);
 
 1150                         fuse_log(FUSE_LOG_DEBUG, 
"%s %llu\n",
 
 1151                                 msg, (
unsigned long long) nodeid);
 
 1156 static void queue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1158         struct lock_queue_element **qp;
 
 1161         pthread_cond_init(&qe->cond, NULL);
 
 1163         for (qp = &f->lockq; *qp != NULL; qp = &(*qp)->next);
 
 1167 static void dequeue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1169         struct lock_queue_element **qp;
 
 1171         pthread_cond_destroy(&qe->cond);
 
 1172         for (qp = &f->lockq; *qp != qe; qp = &(*qp)->next);
 
 1176 static int wait_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1181                 pthread_cond_wait(&qe->cond, &f->lock);
 
 1182         } 
while (!qe->done);
 
 1184         dequeue_path(f, qe);
 
 1189 static int get_path_common(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1190                            char **path, 
struct node **wnode)
 
 1194         pthread_mutex_lock(&f->lock);
 
 1195         err = try_get_path(f, nodeid, name, path, wnode, 
true);
 
 1196         if (err == -EAGAIN) {
 
 1197                 struct lock_queue_element qe = {
 
 1203                 debug_path(f, 
"QUEUE PATH", nodeid, name, !!wnode);
 
 1204                 err = wait_path(f, &qe);
 
 1205                 debug_path(f, 
"DEQUEUE PATH", nodeid, name, !!wnode);
 
 1207         pthread_mutex_unlock(&f->lock);
 
 1212 static int get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1214         return get_path_common(f, nodeid, NULL, path, NULL);
 
 1217 static int get_path_nullok(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1221         if (f->conf.nullpath_ok) {
 
 1224                 err = get_path_common(f, nodeid, NULL, path, NULL);
 
 1232 static int get_path_name(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1235         return get_path_common(f, nodeid, name, path, NULL);
 
 1238 static int get_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1239                            char **path, 
struct node **wnode)
 
 1241         return get_path_common(f, nodeid, name, path, wnode);
 
 1244 #if defined(__FreeBSD__) 
 1245 #define CHECK_DIR_LOOP 
 1248 #if defined(CHECK_DIR_LOOP) 
 1249 static int check_dir_loop(
struct fuse *f,
 
 1253         struct node *node, *node1, *node2;
 
 1256         node1 = lookup_node(f, nodeid1, name1);
 
 1257         id1 = node1 ? node1->nodeid : nodeid1;
 
 1259         node2 = lookup_node(f, nodeid2, name2);
 
 1260         id2 = node2 ? node2->nodeid : nodeid2;
 
 1262         for (node = get_node(f, id2); node->nodeid != 
FUSE_ROOT_ID;
 
 1263              node = node->parent) {
 
 1264                 if (node->name == NULL || node->parent == NULL)
 
 1267                 if (node->nodeid != id2 && node->nodeid == id1)
 
 1273                 for (node = get_node(f, id1); node->nodeid != 
FUSE_ROOT_ID;
 
 1274                      node = node->parent) {
 
 1275                         if (node->name == NULL || node->parent == NULL)
 
 1278                         if (node->nodeid != id1 && node->nodeid == id2)
 
 1287 static int get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1289                      char **path1, 
char **path2,
 
 1290                      struct node **wnode1, 
struct node **wnode2)
 
 1294         pthread_mutex_lock(&f->lock);
 
 1296 #if defined(CHECK_DIR_LOOP) 
 1300                 err = check_dir_loop(f, nodeid1, name1, nodeid2, name2);
 
 1306         err = try_get_path2(f, nodeid1, name1, nodeid2, name2,
 
 1307                             path1, path2, wnode1, wnode2);
 
 1308         if (err == -EAGAIN) {
 
 1309                 struct lock_queue_element qe = {
 
 1320                 debug_path(f, 
"QUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1321                 debug_path(f, 
"      PATH2", nodeid2, name2, !!wnode2);
 
 1322                 err = wait_path(f, &qe);
 
 1323                 debug_path(f, 
"DEQUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1324                 debug_path(f, 
"        PATH2", nodeid2, name2, !!wnode2);
 
 1327 #if defined(CHECK_DIR_LOOP) 
 1330         pthread_mutex_unlock(&f->lock);
 
 1335 static void free_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid,
 
 1336                              struct node *wnode, 
char *path)
 
 1338         pthread_mutex_lock(&f->lock);
 
 1339         unlock_path(f, nodeid, wnode, NULL);
 
 1342         pthread_mutex_unlock(&f->lock);
 
 1346 static void free_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char *path)
 
 1349                 free_path_wrlock(f, nodeid, NULL, path);
 
 1353                        struct node *wnode1, 
struct node *wnode2,
 
 1354                        char *path1, 
char *path2)
 
 1356         pthread_mutex_lock(&f->lock);
 
 1357         unlock_path(f, nodeid1, wnode1, NULL);
 
 1358         unlock_path(f, nodeid2, wnode2, NULL);
 
 1360         pthread_mutex_unlock(&f->lock);
 
 1365 static void forget_node(
struct fuse *f, 
fuse_ino_t nodeid, uint64_t nlookup)
 
 1370         pthread_mutex_lock(&f->lock);
 
 1371         node = get_node(f, nodeid);
 
 1377         while (node->nlookup == nlookup && node->treelock) {
 
 1378                 struct lock_queue_element qe = {
 
 1382                 debug_path(f, 
"QUEUE PATH (forget)", nodeid, NULL, 
false);
 
 1386                         pthread_cond_wait(&qe.cond, &f->lock);
 
 1387                 } 
while (node->nlookup == nlookup && node->treelock);
 
 1389                 dequeue_path(f, &qe);
 
 1390                 debug_path(f, 
"DEQUEUE_PATH (forget)", nodeid, NULL, 
false);
 
 1393         assert(node->nlookup >= nlookup);
 
 1394         node->nlookup -= nlookup;
 
 1395         if (!node->nlookup) {
 
 1396                 unref_node(f, node);
 
 1397         } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
 1398                 set_forget_time(f, node);
 
 1400         pthread_mutex_unlock(&f->lock);
 
 1403 static void unlink_node(
struct fuse *f, 
struct node *node)
 
 1405         if (f->conf.remember) {
 
 1406                 assert(node->nlookup > 1);
 
 1409         unhash_name(f, node);
 
 1412 static void remove_node(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 1416         pthread_mutex_lock(&f->lock);
 
 1417         node = lookup_node(f, dir, name);
 
 1419                 unlink_node(f, node);
 
 1420         pthread_mutex_unlock(&f->lock);
 
 1423 static int rename_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1424                        fuse_ino_t newdir, 
const char *newname, 
int hide)
 
 1427         struct node *newnode;
 
 1430         pthread_mutex_lock(&f->lock);
 
 1431         node  = lookup_node(f, olddir, oldname);
 
 1432         newnode  = lookup_node(f, newdir, newname);
 
 1436         if (newnode != NULL) {
 
 1438                         fuse_log(FUSE_LOG_ERR, 
"fuse: hidden file got created during hiding\n");
 
 1442                 unlink_node(f, newnode);
 
 1445         unhash_name(f, node);
 
 1446         if (hash_name(f, node, newdir, newname) == -1) {
 
 1452                 node->is_hidden = 1;
 
 1455         pthread_mutex_unlock(&f->lock);
 
 1459 static int exchange_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1462         struct node *oldnode;
 
 1463         struct node *newnode;
 
 1466         pthread_mutex_lock(&f->lock);
 
 1467         oldnode  = lookup_node(f, olddir, oldname);
 
 1468         newnode  = lookup_node(f, newdir, newname);
 
 1471                 unhash_name(f, oldnode);
 
 1473                 unhash_name(f, newnode);
 
 1477                 if (hash_name(f, oldnode, newdir, newname) == -1)
 
 1481                 if (hash_name(f, newnode, olddir, oldname) == -1)
 
 1486         pthread_mutex_unlock(&f->lock);
 
 1490 static void set_stat(
struct fuse *f, 
fuse_ino_t nodeid, 
struct stat *stbuf)
 
 1492         if (!f->conf.use_ino)
 
 1493                 stbuf->st_ino = nodeid;
 
 1494         if (f->conf.set_mode)
 
 1495                 stbuf->st_mode = (stbuf->st_mode & S_IFMT) |
 
 1496                                  (0777 & ~f->conf.umask);
 
 1497         if (f->conf.set_uid)
 
 1498                 stbuf->st_uid = f->conf.uid;
 
 1499         if (f->conf.set_gid)
 
 1500                 stbuf->st_gid = f->conf.gid;
 
 1508 static void fuse_intr_sighandler(
int sig)
 
 1514 struct fuse_intr_data {
 
 1516         pthread_cond_t cond;
 
 1520 static void fuse_interrupt(
fuse_req_t req, 
void *d_)
 
 1522         struct fuse_intr_data *d = d_;
 
 1523         struct fuse *f = req_fuse(req);
 
 1525         if (d->id == pthread_self())
 
 1528         pthread_mutex_lock(&f->lock);
 
 1529         while (!d->finished) {
 
 1531                 struct timespec timeout;
 
 1533                 pthread_kill(d->id, f->conf.intr_signal);
 
 1534                 gettimeofday(&now, NULL);
 
 1535                 timeout.tv_sec = now.tv_sec + 1;
 
 1536                 timeout.tv_nsec = now.tv_usec * 1000;
 
 1537                 pthread_cond_timedwait(&d->cond, &f->lock, &timeout);
 
 1539         pthread_mutex_unlock(&f->lock);
 
 1542 static void fuse_do_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1543                                      struct fuse_intr_data *d)
 
 1545         pthread_mutex_lock(&f->lock);
 
 1547         pthread_cond_broadcast(&d->cond);
 
 1548         pthread_mutex_unlock(&f->lock);
 
 1550         pthread_cond_destroy(&d->cond);
 
 1553 static void fuse_do_prepare_interrupt(
fuse_req_t req, 
struct fuse_intr_data *d)
 
 1555         d->id = pthread_self();
 
 1556         pthread_cond_init(&d->cond, NULL);
 
 1561 static inline void fuse_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1562                                          struct fuse_intr_data *d)
 
 1565                 fuse_do_finish_interrupt(f, req, d);
 
 1568 static inline void fuse_prepare_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1569                                           struct fuse_intr_data *d)
 
 1572                 fuse_do_prepare_interrupt(req, d);
 
 1576                               char* buf, 
size_t len)
 
 1580         snprintf(buf, len, 
"%llu", (
unsigned long long) fi->
fh);
 
 1584 int fuse_fs_getattr(
struct fuse_fs *fs, 
const char *path, 
struct stat *buf,
 
 1588         if (fs->op.getattr) {
 
 1591                         fuse_log(FUSE_LOG_DEBUG, 
"getattr[%s] %s\n",
 
 1592                                 file_info_string(fi, buf, 
sizeof(buf)),
 
 1595                 return fs->op.getattr(path, buf, fi);
 
 1601 int fuse_fs_rename(
struct fuse_fs *fs, 
const char *oldpath,
 
 1602                    const char *newpath, 
unsigned int flags)
 
 1605         if (fs->op.rename) {
 
 1607                         fuse_log(FUSE_LOG_DEBUG, 
"rename %s %s 0x%x\n", oldpath, newpath,
 
 1610                 return fs->op.rename(oldpath, newpath, flags);
 
 1616 int fuse_fs_unlink(
struct fuse_fs *fs, 
const char *path)
 
 1619         if (fs->op.unlink) {
 
 1621                         fuse_log(FUSE_LOG_DEBUG, 
"unlink %s\n", path);
 
 1623                 return fs->op.unlink(path);
 
 1629 int fuse_fs_rmdir(
struct fuse_fs *fs, 
const char *path)
 
 1634                         fuse_log(FUSE_LOG_DEBUG, 
"rmdir %s\n", path);
 
 1636                 return fs->op.rmdir(path);
 
 1642 int fuse_fs_symlink(
struct fuse_fs *fs, 
const char *linkname, 
const char *path)
 
 1645         if (fs->op.symlink) {
 
 1647                         fuse_log(FUSE_LOG_DEBUG, 
"symlink %s %s\n", linkname, path);
 
 1649                 return fs->op.symlink(linkname, path);
 
 1655 int fuse_fs_link(
struct fuse_fs *fs, 
const char *oldpath, 
const char *newpath)
 
 1660                         fuse_log(FUSE_LOG_DEBUG, 
"link %s %s\n", oldpath, newpath);
 
 1662                 return fs->op.link(oldpath, newpath);
 
 1668 int fuse_fs_release(
struct fuse_fs *fs,  
const char *path,
 
 1672         if (fs->op.release) {
 
 1674                         fuse_log(FUSE_LOG_DEBUG, 
"release%s[%llu] flags: 0x%x\n",
 
 1675                                 fi->
flush ? 
"+flush" : 
"",
 
 1676                                 (
unsigned long long) fi->
fh, fi->
flags);
 
 1678                 return fs->op.release(path, fi);
 
 1684 int fuse_fs_opendir(
struct fuse_fs *fs, 
const char *path,
 
 1688         if (fs->op.opendir) {
 
 1692                         fuse_log(FUSE_LOG_DEBUG, 
"opendir flags: 0x%x %s\n", fi->
flags,
 
 1695                 err = fs->op.opendir(path, fi);
 
 1697                 if (fs->debug && !err)
 
 1698                         fuse_log(FUSE_LOG_DEBUG, 
"   opendir[%llu] flags: 0x%x %s\n",
 
 1699                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1707 int fuse_fs_open(
struct fuse_fs *fs, 
const char *path,
 
 1715                         fuse_log(FUSE_LOG_DEBUG, 
"open flags: 0x%x %s\n", fi->
flags,
 
 1718                 err = fs->op.open(path, fi);
 
 1720                 if (fs->debug && !err)
 
 1721                         fuse_log(FUSE_LOG_DEBUG, 
"   open[%llu] flags: 0x%x %s\n",
 
 1722                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1730 static void fuse_free_buf(
struct fuse_bufvec *buf)
 
 1735                 for (i = 0; i < buf->
count; i++)
 
 1742 int fuse_fs_read_buf(
struct fuse_fs *fs, 
const char *path,
 
 1743                      struct fuse_bufvec **bufp, 
size_t size, off_t off,
 
 1747         if (fs->op.read || fs->op.read_buf) {
 
 1752                                 "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1753                                 (
unsigned long long) fi->
fh,
 
 1754                                 size, (
unsigned long long) off, fi->
flags);
 
 1756                 if (fs->op.read_buf) {
 
 1757                         res = fs->op.read_buf(path, bufp, size, off, fi);
 
 1771                         *
buf = FUSE_BUFVEC_INIT(size);
 
 1775                         res = fs->op.read(path, mem, size, 
off, fi);
 
 1780                 if (fs->debug && res >= 0)
 
 1781                         fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %zu bytes from %llu\n",
 
 1782                                 (
unsigned long long) fi->
fh,
 
 1784                                 (
unsigned long long) 
off);
 
 1786                         fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1797 int fuse_fs_read(
struct fuse_fs *fs, 
const char *path, 
char *mem, 
size_t size,
 
 1801         if (fs->op.read || fs->op.read_buf) {
 
 1806                                 "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1807                                 (
unsigned long long) fi->
fh,
 
 1808                                 size, (
unsigned long long) 
off, fi->
flags);
 
 1810                 if (fs->op.read_buf) {
 
 1813                         res = fs->op.read_buf(path, &
buf, size, 
off, fi);
 
 1822                         res = fs->op.read(path, mem, size, 
off, fi);
 
 1825                 if (fs->debug && res >= 0)
 
 1826                         fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %u bytes from %llu\n",
 
 1827                                 (
unsigned long long) fi->
fh,
 
 1829                                 (
unsigned long long) 
off);
 
 1830                 if (res >= 0 && res > (
int) size)
 
 1831                         fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1839 int fuse_fs_write_buf(
struct fuse_fs *fs, 
const char *path,
 
 1844         if (fs->op.write_buf || fs->op.write) {
 
 1848                 assert(
buf->idx == 0 && 
buf->off == 0);
 
 1851                                 "write%s[%llu] %zu bytes to %llu flags: 0x%x\n",
 
 1853                                 (
unsigned long long) fi->
fh,
 
 1855                                 (
unsigned long long) 
off,
 
 1858                 if (fs->op.write_buf) {
 
 1859                         res = fs->op.write_buf(path, 
buf, 
off, fi);
 
 1865                         if (
buf->count == 1 &&
 
 1867                                 flatbuf = &
buf->buf[0];
 
 1880                                 flatbuf = &tmp.
buf[0];
 
 1883                         res = fs->op.write(path, flatbuf->
mem, flatbuf->
size,
 
 1889                 if (fs->debug && res >= 0)
 
 1890                         fuse_log(FUSE_LOG_DEBUG, 
"   write%s[%llu] %u bytes to %llu\n",
 
 1892                                 (
unsigned long long) fi->
fh, res,
 
 1893                                 (
unsigned long long) 
off);
 
 1894                 if (res > (
int) size)
 
 1895                         fuse_log(FUSE_LOG_ERR, 
"fuse: wrote too many bytes\n");
 
 1903 int fuse_fs_write(
struct fuse_fs *fs, 
const char *path, 
const char *mem,
 
 1908         bufv.
buf[0].
mem = (
void *) mem;
 
 1910         return fuse_fs_write_buf(fs, path, &bufv, 
off, fi);
 
 1913 int fuse_fs_fsync(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1919                         fuse_log(FUSE_LOG_DEBUG, 
"fsync[%llu] datasync: %i\n",
 
 1920                                 (
unsigned long long) fi->
fh, datasync);
 
 1922                 return fs->op.fsync(path, datasync, fi);
 
 1928 int fuse_fs_fsyncdir(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1932         if (fs->op.fsyncdir) {
 
 1934                         fuse_log(FUSE_LOG_DEBUG, 
"fsyncdir[%llu] datasync: %i\n",
 
 1935                                 (
unsigned long long) fi->
fh, datasync);
 
 1937                 return fs->op.fsyncdir(path, datasync, fi);
 
 1943 int fuse_fs_flush(
struct fuse_fs *fs, 
const char *path,
 
 1949                         fuse_log(FUSE_LOG_DEBUG, 
"flush[%llu]\n",
 
 1950                                 (
unsigned long long) fi->
fh);
 
 1952                 return fs->op.flush(path, fi);
 
 1958 int fuse_fs_statfs(
struct fuse_fs *fs, 
const char *path, 
struct statvfs *
buf)
 
 1961         if (fs->op.statfs) {
 
 1963                         fuse_log(FUSE_LOG_DEBUG, 
"statfs %s\n", path);
 
 1965                 return fs->op.statfs(path, 
buf);
 
 1967                 buf->f_namemax = 255;
 
 1973 int fuse_fs_releasedir(
struct fuse_fs *fs, 
const char *path,
 
 1977         if (fs->op.releasedir) {
 
 1979                         fuse_log(FUSE_LOG_DEBUG, 
"releasedir[%llu] flags: 0x%x\n",
 
 1980                                 (
unsigned long long) fi->
fh, fi->
flags);
 
 1982                 return fs->op.releasedir(path, fi);
 
 1988 int fuse_fs_readdir(
struct fuse_fs *fs, 
const char *path, 
void *
buf,
 
 1994         if (fs->op.readdir) {
 
 1996                         fuse_log(FUSE_LOG_DEBUG, 
"readdir%s[%llu] from %llu\n",
 
 1998                                 (
unsigned long long) fi->
fh,
 
 1999                                 (
unsigned long long) 
off);
 
 2002                 return fs->op.readdir(path, 
buf, filler, 
off, fi, flags);
 
 2008 int fuse_fs_create(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2012         if (fs->op.create) {
 
 2017                                 "create flags: 0x%x %s 0%o umask=0%03o\n",
 
 2018                                 fi->
flags, path, mode,
 
 2021                 err = fs->op.create(path, mode, fi);
 
 2023                 if (fs->debug && !err)
 
 2024                         fuse_log(FUSE_LOG_DEBUG, 
"   create[%llu] flags: 0x%x %s\n",
 
 2025                                 (
unsigned long long) fi->
fh, fi->
flags, path);
 
 2033 int fuse_fs_lock(
struct fuse_fs *fs, 
const char *path,
 
 2039                         fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s %s start: %llu len: %llu pid: %llu\n",
 
 2040                                 (
unsigned long long) fi->
fh,
 
 2041                                 (cmd == F_GETLK ? 
"F_GETLK" :
 
 2042                                  (cmd == F_SETLK ? 
"F_SETLK" :
 
 2043                                   (cmd == F_SETLKW ? 
"F_SETLKW" : 
"???"))),
 
 2044                                 (lock->l_type == F_RDLCK ? 
"F_RDLCK" :
 
 2045                                  (lock->l_type == F_WRLCK ? 
"F_WRLCK" :
 
 2046                                   (lock->l_type == F_UNLCK ? 
"F_UNLCK" :
 
 2048                                 (
unsigned long long) lock->l_start,
 
 2049                                 (
unsigned long long) lock->l_len,
 
 2050                                 (
unsigned long long) lock->l_pid);
 
 2052                 return fs->op.lock(path, fi, cmd, lock);
 
 2058 int fuse_fs_flock(
struct fuse_fs *fs, 
const char *path,
 
 2064                         int xop = op & ~LOCK_NB;
 
 2066                         fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s%s\n",
 
 2067                                 (
unsigned long long) fi->
fh,
 
 2068                                 xop == LOCK_SH ? 
"LOCK_SH" :
 
 2069                                 (xop == LOCK_EX ? 
"LOCK_EX" :
 
 2070                                  (xop == LOCK_UN ? 
"LOCK_UN" : 
"???")),
 
 2071                                 (op & LOCK_NB) ? 
"|LOCK_NB" : 
"");
 
 2073                 return fs->op.flock(path, fi, op);
 
 2079 int fuse_fs_chown(
struct fuse_fs *fs, 
const char *path, uid_t uid,
 
 2086                         fuse_log(FUSE_LOG_DEBUG, 
"chown[%s] %s %lu %lu\n",
 
 2087                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2088                                 path, (
unsigned long) uid, (
unsigned long) gid);
 
 2090                 return fs->op.chown(path, uid, gid, fi);
 
 2096 int fuse_fs_truncate(
struct fuse_fs *fs, 
const char *path, off_t size,
 
 2100         if (fs->op.truncate) {
 
 2103                         fuse_log(FUSE_LOG_DEBUG, 
"truncate[%s] %llu\n",
 
 2104                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2105                                 (
unsigned long long) size);
 
 2107                 return fs->op.truncate(path, size, fi);
 
 2113 int fuse_fs_utimens(
struct fuse_fs *fs, 
const char *path,
 
 2117         if (fs->op.utimens) {
 
 2120                         fuse_log(FUSE_LOG_DEBUG, 
"utimens[%s] %s %li.%09lu %li.%09lu\n",
 
 2121                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2122                                 path, tv[0].tv_sec, tv[0].tv_nsec,
 
 2123                                 tv[1].tv_sec, tv[1].tv_nsec);
 
 2125                 return fs->op.utimens(path, tv, fi);
 
 2131 int fuse_fs_access(
struct fuse_fs *fs, 
const char *path, 
int mask)
 
 2134         if (fs->op.access) {
 
 2136                         fuse_log(FUSE_LOG_DEBUG, 
"access %s 0%o\n", path, mask);
 
 2138                 return fs->op.access(path, mask);
 
 2144 int fuse_fs_readlink(
struct fuse_fs *fs, 
const char *path, 
char *
buf,
 
 2148         if (fs->op.readlink) {
 
 2150                         fuse_log(FUSE_LOG_DEBUG, 
"readlink %s %lu\n", path,
 
 2151                                 (
unsigned long) len);
 
 2153                 return fs->op.readlink(path, 
buf, len);
 
 2159 int fuse_fs_mknod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2165                         fuse_log(FUSE_LOG_DEBUG, 
"mknod %s 0%o 0x%llx umask=0%03o\n",
 
 2166                                 path, mode, (
unsigned long long) rdev,
 
 2169                 return fs->op.mknod(path, mode, rdev);
 
 2175 int fuse_fs_mkdir(
struct fuse_fs *fs, 
const char *path, mode_t mode)
 
 2180                         fuse_log(FUSE_LOG_DEBUG, 
"mkdir %s 0%o umask=0%03o\n",
 
 2183                 return fs->op.mkdir(path, mode);
 
 2189 int fuse_fs_setxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2190                      const char *value, 
size_t size, 
int flags)
 
 2193         if (fs->op.setxattr) {
 
 2195                         fuse_log(FUSE_LOG_DEBUG, 
"setxattr %s %s %lu 0x%x\n",
 
 2196                                 path, name, (
unsigned long) size, flags);
 
 2198                 return fs->op.setxattr(path, name, value, size, flags);
 
 2204 int fuse_fs_getxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2205                      char *value, 
size_t size)
 
 2208         if (fs->op.getxattr) {
 
 2210                         fuse_log(FUSE_LOG_DEBUG, 
"getxattr %s %s %lu\n",
 
 2211                                 path, name, (
unsigned long) size);
 
 2213                 return fs->op.getxattr(path, name, value, size);
 
 2219 int fuse_fs_listxattr(
struct fuse_fs *fs, 
const char *path, 
char *list,
 
 2223         if (fs->op.listxattr) {
 
 2225                         fuse_log(FUSE_LOG_DEBUG, 
"listxattr %s %lu\n",
 
 2226                                 path, (
unsigned long) size);
 
 2228                 return fs->op.listxattr(path, list, size);
 
 2234 int fuse_fs_bmap(
struct fuse_fs *fs, 
const char *path, 
size_t blocksize,
 
 2240                         fuse_log(FUSE_LOG_DEBUG, 
"bmap %s blocksize: %lu index: %llu\n",
 
 2241                                 path, (
unsigned long) blocksize,
 
 2242                                 (
unsigned long long) *
idx);
 
 2244                 return fs->op.bmap(path, blocksize, 
idx);
 
 2250 int fuse_fs_removexattr(
struct fuse_fs *fs, 
const char *path, 
const char *name)
 
 2253         if (fs->op.removexattr) {
 
 2255                         fuse_log(FUSE_LOG_DEBUG, 
"removexattr %s %s\n", path, name);
 
 2257                 return fs->op.removexattr(path, name);
 
 2263 int fuse_fs_ioctl(
struct fuse_fs *fs, 
const char *path, 
unsigned int cmd,
 
 2270                         fuse_log(FUSE_LOG_DEBUG, 
"ioctl[%llu] 0x%x flags: 0x%x\n",
 
 2271                                 (
unsigned long long) fi->
fh, cmd, flags);
 
 2273                 return fs->op.ioctl(path, cmd, arg, fi, flags, data);
 
 2278 int fuse_fs_poll(
struct fuse_fs *fs, 
const char *path,
 
 2287                         fuse_log(FUSE_LOG_DEBUG, 
"poll[%llu] ph: %p, events 0x%x\n",
 
 2288                                 (
unsigned long long) fi->
fh, ph,
 
 2291                 res = fs->op.poll(path, fi, ph, reventsp);
 
 2293                 if (fs->debug && !res)
 
 2294                         fuse_log(FUSE_LOG_DEBUG, 
"   poll[%llu] revents: 0x%x\n",
 
 2295                                 (
unsigned long long) fi->
fh, *reventsp);
 
 2302 int fuse_fs_fallocate(
struct fuse_fs *fs, 
const char *path, 
int mode,
 
 2306         if (fs->op.fallocate) {
 
 2308                         fuse_log(FUSE_LOG_DEBUG, 
"fallocate %s mode %x, offset: %llu, length: %llu\n",
 
 2311                                 (
unsigned long long) offset,
 
 2312                                 (
unsigned long long) length);
 
 2314                 return fs->op.fallocate(path, mode, offset, length, fi);
 
 2319 ssize_t fuse_fs_copy_file_range(
struct fuse_fs *fs, 
const char *path_in,
 
 2321                                 const char *path_out,
 
 2323                                 size_t len, 
int flags)
 
 2326         if (fs->op.copy_file_range) {
 
 2328                         fuse_log(FUSE_LOG_DEBUG, 
"copy_file_range from %s:%llu to " 
 2329                                         "%s:%llu, length: %llu\n",
 
 2331                                 (
unsigned long long) off_in,
 
 2333                                 (
unsigned long long) off_out,
 
 2334                                 (
unsigned long long) len);
 
 2336                 return fs->op.copy_file_range(path_in, fi_in, off_in, path_out,
 
 2337                                               fi_out, off_out, len, flags);
 
 2342 off_t fuse_fs_lseek(
struct fuse_fs *fs, 
const char *path, off_t 
off, 
int whence,
 
 2349                         fuse_log(FUSE_LOG_DEBUG, 
"lseek[%s] %llu %d\n",
 
 2350                                 file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2351                                 (
unsigned long long) 
off, whence);
 
 2353                 return fs->op.lseek(path, 
off, whence, fi);
 
 2359 static int is_open(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 2363         pthread_mutex_lock(&f->lock);
 
 2364         node = lookup_node(f, dir, name);
 
 2365         if (node && node->open_count > 0)
 
 2367         pthread_mutex_unlock(&f->lock);
 
 2371 static char *hidden_name(
struct fuse *f, 
fuse_ino_t dir, 
const char *oldname,
 
 2372                          char *newname, 
size_t bufsize)
 
 2376         struct node *newnode;
 
 2382                 pthread_mutex_lock(&f->lock);
 
 2383                 node = lookup_node(f, dir, oldname);
 
 2385                         pthread_mutex_unlock(&f->lock);
 
 2390                         snprintf(newname, bufsize, 
".fuse_hidden%08x%08x",
 
 2391                                  (
unsigned int) node->nodeid, f->hidectr);
 
 2392                         newnode = lookup_node(f, dir, newname);
 
 2395                 res = try_get_path(f, dir, newname, &newpath, NULL, 
false);
 
 2396                 pthread_mutex_unlock(&f->lock);
 
 2400                 memset(&buf, 0, 
sizeof(buf));
 
 2401                 res = fuse_fs_getattr(f->fs, newpath, &buf, NULL);
 
 2406         } 
while(res == 0 && --failctr);
 
 2411 static int hide_node(
struct fuse *f, 
const char *oldpath,
 
 2418         newpath = hidden_name(f, dir, oldname, newname, 
sizeof(newname));
 
 2420                 err = fuse_fs_rename(f->fs, oldpath, newpath, 0);
 
 2422                         err = rename_node(f, dir, oldname, dir, newname, 1);
 
 2428 static int mtime_eq(
const struct stat *stbuf, 
const struct timespec *ts)
 
 2430         return stbuf->st_mtime == ts->tv_sec &&
 
 2431                 ST_MTIM_NSEC(stbuf) == ts->tv_nsec;
 
 2434 #ifndef CLOCK_MONOTONIC 
 2435 #define CLOCK_MONOTONIC CLOCK_REALTIME 
 2438 static void curr_time(
struct timespec *now)
 
 2440         static clockid_t clockid = CLOCK_MONOTONIC;
 
 2441         int res = clock_gettime(clockid, now);
 
 2442         if (res == -1 && errno == EINVAL) {
 
 2443                 clockid = CLOCK_REALTIME;
 
 2444                 res = clock_gettime(clockid, now);
 
 2447                 perror(
"fuse: clock_gettime");
 
 2452 static void update_stat(
struct node *node, 
const struct stat *stbuf)
 
 2454         if (node->cache_valid && (!mtime_eq(stbuf, &node->mtime) ||
 
 2455                                   stbuf->st_size != node->size))
 
 2456                 node->cache_valid = 0;
 
 2457         node->mtime.tv_sec = stbuf->st_mtime;
 
 2458         node->mtime.tv_nsec = ST_MTIM_NSEC(stbuf);
 
 2459         node->size = stbuf->st_size;
 
 2460         curr_time(&node->stat_updated);
 
 2463 static int do_lookup(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 2468         node = find_node(f, nodeid, name);
 
 2472         e->
ino = node->nodeid;
 
 2476         if (f->conf.auto_cache) {
 
 2477                 pthread_mutex_lock(&f->lock);
 
 2478                 update_stat(node, &e->
attr);
 
 2479                 pthread_mutex_unlock(&f->lock);
 
 2481         set_stat(f, e->
ino, &e->
attr);
 
 2485 static int lookup_path(
struct fuse *f, 
fuse_ino_t nodeid,
 
 2486                        const char *name, 
const char *path,
 
 2492         res = fuse_fs_getattr(f->fs, path, &e->
attr, fi);
 
 2494                 res = do_lookup(f, nodeid, name, e);
 
 2495                 if (res == 0 && f->conf.debug) {
 
 2496                         fuse_log(FUSE_LOG_DEBUG, 
"   NODEID: %llu\n",
 
 2497                                 (
unsigned long long) e->
ino);
 
 2503 static struct fuse_context_i *fuse_get_context_internal(
void)
 
 2505         return (
struct fuse_context_i *) pthread_getspecific(fuse_context_key);
 
 2508 static struct fuse_context_i *fuse_create_context(
struct fuse *f)
 
 2510         struct fuse_context_i *c = fuse_get_context_internal();
 
 2512                 c = (
struct fuse_context_i *)
 
 2513                         calloc(1, 
sizeof(
struct fuse_context_i));
 
 2519                         fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate thread specific data\n");
 
 2522                 pthread_setspecific(fuse_context_key, c);
 
 2524                 memset(c, 0, 
sizeof(*c));
 
 2531 static void fuse_freecontext(
void *data)
 
 2536 static int fuse_create_context_key(
void)
 
 2539         pthread_mutex_lock(&fuse_context_lock);
 
 2540         if (!fuse_context_ref) {
 
 2541                 err = pthread_key_create(&fuse_context_key, fuse_freecontext);
 
 2543                         fuse_log(FUSE_LOG_ERR, 
"fuse: failed to create thread specific key: %s\n",
 
 2545                         pthread_mutex_unlock(&fuse_context_lock);
 
 2550         pthread_mutex_unlock(&fuse_context_lock);
 
 2554 static void fuse_delete_context_key(
void)
 
 2556         pthread_mutex_lock(&fuse_context_lock);
 
 2558         if (!fuse_context_ref) {
 
 2559                 free(pthread_getspecific(fuse_context_key));
 
 2560                 pthread_key_delete(fuse_context_key);
 
 2562         pthread_mutex_unlock(&fuse_context_lock);
 
 2565 static struct fuse *req_fuse_prepare(
fuse_req_t req)
 
 2567         struct fuse_context_i *c = fuse_create_context(req_fuse(req));
 
 2570         c->ctx.uid = ctx->
uid;
 
 2571         c->ctx.gid = ctx->
gid;
 
 2572         c->ctx.pid = ctx->
pid;
 
 2573         c->ctx.umask = ctx->
umask;
 
 2577 static inline void reply_err(
fuse_req_t req, 
int err)
 
 2587                 struct fuse *f = req_fuse(req);
 
 2591                                 forget_node(f, e->
ino, 1);
 
 2594                 reply_err(req, err);
 
 2597 void fuse_fs_init(
struct fuse_fs *fs, 
struct fuse_conn_info *conn,
 
 2601         if (!fs->op.write_buf)
 
 2608                 fs->user_data = fs->op.init(conn, cfg);
 
 2611 static void fuse_lib_init(
void *data, 
struct fuse_conn_info *conn)
 
 2613         struct fuse *f = (
struct fuse *) data;
 
 2615         fuse_create_context(f);
 
 2618         fuse_fs_init(f->fs, conn, &f->conf);
 
 2621 void fuse_fs_destroy(
struct fuse_fs *fs)
 
 2625                 fs->op.destroy(fs->user_data);
 
 2629 static void fuse_lib_destroy(
void *data)
 
 2631         struct fuse *f = (
struct fuse *) data;
 
 2633         fuse_create_context(f);
 
 2634         fuse_fs_destroy(f->fs);
 
 2641         struct fuse *f = req_fuse_prepare(req);
 
 2645         struct node *dot = NULL;
 
 2647         if (name[0] == 
'.') {
 
 2648                 int len = strlen(name);
 
 2650                 if (len == 1 || (name[1] == 
'.' && len == 2)) {
 
 2651                         pthread_mutex_lock(&f->lock);
 
 2654                                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOT\n");
 
 2655                                 dot = get_node_nocheck(f, parent);
 
 2657                                         pthread_mutex_unlock(&f->lock);
 
 2658                                         reply_entry(req, &e, -ESTALE);
 
 2664                                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOTDOT\n");
 
 2665                                 parent = get_node(f, parent)->parent->nodeid;
 
 2667                         pthread_mutex_unlock(&f->lock);
 
 2672         err = get_path_name(f, parent, name, &path);
 
 2674                 struct fuse_intr_data d;
 
 2676                         fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP %s\n", path);
 
 2677                 fuse_prepare_interrupt(f, req, &d);
 
 2678                 err = lookup_path(f, parent, name, path, &e, NULL);
 
 2679                 if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
 
 2684                 fuse_finish_interrupt(f, req, &d);
 
 2685                 free_path(f, parent, path);
 
 2688                 pthread_mutex_lock(&f->lock);
 
 2690                 pthread_mutex_unlock(&f->lock);
 
 2692         reply_entry(req, &e, err);
 
 2695 static void do_forget(
struct fuse *f, 
fuse_ino_t ino, uint64_t nlookup)
 
 2698                 fuse_log(FUSE_LOG_DEBUG, 
"FORGET %llu/%llu\n", (
unsigned long long)ino,
 
 2699                         (
unsigned long long) nlookup);
 
 2700         forget_node(f, ino, nlookup);
 
 2705         do_forget(req_fuse(req), ino, nlookup);
 
 2709 static void fuse_lib_forget_multi(
fuse_req_t req, 
size_t count,
 
 2710                                   struct fuse_forget_data *forgets)
 
 2712         struct fuse *f = req_fuse(req);
 
 2715         for (i = 0; i < count; i++)
 
 2716                 do_forget(f, forgets[i].ino, forgets[i].nlookup);
 
 2725         struct fuse *f = req_fuse_prepare(req);
 
 2730         memset(&buf, 0, 
sizeof(buf));
 
 2733                 err = get_path_nullok(f, ino, &path);
 
 2735                 err = get_path(f, ino, &path);
 
 2737                 struct fuse_intr_data d;
 
 2738                 fuse_prepare_interrupt(f, req, &d);
 
 2739                 err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2740                 fuse_finish_interrupt(f, req, &d);
 
 2741                 free_path(f, ino, path);
 
 2746                 pthread_mutex_lock(&f->lock);
 
 2747                 node = get_node(f, ino);
 
 2748                 if (node->is_hidden && buf.st_nlink > 0)
 
 2750                 if (f->conf.auto_cache)
 
 2751                         update_stat(node, &buf);
 
 2752                 pthread_mutex_unlock(&f->lock);
 
 2753                 set_stat(f, ino, &buf);
 
 2756                 reply_err(req, err);
 
 2759 int fuse_fs_chmod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2766                         fuse_log(FUSE_LOG_DEBUG, 
"chmod[%s] %s %llo\n",
 
 2767                                 file_info_string(fi, buf, 
sizeof(buf)),
 
 2768                                 path, (
unsigned long long) mode);
 
 2770                 return fs->op.chmod(path, mode, fi);
 
 2779         struct fuse *f = req_fuse_prepare(req);
 
 2784         memset(&buf, 0, 
sizeof(buf));
 
 2786                 err = get_path_nullok(f, ino, &path);
 
 2788                 err = get_path(f, ino, &path);
 
 2790                 struct fuse_intr_data d;
 
 2791                 fuse_prepare_interrupt(f, req, &d);
 
 2793                 if (!err && (valid & FUSE_SET_ATTR_MODE))
 
 2794                         err = fuse_fs_chmod(f->fs, path, attr->st_mode, fi);
 
 2795                 if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) {
 
 2796                         uid_t uid = (valid & FUSE_SET_ATTR_UID) ?
 
 2797                                 attr->st_uid : (uid_t) -1;
 
 2798                         gid_t gid = (valid & FUSE_SET_ATTR_GID) ?
 
 2799                                 attr->st_gid : (gid_t) -1;
 
 2800                         err = fuse_fs_chown(f->fs, path, uid, gid, fi);
 
 2802                 if (!err && (valid & FUSE_SET_ATTR_SIZE)) {
 
 2803                         err = fuse_fs_truncate(f->fs, path,
 
 2806 #ifdef HAVE_UTIMENSAT 
 2808                     (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))) {
 
 2809                         struct timespec tv[2];
 
 2813                         tv[0].tv_nsec = UTIME_OMIT;
 
 2814                         tv[1].tv_nsec = UTIME_OMIT;
 
 2816                         if (valid & FUSE_SET_ATTR_ATIME_NOW)
 
 2817                                 tv[0].tv_nsec = UTIME_NOW;
 
 2818                         else if (valid & FUSE_SET_ATTR_ATIME)
 
 2819                                 tv[0] = attr->st_atim;
 
 2821                         if (valid & FUSE_SET_ATTR_MTIME_NOW)
 
 2822                                 tv[1].tv_nsec = UTIME_NOW;
 
 2823                         else if (valid & FUSE_SET_ATTR_MTIME)
 
 2824                                 tv[1] = attr->st_mtim;
 
 2826                         err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2830                     (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) ==
 
 2831                     (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) {
 
 2832                         struct timespec tv[2];
 
 2833                         tv[0].tv_sec = attr->st_atime;
 
 2834                         tv[0].tv_nsec = ST_ATIM_NSEC(attr);
 
 2835                         tv[1].tv_sec = attr->st_mtime;
 
 2836                         tv[1].tv_nsec = ST_MTIM_NSEC(attr);
 
 2837                         err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2840                         err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2842                 fuse_finish_interrupt(f, req, &d);
 
 2843                 free_path(f, ino, path);
 
 2846                 if (f->conf.auto_cache) {
 
 2847                         pthread_mutex_lock(&f->lock);
 
 2848                         update_stat(get_node(f, ino), &buf);
 
 2849                         pthread_mutex_unlock(&f->lock);
 
 2851                 set_stat(f, ino, &buf);
 
 2854                 reply_err(req, err);
 
 2859         struct fuse *f = req_fuse_prepare(req);
 
 2863         err = get_path(f, ino, &path);
 
 2865                 struct fuse_intr_data d;
 
 2867                 fuse_prepare_interrupt(f, req, &d);
 
 2868                 err = fuse_fs_access(f->fs, path, mask);
 
 2869                 fuse_finish_interrupt(f, req, &d);
 
 2870                 free_path(f, ino, path);
 
 2872         reply_err(req, err);
 
 2877         struct fuse *f = req_fuse_prepare(req);
 
 2878         char linkname[PATH_MAX + 1];
 
 2882         err = get_path(f, ino, &path);
 
 2884                 struct fuse_intr_data d;
 
 2885                 fuse_prepare_interrupt(f, req, &d);
 
 2886                 err = fuse_fs_readlink(f->fs, path, linkname, 
sizeof(linkname));
 
 2887                 fuse_finish_interrupt(f, req, &d);
 
 2888                 free_path(f, ino, path);
 
 2891                 linkname[PATH_MAX] = 
'\0';
 
 2894                 reply_err(req, err);
 
 2898                            mode_t mode, dev_t rdev)
 
 2900         struct fuse *f = req_fuse_prepare(req);
 
 2905         err = get_path_name(f, parent, name, &path);
 
 2907                 struct fuse_intr_data d;
 
 2909                 fuse_prepare_interrupt(f, req, &d);
 
 2911                 if (S_ISREG(mode)) {
 
 2914                         memset(&fi, 0, 
sizeof(fi));
 
 2915                         fi.
flags = O_CREAT | O_EXCL | O_WRONLY;
 
 2916                         err = fuse_fs_create(f->fs, path, mode, &fi);
 
 2918                                 err = lookup_path(f, parent, name, path, &e,
 
 2920                                 fuse_fs_release(f->fs, path, &fi);
 
 2923                 if (err == -ENOSYS) {
 
 2924                         err = fuse_fs_mknod(f->fs, path, mode, rdev);
 
 2926                                 err = lookup_path(f, parent, name, path, &e,
 
 2929                 fuse_finish_interrupt(f, req, &d);
 
 2930                 free_path(f, parent, path);
 
 2932         reply_entry(req, &e, err);
 
 2938         struct fuse *f = req_fuse_prepare(req);
 
 2943         err = get_path_name(f, parent, name, &path);
 
 2945                 struct fuse_intr_data d;
 
 2947                 fuse_prepare_interrupt(f, req, &d);
 
 2948                 err = fuse_fs_mkdir(f->fs, path, mode);
 
 2950                         err = lookup_path(f, parent, name, path, &e, NULL);
 
 2951                 fuse_finish_interrupt(f, req, &d);
 
 2952                 free_path(f, parent, path);
 
 2954         reply_entry(req, &e, err);
 
 2960         struct fuse *f = req_fuse_prepare(req);
 
 2965         err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 2967                 struct fuse_intr_data d;
 
 2969                 fuse_prepare_interrupt(f, req, &d);
 
 2970                 if (!f->conf.hard_remove && is_open(f, parent, name)) {
 
 2971                         err = hide_node(f, path, parent, name);
 
 2973                         err = fuse_fs_unlink(f->fs, path);
 
 2975                                 remove_node(f, parent, name);
 
 2977                 fuse_finish_interrupt(f, req, &d);
 
 2978                 free_path_wrlock(f, parent, wnode, path);
 
 2980         reply_err(req, err);
 
 2985         struct fuse *f = req_fuse_prepare(req);
 
 2990         err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 2992                 struct fuse_intr_data d;
 
 2994                 fuse_prepare_interrupt(f, req, &d);
 
 2995                 err = fuse_fs_rmdir(f->fs, path);
 
 2996                 fuse_finish_interrupt(f, req, &d);
 
 2998                         remove_node(f, parent, name);
 
 2999                 free_path_wrlock(f, parent, wnode, path);
 
 3001         reply_err(req, err);
 
 3004 static void fuse_lib_symlink(
fuse_req_t req, 
const char *linkname,
 
 3007         struct fuse *f = req_fuse_prepare(req);
 
 3012         err = get_path_name(f, parent, name, &path);
 
 3014                 struct fuse_intr_data d;
 
 3016                 fuse_prepare_interrupt(f, req, &d);
 
 3017                 err = fuse_fs_symlink(f->fs, linkname, path);
 
 3019                         err = lookup_path(f, parent, name, path, &e, NULL);
 
 3020                 fuse_finish_interrupt(f, req, &d);
 
 3021                 free_path(f, parent, path);
 
 3023         reply_entry(req, &e, err);
 
 3028                             const char *newname, 
unsigned int flags)
 
 3030         struct fuse *f = req_fuse_prepare(req);
 
 3033         struct node *wnode1;
 
 3034         struct node *wnode2;
 
 3037         err = get_path2(f, olddir, oldname, newdir, newname,
 
 3038                         &oldpath, &newpath, &wnode1, &wnode2);
 
 3040                 struct fuse_intr_data d;
 
 3042                 fuse_prepare_interrupt(f, req, &d);
 
 3043                 if (!f->conf.hard_remove && !(flags & RENAME_EXCHANGE) &&
 
 3044                     is_open(f, newdir, newname))
 
 3045                         err = hide_node(f, newpath, newdir, newname);
 
 3047                         err = fuse_fs_rename(f->fs, oldpath, newpath, flags);
 
 3049                                 if (flags & RENAME_EXCHANGE) {
 
 3050                                         err = exchange_node(f, olddir, oldname,
 
 3053                                         err = rename_node(f, olddir, oldname,
 
 3054                                                           newdir, newname, 0);
 
 3058                 fuse_finish_interrupt(f, req, &d);
 
 3059                 free_path2(f, olddir, newdir, wnode1, wnode2, oldpath, newpath);
 
 3061         reply_err(req, err);
 
 3065                           const char *newname)
 
 3067         struct fuse *f = req_fuse_prepare(req);
 
 3073         err = get_path2(f, 
ino, NULL, newparent, newname,
 
 3074                         &oldpath, &newpath, NULL, NULL);
 
 3076                 struct fuse_intr_data d;
 
 3078                 fuse_prepare_interrupt(f, req, &d);
 
 3079                 err = fuse_fs_link(f->fs, oldpath, newpath);
 
 3081                         err = lookup_path(f, newparent, newname, newpath,
 
 3083                 fuse_finish_interrupt(f, req, &d);
 
 3084                 free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
 
 3086         reply_entry(req, &e, err);
 
 3089 static void fuse_do_release(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3093         int unlink_hidden = 0;
 
 3095         fuse_fs_release(f->fs, path, fi);
 
 3097         pthread_mutex_lock(&f->lock);
 
 3098         node = get_node(f, ino);
 
 3099         assert(node->open_count > 0);
 
 3101         if (node->is_hidden && !node->open_count) {
 
 3103                 node->is_hidden = 0;
 
 3105         pthread_mutex_unlock(&f->lock);
 
 3109                         fuse_fs_unlink(f->fs, path);
 
 3110                 } 
else if (f->conf.nullpath_ok) {
 
 3113                         if (get_path(f, ino, &unlinkpath) == 0)
 
 3114                                 fuse_fs_unlink(f->fs, unlinkpath);
 
 3116                         free_path(f, ino, unlinkpath);
 
 3122                             const char *name, mode_t mode,
 
 3125         struct fuse *f = req_fuse_prepare(req);
 
 3126         struct fuse_intr_data d;
 
 3131         err = get_path_name(f, parent, name, &path);
 
 3133                 fuse_prepare_interrupt(f, req, &d);
 
 3134                 err = fuse_fs_create(f->fs, path, mode, fi);
 
 3136                         err = lookup_path(f, parent, name, path, &e, fi);
 
 3138                                 fuse_fs_release(f->fs, path, fi);
 
 3139                         else if (!S_ISREG(e.
attr.st_mode)) {
 
 3141                                 fuse_fs_release(f->fs, path, fi);
 
 3142                                 forget_node(f, e.
ino, 1);
 
 3144                                 if (f->conf.direct_io)
 
 3146                                 if (f->conf.kernel_cache)
 
 3151                 fuse_finish_interrupt(f, req, &d);
 
 3154                 pthread_mutex_lock(&f->lock);
 
 3155                 get_node(f, e.
ino)->open_count++;
 
 3156                 pthread_mutex_unlock(&f->lock);
 
 3160                         fuse_do_release(f, e.
ino, path, fi);
 
 3161                         forget_node(f, e.
ino, 1);
 
 3164                 reply_err(req, err);
 
 3167         free_path(f, parent, path);
 
 3170 static double diff_timespec(
const struct timespec *t1,
 
 3171                             const struct timespec *t2)
 
 3173         return (t1->tv_sec - t2->tv_sec) +
 
 3174                 ((double) t1->tv_nsec - (
double) t2->tv_nsec) / 1000000000.0;
 
 3177 static void open_auto_cache(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3182         pthread_mutex_lock(&f->lock);
 
 3183         node = get_node(f, ino);
 
 3184         if (node->cache_valid) {
 
 3185                 struct timespec now;
 
 3188                 if (diff_timespec(&now, &node->stat_updated) >
 
 3189                     f->conf.ac_attr_timeout) {
 
 3192                         pthread_mutex_unlock(&f->lock);
 
 3193                         err = fuse_fs_getattr(f->fs, path, &stbuf, fi);
 
 3194                         pthread_mutex_lock(&f->lock);
 
 3196                                 update_stat(node, &stbuf);
 
 3198                                 node->cache_valid = 0;
 
 3201         if (node->cache_valid)
 
 3204         node->cache_valid = 1;
 
 3205         pthread_mutex_unlock(&f->lock);
 
 3211         struct fuse *f = req_fuse_prepare(req);
 
 3212         struct fuse_intr_data d;
 
 3216         err = get_path(f, ino, &path);
 
 3218                 fuse_prepare_interrupt(f, req, &d);
 
 3219                 err = fuse_fs_open(f->fs, path, fi);
 
 3221                         if (f->conf.direct_io)
 
 3223                         if (f->conf.kernel_cache)
 
 3226                         if (f->conf.auto_cache)
 
 3227                                 open_auto_cache(f, ino, path, fi);
 
 3229                         if (f->conf.no_rofd_flush &&
 
 3230                             (fi->
flags & O_ACCMODE) == O_RDONLY)
 
 3233                 fuse_finish_interrupt(f, req, &d);
 
 3236                 pthread_mutex_lock(&f->lock);
 
 3237                 get_node(f, ino)->open_count++;
 
 3238                 pthread_mutex_unlock(&f->lock);
 
 3242                         fuse_do_release(f, ino, path, fi);
 
 3245                 reply_err(req, err);
 
 3247         free_path(f, ino, path);
 
 3253         struct fuse *f = req_fuse_prepare(req);
 
 3258         res = get_path_nullok(f, ino, &path);
 
 3260                 struct fuse_intr_data d;
 
 3262                 fuse_prepare_interrupt(f, req, &d);
 
 3263                 res = fuse_fs_read_buf(f->fs, path, &buf, size, off, fi);
 
 3264                 fuse_finish_interrupt(f, req, &d);
 
 3265                 free_path(f, ino, path);
 
 3271                 reply_err(req, res);
 
 3280         struct fuse *f = req_fuse_prepare(req);
 
 3284         res = get_path_nullok(f, ino, &path);
 
 3286                 struct fuse_intr_data d;
 
 3288                 fuse_prepare_interrupt(f, req, &d);
 
 3289                 res = fuse_fs_write_buf(f->fs, path, buf, off, fi);
 
 3290                 fuse_finish_interrupt(f, req, &d);
 
 3291                 free_path(f, ino, path);
 
 3297                 reply_err(req, res);
 
 3303         struct fuse *f = req_fuse_prepare(req);
 
 3307         err = get_path_nullok(f, ino, &path);
 
 3309                 struct fuse_intr_data d;
 
 3311                 fuse_prepare_interrupt(f, req, &d);
 
 3312                 err = fuse_fs_fsync(f->fs, path, datasync, fi);
 
 3313                 fuse_finish_interrupt(f, req, &d);
 
 3314                 free_path(f, ino, path);
 
 3316         reply_err(req, err);
 
 3319 static struct fuse_dh *get_dirhandle(
const struct fuse_file_info *llfi,
 
 3322         struct fuse_dh *dh = (
struct fuse_dh *) (uintptr_t) llfi->
fh;
 
 3331         struct fuse *f = req_fuse_prepare(req);
 
 3332         struct fuse_intr_data d;
 
 3338         dh = (
struct fuse_dh *) malloc(
sizeof(
struct fuse_dh));
 
 3340                 reply_err(req, -ENOMEM);
 
 3343         memset(dh, 0, 
sizeof(
struct fuse_dh));
 
 3345         dh->contents = NULL;
 
 3350         pthread_mutex_init(&dh->lock, NULL);
 
 3352         llfi->
fh = (uintptr_t) dh;
 
 3354         memset(&fi, 0, 
sizeof(fi));
 
 3357         err = get_path(f, ino, &path);
 
 3359                 fuse_prepare_interrupt(f, req, &d);
 
 3360                 err = fuse_fs_opendir(f->fs, path, &fi);
 
 3361                 fuse_finish_interrupt(f, req, &d);
 
 3368                         fuse_fs_releasedir(f->fs, path, &fi);
 
 3369                         pthread_mutex_destroy(&dh->lock);
 
 3373                 reply_err(req, err);
 
 3374                 pthread_mutex_destroy(&dh->lock);
 
 3377         free_path(f, ino, path);
 
 3380 static int extend_contents(
struct fuse_dh *dh, 
unsigned minsize)
 
 3382         if (minsize > dh->size) {
 
 3384                 unsigned newsize = dh->size;
 
 3387                 while (newsize < minsize) {
 
 3388                         if (newsize >= 0x80000000)
 
 3389                                 newsize = 0xffffffff;
 
 3394                 newptr = (
char *) realloc(dh->contents, newsize);
 
 3396                         dh->error = -ENOMEM;
 
 3399                 dh->contents = newptr;
 
 3405 static int fuse_add_direntry_to_dh(
struct fuse_dh *dh, 
const char *name,
 
 3408         struct fuse_direntry *de;
 
 3410         de = malloc(
sizeof(
struct fuse_direntry));
 
 3412                 dh->error = -ENOMEM;
 
 3415         de->name = strdup(name);
 
 3417                 dh->error = -ENOMEM;
 
 3425         dh->last = &de->next;
 
 3436         pthread_mutex_lock(&f->lock);
 
 3437         node = lookup_node(f, parent, name);
 
 3440         pthread_mutex_unlock(&f->lock);
 
 3445 static int fill_dir(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3448         struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3459                 memset(&stbuf, 0, 
sizeof(stbuf));
 
 3460                 stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3463         if (!dh->fuse->conf.use_ino) {
 
 3464                 stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3465                 if (dh->fuse->conf.readdir_ino) {
 
 3466                         stbuf.st_ino = (ino_t)
 
 3467                                 lookup_nodeid(dh->fuse, dh->nodeid, name);
 
 3484                 if (extend_contents(dh, dh->needlen) == -1)
 
 3489                                           dh->needlen - dh->len, name,
 
 3491                 if (newlen > dh->needlen)
 
 3498                 if (fuse_add_direntry_to_dh(dh, name, &stbuf) == -1)
 
 3504 static int is_dot_or_dotdot(
const char *name)
 
 3506         return name[0] == 
'.' && (name[1] == 
'\0' ||
 
 3507                                   (name[1] == 
'.' && name[2] == 
'\0'));
 
 3510 static int fill_dir_plus(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3513         struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3518         struct fuse *f = dh->fuse;
 
 3529                 if (!is_dot_or_dotdot(name)) {
 
 3530                         res = do_lookup(f, dh->nodeid, name, &e);
 
 3537                 e.
attr.st_ino = FUSE_UNKNOWN_INO;
 
 3539                         e.
attr.st_mode = statp->st_mode;
 
 3540                         if (f->conf.use_ino)
 
 3541                                 e.
attr.st_ino = statp->st_ino;
 
 3543                 if (!f->conf.use_ino && f->conf.readdir_ino) {
 
 3544                         e.
attr.st_ino = (ino_t)
 
 3545                                 lookup_nodeid(f, dh->nodeid, name);
 
 3561                 if (extend_contents(dh, dh->needlen) == -1)
 
 3566                                                dh->needlen - dh->len, name,
 
 3568                 if (newlen > dh->needlen)
 
 3574                 if (fuse_add_direntry_to_dh(dh, name, &e.
attr) == -1)
 
 3581 static void free_direntries(
struct fuse_direntry *de)
 
 3584                 struct fuse_direntry *next = de->next;
 
 3592                         size_t size, off_t off, 
struct fuse_dh *dh,
 
 3599         if (f->fs->op.readdir)
 
 3600                 err = get_path_nullok(f, ino, &path);
 
 3602                 err = get_path(f, ino, &path);
 
 3604                 struct fuse_intr_data d;
 
 3608                         filler = fill_dir_plus;
 
 3610                 free_direntries(dh->first);
 
 3612                 dh->last = &dh->first;
 
 3618                 fuse_prepare_interrupt(f, req, &d);
 
 3619                 err = fuse_fs_readdir(f->fs, path, dh, filler, off, fi, flags);
 
 3620                 fuse_finish_interrupt(f, req, &d);
 
 3626                 free_path(f, ino, path);
 
 3631 static int readdir_fill_from_list(
fuse_req_t req, 
struct fuse_dh *dh,
 
 3635         struct fuse_direntry *de = dh->first;
 
 3639         if (extend_contents(dh, dh->needlen) == -1)
 
 3642         for (pos = 0; pos < off; pos++) {
 
 3649                 char *p = dh->contents + dh->len;
 
 3650                 unsigned rem = dh->needlen - dh->len;
 
 3664                                                     de->name, &de->stat, pos);
 
 3666                 newlen = dh->len + thislen;
 
 3667                 if (newlen > dh->needlen)
 
 3679         struct fuse *f = req_fuse_prepare(req);
 
 3681         struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3684         pthread_mutex_lock(&dh->lock);
 
 3691                 err = readdir_fill(f, req, ino, size, off, dh, &fi, flags);
 
 3693                         reply_err(req, err);
 
 3699                 err = readdir_fill_from_list(req, dh, off, flags);
 
 3701                         reply_err(req, err);
 
 3707         pthread_mutex_unlock(&dh->lock);
 
 3713         fuse_readdir_common(req, ino, size, off, llfi, 0);
 
 3725         struct fuse *f = req_fuse_prepare(req);
 
 3726         struct fuse_intr_data d;
 
 3728         struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3731         get_path_nullok(f, ino, &path);
 
 3733         fuse_prepare_interrupt(f, req, &d);
 
 3734         fuse_fs_releasedir(f->fs, path, &fi);
 
 3735         fuse_finish_interrupt(f, req, &d);
 
 3736         free_path(f, ino, path);
 
 3738         pthread_mutex_lock(&dh->lock);
 
 3739         pthread_mutex_unlock(&dh->lock);
 
 3740         pthread_mutex_destroy(&dh->lock);
 
 3741         free_direntries(dh->first);
 
 3750         struct fuse *f = req_fuse_prepare(req);
 
 3755         get_dirhandle(llfi, &fi);
 
 3757         err = get_path_nullok(f, ino, &path);
 
 3759                 struct fuse_intr_data d;
 
 3760                 fuse_prepare_interrupt(f, req, &d);
 
 3761                 err = fuse_fs_fsyncdir(f->fs, path, datasync, &fi);
 
 3762                 fuse_finish_interrupt(f, req, &d);
 
 3763                 free_path(f, ino, path);
 
 3765         reply_err(req, err);
 
 3770         struct fuse *f = req_fuse_prepare(req);
 
 3775         memset(&buf, 0, 
sizeof(buf));
 
 3777                 err = get_path(f, ino, &path);
 
 3780                 struct fuse_intr_data d;
 
 3781                 fuse_prepare_interrupt(f, req, &d);
 
 3782                 err = fuse_fs_statfs(f->fs, path ? path : 
"/", &buf);
 
 3783                 fuse_finish_interrupt(f, req, &d);
 
 3784                 free_path(f, ino, path);
 
 3790                 reply_err(req, err);
 
 3794                               const char *value, 
size_t size, 
int flags)
 
 3796         struct fuse *f = req_fuse_prepare(req);
 
 3800         err = get_path(f, ino, &path);
 
 3802                 struct fuse_intr_data d;
 
 3803                 fuse_prepare_interrupt(f, req, &d);
 
 3804                 err = fuse_fs_setxattr(f->fs, path, name, value, size, flags);
 
 3805                 fuse_finish_interrupt(f, req, &d);
 
 3806                 free_path(f, ino, path);
 
 3808         reply_err(req, err);
 
 3812                            const char *name, 
char *value, 
size_t size)
 
 3817         err = get_path(f, ino, &path);
 
 3819                 struct fuse_intr_data d;
 
 3820                 fuse_prepare_interrupt(f, req, &d);
 
 3821                 err = fuse_fs_getxattr(f->fs, path, name, value, size);
 
 3822                 fuse_finish_interrupt(f, req, &d);
 
 3823                 free_path(f, ino, path);
 
 3831         struct fuse *f = req_fuse_prepare(req);
 
 3835                 char *value = (
char *) malloc(size);
 
 3836                 if (value == NULL) {
 
 3837                         reply_err(req, -ENOMEM);
 
 3840                 res = common_getxattr(f, req, ino, name, value, size);
 
 3844                         reply_err(req, res);
 
 3847                 res = common_getxattr(f, req, ino, name, NULL, 0);
 
 3851                         reply_err(req, res);
 
 3856                             char *list, 
size_t size)
 
 3861         err = get_path(f, ino, &path);
 
 3863                 struct fuse_intr_data d;
 
 3864                 fuse_prepare_interrupt(f, req, &d);
 
 3865                 err = fuse_fs_listxattr(f->fs, path, list, size);
 
 3866                 fuse_finish_interrupt(f, req, &d);
 
 3867                 free_path(f, ino, path);
 
 3874         struct fuse *f = req_fuse_prepare(req);
 
 3878                 char *list = (
char *) malloc(size);
 
 3880                         reply_err(req, -ENOMEM);
 
 3883                 res = common_listxattr(f, req, ino, list, size);
 
 3887                         reply_err(req, res);
 
 3890                 res = common_listxattr(f, req, ino, NULL, 0);
 
 3894                         reply_err(req, res);
 
 3901         struct fuse *f = req_fuse_prepare(req);
 
 3905         err = get_path(f, ino, &path);
 
 3907                 struct fuse_intr_data d;
 
 3908                 fuse_prepare_interrupt(f, req, &d);
 
 3909                 err = fuse_fs_removexattr(f->fs, path, name);
 
 3910                 fuse_finish_interrupt(f, req, &d);
 
 3911                 free_path(f, ino, path);
 
 3913         reply_err(req, err);
 
 3916 static struct lock *locks_conflict(
struct node *node, 
const struct lock *lock)
 
 3920         for (l = node->locks; l; l = l->next)
 
 3921                 if (l->owner != lock->owner &&
 
 3922                     lock->start <= l->end && l->start <= lock->end &&
 
 3923                     (l->type == F_WRLCK || lock->type == F_WRLCK))
 
 3929 static void delete_lock(
struct lock **lockp)
 
 3931         struct lock *l = *lockp;
 
 3936 static void insert_lock(
struct lock **pos, 
struct lock *lock)
 
 3942 static int locks_insert(
struct node *node, 
struct lock *lock)
 
 3945         struct lock *newl1 = NULL;
 
 3946         struct lock *newl2 = NULL;
 
 3948         if (lock->type != F_UNLCK || lock->start != 0 ||
 
 3949             lock->end != OFFSET_MAX) {
 
 3950                 newl1 = malloc(
sizeof(
struct lock));
 
 3951                 newl2 = malloc(
sizeof(
struct lock));
 
 3953                 if (!newl1 || !newl2) {
 
 3960         for (lp = &node->locks; *lp;) {
 
 3961                 struct lock *l = *lp;
 
 3962                 if (l->owner != lock->owner)
 
 3965                 if (lock->type == l->type) {
 
 3966                         if (l->end < lock->start - 1)
 
 3968                         if (lock->end < l->start - 1)
 
 3970                         if (l->start <= lock->start && lock->end <= l->end)
 
 3972                         if (l->start < lock->start)
 
 3973                                 lock->start = l->start;
 
 3974                         if (lock->end < l->end)
 
 3978                         if (l->end < lock->start)
 
 3980                         if (lock->end < l->start)
 
 3982                         if (lock->start <= l->start && l->end <= lock->end)
 
 3984                         if (l->end <= lock->end) {
 
 3985                                 l->end = lock->start - 1;
 
 3988                         if (lock->start <= l->start) {
 
 3989                                 l->start = lock->end + 1;
 
 3993                         newl2->start = lock->end + 1;
 
 3994                         l->end = lock->start - 1;
 
 3995                         insert_lock(&l->next, newl2);
 
 4005         if (lock->type != F_UNLCK) {
 
 4007                 insert_lock(lp, newl1);
 
 4016 static void flock_to_lock(
struct flock *flock, 
struct lock *lock)
 
 4018         memset(lock, 0, 
sizeof(
struct lock));
 
 4019         lock->type = flock->l_type;
 
 4020         lock->start = flock->l_start;
 
 4022                 flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX;
 
 4023         lock->pid = flock->l_pid;
 
 4026 static void lock_to_flock(
struct lock *lock, 
struct flock *flock)
 
 4028         flock->l_type = lock->type;
 
 4029         flock->l_start = lock->start;
 
 4031                 (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1;
 
 4032         flock->l_pid = lock->pid;
 
 4038         struct fuse_intr_data d;
 
 4044         fuse_prepare_interrupt(f, req, &d);
 
 4045         memset(&lock, 0, 
sizeof(lock));
 
 4046         lock.l_type = F_UNLCK;
 
 4047         lock.l_whence = SEEK_SET;
 
 4048         err = fuse_fs_flush(f->fs, path, fi);
 
 4049         errlock = fuse_fs_lock(f->fs, path, fi, F_SETLK, &lock);
 
 4050         fuse_finish_interrupt(f, req, &d);
 
 4052         if (errlock != -ENOSYS) {
 
 4053                 flock_to_lock(&lock, &l);
 
 4055                 pthread_mutex_lock(&f->lock);
 
 4056                 locks_insert(get_node(f, ino), &l);
 
 4057                 pthread_mutex_unlock(&f->lock);
 
 4070         struct fuse *f = req_fuse_prepare(req);
 
 4071         struct fuse_intr_data d;
 
 4075         get_path_nullok(f, ino, &path);
 
 4077                 err = fuse_flush_common(f, req, ino, path, fi);
 
 4082         fuse_prepare_interrupt(f, req, &d);
 
 4083         fuse_do_release(f, ino, path, fi);
 
 4084         fuse_finish_interrupt(f, req, &d);
 
 4085         free_path(f, ino, path);
 
 4087         reply_err(req, err);
 
 4093         struct fuse *f = req_fuse_prepare(req);
 
 4097         get_path_nullok(f, ino, &path);
 
 4098         err = fuse_flush_common(f, req, ino, path, fi);
 
 4099         free_path(f, ino, path);
 
 4101         reply_err(req, err);
 
 4108         struct fuse *f = req_fuse_prepare(req);
 
 4112         err = get_path_nullok(f, ino, &path);
 
 4114                 struct fuse_intr_data d;
 
 4115                 fuse_prepare_interrupt(f, req, &d);
 
 4116                 err = fuse_fs_lock(f->fs, path, fi, cmd, lock);
 
 4117                 fuse_finish_interrupt(f, req, &d);
 
 4118                 free_path(f, ino, path);
 
 4128         struct lock *conflict;
 
 4129         struct fuse *f = req_fuse(req);
 
 4131         flock_to_lock(lock, &l);
 
 4133         pthread_mutex_lock(&f->lock);
 
 4134         conflict = locks_conflict(get_node(f, ino), &l);
 
 4136                 lock_to_flock(conflict, lock);
 
 4137         pthread_mutex_unlock(&f->lock);
 
 4139                 err = fuse_lock_common(req, ino, fi, lock, F_GETLK);
 
 4146                 reply_err(req, err);
 
 4153         int err = fuse_lock_common(req, ino, fi, lock,
 
 4154                                    sleep ? F_SETLKW : F_SETLK);
 
 4156                 struct fuse *f = req_fuse(req);
 
 4158                 flock_to_lock(lock, &l);
 
 4160                 pthread_mutex_lock(&f->lock);
 
 4161                 locks_insert(get_node(f, ino), &l);
 
 4162                 pthread_mutex_unlock(&f->lock);
 
 4164         reply_err(req, err);
 
 4170         struct fuse *f = req_fuse_prepare(req);
 
 4174         err = get_path_nullok(f, ino, &path);
 
 4176                 struct fuse_intr_data d;
 
 4177                 fuse_prepare_interrupt(f, req, &d);
 
 4178                 err = fuse_fs_flock(f->fs, path, fi, op);
 
 4179                 fuse_finish_interrupt(f, req, &d);
 
 4180                 free_path(f, ino, path);
 
 4182         reply_err(req, err);
 
 4188         struct fuse *f = req_fuse_prepare(req);
 
 4189         struct fuse_intr_data d;
 
 4193         err = get_path(f, ino, &path);
 
 4195                 fuse_prepare_interrupt(f, req, &d);
 
 4196                 err = fuse_fs_bmap(f->fs, path, blocksize, &idx);
 
 4197                 fuse_finish_interrupt(f, req, &d);
 
 4198                 free_path(f, ino, path);
 
 4203                 reply_err(req, err);
 
 4208                            unsigned int flags, 
const void *in_buf,
 
 4209                            size_t in_bufsz, 
size_t out_bufsz)
 
 4211         struct fuse *f = req_fuse_prepare(req);
 
 4212         struct fuse_intr_data d;
 
 4214         char *path, *out_buf = NULL;
 
 4218         if (
flags & FUSE_IOCTL_UNRESTRICTED)
 
 4221         if (
flags & FUSE_IOCTL_DIR)
 
 4222                 get_dirhandle(llfi, &fi);
 
 4228                 out_buf = malloc(out_bufsz);
 
 4233         assert(!in_bufsz || !out_bufsz || in_bufsz == out_bufsz);
 
 4234         if (out_buf && in_bufsz)
 
 4235                 memcpy(out_buf, in_buf, in_bufsz);
 
 4237         err = get_path_nullok(f, ino, &path);
 
 4241         fuse_prepare_interrupt(f, req, &d);
 
 4243         err = fuse_fs_ioctl(f->fs, path, cmd, arg, &fi, 
flags,
 
 4244                             out_buf ? out_buf : (
void *)in_buf);
 
 4246         fuse_finish_interrupt(f, req, &d);
 
 4247         free_path(f, ino, path);
 
 4254         reply_err(req, err);
 
 4262         struct fuse *f = req_fuse_prepare(req);
 
 4263         struct fuse_intr_data d;
 
 4266         unsigned revents = 0;
 
 4268         err = get_path_nullok(f, ino, &path);
 
 4270                 fuse_prepare_interrupt(f, req, &d);
 
 4271                 err = fuse_fs_poll(f->fs, path, fi, ph, &revents);
 
 4272                 fuse_finish_interrupt(f, req, &d);
 
 4273                 free_path(f, ino, path);
 
 4278                 reply_err(req, err);
 
 4284         struct fuse *f = req_fuse_prepare(req);
 
 4285         struct fuse_intr_data d;
 
 4289         err = get_path_nullok(f, ino, &path);
 
 4291                 fuse_prepare_interrupt(f, req, &d);
 
 4292                 err = fuse_fs_fallocate(f->fs, path, mode, offset, length, fi);
 
 4293                 fuse_finish_interrupt(f, req, &d);
 
 4294                 free_path(f, ino, path);
 
 4296         reply_err(req, err);
 
 4305         struct fuse *f = req_fuse_prepare(req);
 
 4306         struct fuse_intr_data d;
 
 4307         char *path_in, *path_out;
 
 4311         err = get_path_nullok(f, nodeid_in, &path_in);
 
 4313                 reply_err(req, err);
 
 4317         err = get_path_nullok(f, nodeid_out, &path_out);
 
 4319                 free_path(f, nodeid_in, path_in);
 
 4320                 reply_err(req, err);
 
 4324         fuse_prepare_interrupt(f, req, &d);
 
 4325         res = fuse_fs_copy_file_range(f->fs, path_in, fi_in, off_in, path_out,
 
 4326                                       fi_out, off_out, len, flags);
 
 4327         fuse_finish_interrupt(f, req, &d);
 
 4332                 reply_err(req, res);
 
 4334         free_path(f, nodeid_in, path_in);
 
 4335         free_path(f, nodeid_out, path_out);
 
 4341         struct fuse *f = req_fuse_prepare(req);
 
 4342         struct fuse_intr_data d;
 
 4347         err = get_path(f, ino, &path);
 
 4349                 reply_err(req, err);
 
 4353         fuse_prepare_interrupt(f, req, &d);
 
 4354         res = fuse_fs_lseek(f->fs, path, off, whence, fi);
 
 4355         fuse_finish_interrupt(f, req, &d);
 
 4356         free_path(f, ino, path);
 
 4360                 reply_err(req, res);
 
 4363 static int clean_delay(
struct fuse *f)
 
 4371         int max_sleep = 3600;
 
 4372         int sleep_time = f->conf.remember / 10;
 
 4374         if (sleep_time > max_sleep)
 
 4376         if (sleep_time < min_sleep)
 
 4383         struct node_lru *lnode;
 
 4384         struct list_head *curr, *next;
 
 4386         struct timespec now;
 
 4388         pthread_mutex_lock(&f->lock);
 
 4392         for (curr = f->lru_table.next; curr != &f->lru_table; curr = next) {
 
 4396                 lnode = list_entry(curr, 
struct node_lru, lru);
 
 4397                 node = &lnode->node;
 
 4399                 age = diff_timespec(&now, &lnode->forget_time);
 
 4400                 if (age <= f->conf.remember)
 
 4403                 assert(node->nlookup == 1);
 
 4406                 if (node->refctr > 1)
 
 4410                 unhash_name(f, node);
 
 4411                 unref_node(f, node);
 
 4413         pthread_mutex_unlock(&f->lock);
 
 4415         return clean_delay(f);
 
 4419         .
init = fuse_lib_init,
 
 4420         .destroy = fuse_lib_destroy,
 
 4421         .lookup = fuse_lib_lookup,
 
 4422         .forget = fuse_lib_forget,
 
 4423         .forget_multi = fuse_lib_forget_multi,
 
 4424         .getattr = fuse_lib_getattr,
 
 4425         .setattr = fuse_lib_setattr,
 
 4426         .access = fuse_lib_access,
 
 4427         .readlink = fuse_lib_readlink,
 
 4428         .mknod = fuse_lib_mknod,
 
 4429         .mkdir = fuse_lib_mkdir,
 
 4430         .unlink = fuse_lib_unlink,
 
 4431         .rmdir = fuse_lib_rmdir,
 
 4432         .symlink = fuse_lib_symlink,
 
 4433         .rename = fuse_lib_rename,
 
 4434         .link = fuse_lib_link,
 
 4435         .create = fuse_lib_create,
 
 4436         .open = fuse_lib_open,
 
 4437         .read = fuse_lib_read,
 
 4438         .write_buf = fuse_lib_write_buf,
 
 4439         .flush = fuse_lib_flush,
 
 4440         .release = fuse_lib_release,
 
 4441         .fsync = fuse_lib_fsync,
 
 4442         .opendir = fuse_lib_opendir,
 
 4443         .readdir = fuse_lib_readdir,
 
 4444         .readdirplus = fuse_lib_readdirplus,
 
 4445         .releasedir = fuse_lib_releasedir,
 
 4446         .fsyncdir = fuse_lib_fsyncdir,
 
 4447         .statfs = fuse_lib_statfs,
 
 4448         .setxattr = fuse_lib_setxattr,
 
 4449         .getxattr = fuse_lib_getxattr,
 
 4450         .listxattr = fuse_lib_listxattr,
 
 4451         .removexattr = fuse_lib_removexattr,
 
 4452         .getlk = fuse_lib_getlk,
 
 4453         .setlk = fuse_lib_setlk,
 
 4454         .flock = fuse_lib_flock,
 
 4455         .bmap = fuse_lib_bmap,
 
 4456         .ioctl = fuse_lib_ioctl,
 
 4457         .poll = fuse_lib_poll,
 
 4458         .fallocate = fuse_lib_fallocate,
 
 4459         .copy_file_range = fuse_lib_copy_file_range,
 
 4460         .lseek = fuse_lib_lseek,
 
 4463 int fuse_notify_poll(
struct fuse_pollhandle *ph)
 
 4473 static int fuse_session_loop_remember(
struct fuse *f)
 
 4475         struct fuse_session *se = f->se;
 
 4477         struct timespec now;
 
 4479         struct pollfd fds = {
 
 4488         next_clean = now.tv_sec;
 
 4493                 if (now.tv_sec < next_clean)
 
 4494                         timeout = next_clean - now.tv_sec;
 
 4498                 res = poll(&fds, 1, timeout * 1000);
 
 4504                 } 
else if (res > 0) {
 
 4505                         res = fuse_session_receive_buf_int(se, &fbuf, NULL);
 
 4512                         fuse_session_process_buf_int(se, &fbuf, NULL);
 
 4516                         next_clean = now.tv_sec + timeout;
 
 4522         return res < 0 ? -1 : 0;
 
 4531                 return fuse_session_loop_remember(f);
 
 4536 FUSE_SYMVER(
"fuse_loop_mt_312", 
"fuse_loop_mt@@FUSE_3.12")
 
 4551 int fuse_loop_mt_32(
struct fuse *f, 
struct fuse_loop_config_v1 *config_v1);
 
 4552 FUSE_SYMVER(
"fuse_loop_mt_32", 
"fuse_loop_mt@FUSE_3.2")
 
 4553 int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config_v1 *config_v1)
 
 4561         int res = fuse_loop_mt_312(f, config);
 
 4568 int fuse_loop_mt_31(
struct fuse *f, 
int clone_fd);
 
 4569 FUSE_SYMVER(
"fuse_loop_mt_31", 
"fuse_loop_mt@FUSE_3.0")
 
 4570 int fuse_loop_mt_31(struct fuse *f, 
int clone_fd)
 
 4580         err = fuse_loop_mt_312(f, config);
 
 4594         struct fuse_context_i *c = fuse_get_context_internal();
 
 4604         struct fuse_context_i *c = fuse_get_context_internal();
 
 4613         struct fuse_context_i *c = fuse_get_context_internal();
 
 4623         int err = lookup_path_in_cache(f, path, &ino);
 
 4631 #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } 
 4633 static const struct fuse_opt fuse_lib_opts[] = {
 
 4636         FUSE_LIB_OPT(
"debug",                 debug, 1),
 
 4637         FUSE_LIB_OPT(
"-d",                    debug, 1),
 
 4638         FUSE_LIB_OPT(
"kernel_cache",          kernel_cache, 1),
 
 4639         FUSE_LIB_OPT(
"auto_cache",            auto_cache, 1),
 
 4640         FUSE_LIB_OPT(
"noauto_cache",          auto_cache, 0),
 
 4641         FUSE_LIB_OPT(
"no_rofd_flush",         no_rofd_flush, 1),
 
 4642         FUSE_LIB_OPT(
"umask=",                set_mode, 1),
 
 4643         FUSE_LIB_OPT(
"umask=%o",              umask, 0),
 
 4644         FUSE_LIB_OPT(
"uid=",                  set_uid, 1),
 
 4645         FUSE_LIB_OPT(
"uid=%d",                uid, 0),
 
 4646         FUSE_LIB_OPT(
"gid=",                  set_gid, 1),
 
 4647         FUSE_LIB_OPT(
"gid=%d",                gid, 0),
 
 4648         FUSE_LIB_OPT(
"entry_timeout=%lf",     entry_timeout, 0),
 
 4649         FUSE_LIB_OPT(
"attr_timeout=%lf",      attr_timeout, 0),
 
 4650         FUSE_LIB_OPT(
"ac_attr_timeout=%lf",   ac_attr_timeout, 0),
 
 4651         FUSE_LIB_OPT(
"ac_attr_timeout=",      ac_attr_timeout_set, 1),
 
 4652         FUSE_LIB_OPT(
"negative_timeout=%lf",  negative_timeout, 0),
 
 4653         FUSE_LIB_OPT(
"noforget",              remember, -1),
 
 4654         FUSE_LIB_OPT(
"remember=%u",           remember, 0),
 
 4655         FUSE_LIB_OPT(
"modules=%s",            modules, 0),
 
 4659 static int fuse_lib_opt_proc(
void *data, 
const char *arg, 
int key,
 
 4662         (void) arg; (void) outargs; (void) data; (void) key;
 
 4669 static const struct fuse_opt fuse_help_opts[] = {
 
 4670         FUSE_LIB_OPT(
"modules=%s", modules, 1),
 
 4675 static void print_module_help(
const char *name,
 
 4682         printf(
"\nOptions for %s module:\n", name);
 
 4692 "    -o kernel_cache        cache files in kernel\n" 
 4693 "    -o [no]auto_cache      enable caching based on modification times (off)\n" 
 4694 "    -o no_rofd_flush       disable flushing of read-only fd on close (off)\n" 
 4695 "    -o umask=M             set file permissions (octal)\n" 
 4696 "    -o uid=N               set file owner\n" 
 4697 "    -o gid=N               set file group\n" 
 4698 "    -o entry_timeout=T     cache timeout for names (1.0s)\n" 
 4699 "    -o negative_timeout=T  cache timeout for deleted names (0.0s)\n" 
 4700 "    -o attr_timeout=T      cache timeout for attributes (1.0s)\n" 
 4701 "    -o ac_attr_timeout=T   auto cache timeout for attributes (attr_timeout)\n" 
 4702 "    -o noforget            never forget cached inodes\n" 
 4703 "    -o remember=T          remember cached inodes for T seconds (0s)\n" 
 4704 "    -o modules=M1[:M2...]  names of modules to push onto filesystem stack\n");
 
 4711         print_module_help(
"subdir", &fuse_module_subdir_factory);
 
 4713         print_module_help(
"iconv", &fuse_module_iconv_factory);
 
 4720                            fuse_lib_opt_proc) == -1
 
 4729         for (module = conf.modules; module; module = next) {
 
 4731                 for (p = module; *p && *p != 
':'; p++);
 
 4732                 next = *p ? p + 1 : NULL;
 
 4735                 m = fuse_get_module(module);
 
 4737                         print_module_help(module, &m->factory);
 
 4743 static int fuse_init_intr_signal(
int signum, 
int *installed)
 
 4745         struct sigaction old_sa;
 
 4747         if (sigaction(signum, NULL, &old_sa) == -1) {
 
 4748                 perror(
"fuse: cannot get old signal handler");
 
 4752         if (old_sa.sa_handler == SIG_DFL) {
 
 4753                 struct sigaction sa;
 
 4755                 memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4756                 sa.sa_handler = fuse_intr_sighandler;
 
 4757                 sigemptyset(&sa.sa_mask);
 
 4759                 if (sigaction(signum, &sa, NULL) == -1) {
 
 4760                         perror(
"fuse: cannot set interrupt signal handler");
 
 4768 static void fuse_restore_intr_signal(
int signum)
 
 4770         struct sigaction sa;
 
 4772         memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4773         sa.sa_handler = SIG_DFL;
 
 4774         sigaction(signum, &sa, NULL);
 
 4778 static int fuse_push_module(
struct fuse *f, 
const char *module,
 
 4781         struct fuse_fs *fs[2] = { f->fs, NULL };
 
 4782         struct fuse_fs *newfs;
 
 4788         newfs = m->factory(args, fs);
 
 4803                 fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not not work\n");
 
 4807         fs = (
struct fuse_fs *) calloc(1, 
sizeof(
struct fuse_fs));
 
 4809                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse_fs object\n");
 
 4813         fs->user_data = user_data;
 
 4815                 memcpy(&fs->op, op, op_size);
 
 4819 static int node_table_init(
struct node_table *t)
 
 4821         t->size = NODE_TABLE_MIN_SIZE;
 
 4822         t->array = (
struct node **) calloc(1, 
sizeof(
struct node *) * t->size);
 
 4823         if (t->array == NULL) {
 
 4824                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 4833 static void *fuse_prune_nodes(
void *fuse)
 
 4835         struct fuse *f = fuse;
 
 4848                 return fuse_start_thread(&f->prune_thread, fuse_prune_nodes, f);
 
 4855         if (lru_enabled(f)) {
 
 4856                 pthread_mutex_lock(&f->lock);
 
 4857                 pthread_cancel(f->prune_thread);
 
 4858                 pthread_mutex_unlock(&f->lock);
 
 4859                 pthread_join(f->prune_thread, NULL);
 
 4864 FUSE_SYMVER(
"fuse_new_31", 
"fuse_new@@FUSE_3.1")
 
 4867                       size_t op_size, 
void *user_data)
 
 4874         f = (
struct fuse *) calloc(1, 
sizeof(
struct fuse));
 
 4876                 fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse object\n");
 
 4880         f->conf.entry_timeout = 1.0;
 
 4881         f->conf.attr_timeout = 1.0;
 
 4882         f->conf.negative_timeout = 0.0;
 
 4883         f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL;
 
 4887                            fuse_lib_opt_proc) == -1)
 
 4890         pthread_mutex_lock(&fuse_context_lock);
 
 4891         static int builtin_modules_registered = 0;
 
 4893         if (builtin_modules_registered == 0) {
 
 4895                 fuse_register_module(
"subdir", fuse_module_subdir_factory, NULL);
 
 4897                 fuse_register_module(
"iconv", fuse_module_iconv_factory, NULL);
 
 4899                 builtin_modules_registered= 1;
 
 4901         pthread_mutex_unlock(&fuse_context_lock);
 
 4903         if (fuse_create_context_key() == -1)
 
 4908                 goto out_delete_context_key;
 
 4918         f->pagesize = getpagesize();
 
 4919         init_list_head(&f->partial_slabs);
 
 4920         init_list_head(&f->full_slabs);
 
 4921         init_list_head(&f->lru_table);
 
 4923         if (f->conf.modules) {
 
 4927                 for (module = f->conf.modules; module; module = next) {
 
 4929                         for (p = module; *p && *p != 
':'; p++);
 
 4930                         next = *p ? p + 1 : NULL;
 
 4933                             fuse_push_module(f, module, args) == -1)
 
 4938         if (!f->conf.ac_attr_timeout_set)
 
 4939                 f->conf.ac_attr_timeout = f->conf.attr_timeout;
 
 4941 #if defined(__FreeBSD__) || defined(__NetBSD__) 
 4946         f->conf.readdir_ino = 1;
 
 4953         if (f->conf.debug) {
 
 4954                 fuse_log(FUSE_LOG_DEBUG, 
"nullpath_ok: %i\n", f->conf.nullpath_ok);
 
 4958         f->fs->debug = f->conf.debug;
 
 4961         if (node_table_init(&f->name_table) == -1)
 
 4962                 goto out_free_session;
 
 4964         if (node_table_init(&f->id_table) == -1)
 
 4965                 goto out_free_name_table;
 
 4967         pthread_mutex_init(&f->lock, NULL);
 
 4969         root = alloc_node(f);
 
 4971                 fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 4972                 goto out_free_id_table;
 
 4974         if (lru_enabled(f)) {
 
 4975                 struct node_lru *lnode = node_lru(root);
 
 4976                 init_list_head(&lnode->lru);
 
 4979         strcpy(root->inline_name, 
"/");
 
 4980         root->name = root->inline_name;
 
 4983             fuse_init_intr_signal(f->conf.intr_signal,
 
 4984                                   &f->intr_installed) == -1)
 
 4987         root->parent = NULL;
 
 4997         free(f->id_table.array);
 
 4998 out_free_name_table:
 
 4999         free(f->name_table.array);
 
 5004         free(f->conf.modules);
 
 5005 out_delete_context_key:
 
 5006         fuse_delete_context_key();
 
 5015                          size_t op_size, 
void *private_data);
 
 5016 FUSE_SYMVER(
"fuse_new_30", 
"fuse_new@FUSE_3.0")
 
 5017 struct fuse *fuse_new_30(struct 
fuse_args *args,
 
 5019                          size_t op_size, 
void *user_data)
 
 5023         memset(&conf, 0, 
sizeof(conf));
 
 5026                 FUSE_LIB_OPT(
"-h", show_help, 1),
 
 5027                 FUSE_LIB_OPT(
"--help", show_help, 1),
 
 5032                            fuse_lib_opt_proc) == -1)
 
 5035         if (conf.show_help) {
 
 5046         if (f->conf.intr && f->intr_installed)
 
 5047                 fuse_restore_intr_signal(f->conf.intr_signal);
 
 5050                 fuse_create_context(f);
 
 5052                 for (i = 0; i < f->id_table.size; i++) {
 
 5055                         for (node = f->id_table.array[i]; node != NULL;
 
 5056                              node = node->id_next) {
 
 5057                                 if (node->is_hidden) {
 
 5059                                         if (try_get_path(f, node->nodeid, NULL, &path, NULL, 
false) == 0) {
 
 5060                                                 fuse_fs_unlink(f->fs, path);
 
 5067         for (i = 0; i < f->id_table.size; i++) {
 
 5071                 for (node = f->id_table.array[i]; node != NULL; node = next) {
 
 5072                         next = node->id_next;
 
 5077         assert(list_empty(&f->partial_slabs));
 
 5078         assert(list_empty(&f->full_slabs));
 
 5080         while (fuse_modules) {
 
 5081                 fuse_put_module(fuse_modules);
 
 5083         free(f->id_table.array);
 
 5084         free(f->name_table.array);
 
 5085         pthread_mutex_destroy(&f->lock);
 
 5087         free(f->conf.modules);
 
 5089         fuse_delete_context_key();
 
 5103         return FUSE_VERSION;
 
 5108         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
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)