14#include "fuse_config.h" 
   16#include "fuse_lowlevel.h" 
   19#include "fuse_kernel.h" 
   41#define FUSE_NODE_SLAB 1 
   47#ifndef RENAME_EXCHANGE 
   48#define RENAME_EXCHANGE         (1 << 1)         
   51#define FUSE_DEFAULT_INTR_SIGNAL SIGUSR1 
   53#define FUSE_UNKNOWN_INO 0xffffffff 
   54#define OFFSET_MAX 0x7fffffffffffffffLL 
   56#define NODE_TABLE_MIN_SIZE 8192 
   69struct lock_queue_element {
 
   70        struct lock_queue_element *next;
 
   91#define container_of(ptr, type, member) ({                              \ 
   92                        const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 
   93                        (type *)( (char *)__mptr - offsetof(type,member) );}) 
   95#define list_entry(ptr, type, member)           \ 
   96        container_of(ptr, type, member) 
   99        struct list_head *next;
 
  100        struct list_head *prev;
 
  104        struct list_head list;  
 
  105        struct list_head freelist;
 
  110        struct fuse_session *se;
 
  111        struct node_table name_table;
 
  112        struct node_table id_table;
 
  113        struct list_head lru_table;
 
  115        unsigned int generation;
 
  116        unsigned int hidectr;
 
  117        pthread_mutex_t lock;
 
  121        struct lock_queue_element *lockq;
 
  123        struct list_head partial_slabs;
 
  124        struct list_head full_slabs;
 
  125        pthread_t prune_thread;
 
  138        struct node *name_next;
 
  139        struct node *id_next;
 
  141        unsigned int generation;
 
  147        struct timespec stat_updated;
 
  148        struct timespec mtime;
 
  151        unsigned int is_hidden : 1;
 
  152        unsigned int cache_valid : 1;
 
  154        char inline_name[32];
 
  157#define TREELOCK_WRITE -1 
  158#define TREELOCK_WAIT_OFFSET INT_MIN 
  162        struct list_head lru;
 
  163        struct timespec forget_time;
 
  166struct fuse_direntry {
 
  170        struct fuse_direntry *next;
 
  174        pthread_mutex_t lock;
 
  178        struct fuse_direntry *first;
 
  179        struct fuse_direntry **last;
 
  189struct fuse_context_i {
 
  200static pthread_key_t fuse_context_key;
 
  201static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER;
 
  202static int fuse_context_ref;
 
  205static int fuse_register_module(
const char *name,
 
  207                                struct fusemod_so *so)
 
  213                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module\n");
 
  216        mod->name = strdup(name);
 
  218                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module name\n");
 
  222        mod->factory = factory;
 
  227        mod->next = fuse_modules;
 
  233static void fuse_unregister_module(
struct fuse_module *m)
 
  236        for (mp = &fuse_modules; *mp; mp = &(*mp)->next) {
 
  246static int fuse_load_so_module(
const char *module)
 
  250        struct fusemod_so *so;
 
  253        tmp = malloc(strlen(module) + 64);
 
  255                fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
  258        sprintf(tmp, 
"libfusemod_%s.so", module);
 
  259        so = calloc(1, 
sizeof(
struct fusemod_so));
 
  261                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate module so\n");
 
  265        so->handle = dlopen(tmp, RTLD_NOW);
 
  266        if (so->handle == NULL) {
 
  267                fuse_log(FUSE_LOG_ERR, 
"fuse: dlopen(%s) failed: %s\n",
 
  272        sprintf(tmp, 
"fuse_module_%s_factory", module);
 
  274        if (factory == NULL) {
 
  275                fuse_log(FUSE_LOG_ERR, 
"fuse: symbol <%s> not found in module: %s\n",
 
  279        ret = fuse_register_module(module, *factory, so);
 
  294static struct fuse_module *fuse_find_module(
const char *module)
 
  297        for (m = fuse_modules; m; m = m->next) {
 
  298                if (strcmp(module, m->name) == 0) {
 
  306static struct fuse_module *fuse_get_module(
const char *module)
 
  310        pthread_mutex_lock(&fuse_context_lock);
 
  311        m = fuse_find_module(module);
 
  313                int err = fuse_load_so_module(module);
 
  315                        m = fuse_find_module(module);
 
  317        pthread_mutex_unlock(&fuse_context_lock);
 
  323        pthread_mutex_lock(&fuse_context_lock);
 
  329        if (!m->ctr && m->so) {
 
  330                struct fusemod_so *so = m->so;
 
  335                        for (mp = &fuse_modules; *mp;) {
 
  337                                        fuse_unregister_module(*mp);
 
  344        } 
else if (!m->ctr) {
 
  345                fuse_unregister_module(m);
 
  347        pthread_mutex_unlock(&fuse_context_lock);
 
  350static void init_list_head(
struct list_head *list)
 
  356static int list_empty(
const struct list_head *head)
 
  358        return head->next == head;
 
  361static void list_add(
struct list_head *
new, 
struct list_head *prev,
 
  362                     struct list_head *next)
 
  370static inline void list_add_head(
struct list_head *
new, 
struct list_head *head)
 
  372        list_add(
new, head, head->next);
 
  375static inline void list_add_tail(
struct list_head *
new, 
struct list_head *head)
 
  377        list_add(
new, head->prev, head);
 
  380static inline void list_del(
struct list_head *entry)
 
  382        struct list_head *prev = entry->prev;
 
  383        struct list_head *next = entry->next;
 
  389static inline int lru_enabled(
struct fuse *f)
 
  391        return f->conf.remember > 0;
 
  394static struct node_lru *node_lru(
struct node *node)
 
  396        return (
struct node_lru *) node;
 
  399static size_t get_node_size(
struct fuse *f)
 
  402                return sizeof(
struct node_lru);
 
  404                return sizeof(
struct node);
 
  408static struct node_slab *list_to_slab(
struct list_head *head)
 
  410        return (
struct node_slab *) head;
 
  413static struct node_slab *node_to_slab(
struct fuse *f, 
struct node *node)
 
  415        return (
struct node_slab *) (((uintptr_t) node) & ~((uintptr_t) f->pagesize - 1));
 
  418static int alloc_slab(
struct fuse *f)
 
  421        struct node_slab *slab;
 
  425        size_t node_size = get_node_size(f);
 
  427        mem = mmap(NULL, f->pagesize, PROT_READ | PROT_WRITE,
 
  428                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
  430        if (mem == MAP_FAILED)
 
  434        init_list_head(&slab->freelist);
 
  436        num = (f->pagesize - 
sizeof(
struct node_slab)) / node_size;
 
  438        start = (
char *) mem + f->pagesize - num * node_size;
 
  439        for (i = 0; i < num; i++) {
 
  442                n = (
struct list_head *) (start + i * node_size);
 
  443                list_add_tail(n, &slab->freelist);
 
  445        list_add_tail(&slab->list, &f->partial_slabs);
 
  450static struct node *alloc_node(
struct fuse *f)
 
  452        struct node_slab *slab;
 
  453        struct list_head *node;
 
  455        if (list_empty(&f->partial_slabs)) {
 
  456                int res = alloc_slab(f);
 
  460        slab = list_to_slab(f->partial_slabs.next);
 
  462        node = slab->freelist.next;
 
  464        if (list_empty(&slab->freelist)) {
 
  465                list_del(&slab->list);
 
  466                list_add_tail(&slab->list, &f->full_slabs);
 
  468        memset(node, 0, 
sizeof(
struct node));
 
  470        return (
struct node *) node;
 
  473static void free_slab(
struct fuse *f, 
struct node_slab *slab)
 
  477        list_del(&slab->list);
 
  478        res = munmap(slab, f->pagesize);
 
  480                fuse_log(FUSE_LOG_WARNING, 
"fuse warning: munmap(%p) failed\n",
 
  484static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  486        struct node_slab *slab = node_to_slab(f, node);
 
  487        struct list_head *n = (
struct list_head *) node;
 
  491                if (list_empty(&slab->freelist)) {
 
  492                        list_del(&slab->list);
 
  493                        list_add_tail(&slab->list, &f->partial_slabs);
 
  495                list_add_head(n, &slab->freelist);
 
  501static struct node *alloc_node(
struct fuse *f)
 
  503        return (
struct node *) calloc(1, get_node_size(f));
 
  506static void free_node_mem(
struct fuse *f, 
struct node *node)
 
  513static size_t id_hash(
struct fuse *f, 
fuse_ino_t ino)
 
  515        uint64_t hash = ((uint32_t) ino * 2654435761U) % f->id_table.size;
 
  516        uint64_t oldhash = hash % (f->id_table.size / 2);
 
  518        if (oldhash >= f->id_table.split)
 
  524static struct node *get_node_nocheck(
struct fuse *f, 
fuse_ino_t nodeid)
 
  526        size_t hash = id_hash(f, nodeid);
 
  529        for (node = f->id_table.array[hash]; node != NULL; node = node->id_next)
 
  530                if (node->nodeid == nodeid)
 
  536static struct node *get_node(
struct fuse *f, 
fuse_ino_t nodeid)
 
  538        struct node *node = get_node_nocheck(f, nodeid);
 
  540                fuse_log(FUSE_LOG_ERR, 
"fuse internal error: node %llu not found\n",
 
  541                        (
unsigned long long) nodeid);
 
  547static void curr_time(
struct timespec *now);
 
  548static double diff_timespec(
const struct timespec *t1,
 
  549                           const struct timespec *t2);
 
  551static void remove_node_lru(
struct node *node)
 
  553        struct node_lru *lnode = node_lru(node);
 
  554        list_del(&lnode->lru);
 
  555        init_list_head(&lnode->lru);
 
  558static void set_forget_time(
struct fuse *f, 
struct node *node)
 
  560        struct node_lru *lnode = node_lru(node);
 
  562        list_del(&lnode->lru);
 
  563        list_add_tail(&lnode->lru, &f->lru_table);
 
  564        curr_time(&lnode->forget_time);
 
  567static void free_node(
struct fuse *f, 
struct node *node)
 
  569        if (node->name != node->inline_name)
 
  571        free_node_mem(f, node);
 
  574static void node_table_reduce(
struct node_table *t)
 
  576        size_t newsize = t->size / 2;
 
  579        if (newsize < NODE_TABLE_MIN_SIZE)
 
  582        newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  583        if (newarray != NULL)
 
  587        t->split = t->size / 2;
 
  590static void remerge_id(
struct fuse *f)
 
  592        struct node_table *t = &f->id_table;
 
  596                node_table_reduce(t);
 
  598        for (iter = 8; t->split > 0 && iter; iter--) {
 
  602                upper = &t->array[t->split + t->size / 2];
 
  606                        for (nodep = &t->array[t->split]; *nodep;
 
  607                             nodep = &(*nodep)->id_next);
 
  616static void unhash_id(
struct fuse *f, 
struct node *node)
 
  618        struct node **nodep = &f->id_table.array[id_hash(f, node->nodeid)];
 
  620        for (; *nodep != NULL; nodep = &(*nodep)->id_next)
 
  621                if (*nodep == node) {
 
  622                        *nodep = node->id_next;
 
  625                        if(f->id_table.use < f->id_table.size / 4)
 
  631static int node_table_resize(
struct node_table *t)
 
  633        size_t newsize = t->size * 2;
 
  636        newarray = realloc(t->array, 
sizeof(
struct node *) * newsize);
 
  637        if (newarray == NULL)
 
  641        memset(t->array + t->size, 0, t->size * 
sizeof(
struct node *));
 
  648static void rehash_id(
struct fuse *f)
 
  650        struct node_table *t = &f->id_table;
 
  655        if (t->split == t->size / 2)
 
  660        for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  661                struct node *node = *nodep;
 
  662                size_t newhash = id_hash(f, node->nodeid);
 
  664                if (newhash != hash) {
 
  666                        *nodep = node->id_next;
 
  667                        node->id_next = t->array[newhash];
 
  668                        t->array[newhash] = node;
 
  670                        next = &node->id_next;
 
  673        if (t->split == t->size / 2)
 
  674                node_table_resize(t);
 
  677static void hash_id(
struct fuse *f, 
struct node *node)
 
  679        size_t hash = id_hash(f, node->nodeid);
 
  680        node->id_next = f->id_table.array[hash];
 
  681        f->id_table.array[hash] = node;
 
  684        if (f->id_table.use >= f->id_table.size / 2)
 
  688static size_t name_hash(
struct fuse *f, 
fuse_ino_t parent,
 
  691        uint64_t hash = parent;
 
  694        for (; *name; name++)
 
  695                hash = hash * 31 + (
unsigned char) *name;
 
  697        hash %= f->name_table.size;
 
  698        oldhash = hash % (f->name_table.size / 2);
 
  699        if (oldhash >= f->name_table.split)
 
  705static void unref_node(
struct fuse *f, 
struct node *node);
 
  707static void remerge_name(
struct fuse *f)
 
  709        struct node_table *t = &f->name_table;
 
  713                node_table_reduce(t);
 
  715        for (iter = 8; t->split > 0 && iter; iter--) {
 
  719                upper = &t->array[t->split + t->size / 2];
 
  723                        for (nodep = &t->array[t->split]; *nodep;
 
  724                             nodep = &(*nodep)->name_next);
 
  733static void unhash_name(
struct fuse *f, 
struct node *node)
 
  736                size_t hash = name_hash(f, node->parent->nodeid, node->name);
 
  737                struct node **nodep = &f->name_table.array[hash];
 
  739                for (; *nodep != NULL; nodep = &(*nodep)->name_next)
 
  740                        if (*nodep == node) {
 
  741                                *nodep = node->name_next;
 
  742                                node->name_next = NULL;
 
  743                                unref_node(f, node->parent);
 
  744                                if (node->name != node->inline_name)
 
  750                                if (f->name_table.use < f->name_table.size / 4)
 
  755                        "fuse internal error: unable to unhash node: %llu\n",
 
  756                        (
unsigned long long) node->nodeid);
 
  761static void rehash_name(
struct fuse *f)
 
  763        struct node_table *t = &f->name_table;
 
  768        if (t->split == t->size / 2)
 
  773        for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) {
 
  774                struct node *node = *nodep;
 
  775                size_t newhash = name_hash(f, node->parent->nodeid, node->name);
 
  777                if (newhash != hash) {
 
  779                        *nodep = node->name_next;
 
  780                        node->name_next = t->array[newhash];
 
  781                        t->array[newhash] = node;
 
  783                        next = &node->name_next;
 
  786        if (t->split == t->size / 2)
 
  787                node_table_resize(t);
 
  790static int hash_name(
struct fuse *f, 
struct node *node, 
fuse_ino_t parentid,
 
  793        size_t hash = name_hash(f, parentid, name);
 
  794        struct node *parent = get_node(f, parentid);
 
  795        if (strlen(name) < 
sizeof(node->inline_name)) {
 
  796                strcpy(node->inline_name, name);
 
  797                node->name = node->inline_name;
 
  799                node->name = strdup(name);
 
  800                if (node->name == NULL)
 
  805        node->parent = parent;
 
  806        node->name_next = f->name_table.array[hash];
 
  807        f->name_table.array[hash] = node;
 
  810        if (f->name_table.use >= f->name_table.size / 2)
 
  816static void delete_node(
struct fuse *f, 
struct node *node)
 
  819                fuse_log(FUSE_LOG_DEBUG, 
"DELETE: %llu\n",
 
  820                        (
unsigned long long) node->nodeid);
 
  822        assert(node->treelock == 0);
 
  823        unhash_name(f, node);
 
  825                remove_node_lru(node);
 
  830static void unref_node(
struct fuse *f, 
struct node *node)
 
  832        assert(node->refctr > 0);
 
  835                delete_node(f, node);
 
  841                f->ctr = (f->ctr + 1) & 0xffffffff;
 
  844        } 
while (f->ctr == 0 || f->ctr == FUSE_UNKNOWN_INO ||
 
  845                 get_node_nocheck(f, f->ctr) != NULL);
 
  849static struct node *lookup_node(
struct fuse *f, 
fuse_ino_t parent,
 
  852        size_t hash = name_hash(f, parent, name);
 
  855        for (node = f->name_table.array[hash]; node != NULL; node = node->name_next)
 
  856                if (node->parent->nodeid == parent &&
 
  857                    strcmp(node->name, name) == 0)
 
  863static void inc_nlookup(
struct node *node)
 
  870static struct node *find_node(
struct fuse *f, 
fuse_ino_t parent,
 
  875        pthread_mutex_lock(&f->lock);
 
  877                node = get_node(f, parent);
 
  879                node = lookup_node(f, parent, name);
 
  881                node = alloc_node(f);
 
  885                node->nodeid = next_id(f);
 
  886                node->generation = f->generation;
 
  887                if (f->conf.remember)
 
  890                if (hash_name(f, node, parent, name) == -1) {
 
  896                if (lru_enabled(f)) {
 
  897                        struct node_lru *lnode = node_lru(node);
 
  898                        init_list_head(&lnode->lru);
 
  900        } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
  901                remove_node_lru(node);
 
  905        pthread_mutex_unlock(&f->lock);
 
  909static int lookup_path_in_cache(
struct fuse *f,
 
  912        char *tmp = strdup(path);
 
  916        pthread_mutex_lock(&f->lock);
 
  921        char *path_element = strtok_r(tmp, 
"/", &save_ptr);
 
  922        while (path_element != NULL) {
 
  923                struct node *node = lookup_node(f, ino, path_element);
 
  929                path_element = strtok_r(NULL, 
"/", &save_ptr);
 
  931        pthread_mutex_unlock(&f->lock);
 
  939static char *add_name(
char **buf, 
unsigned *bufsize, 
char *s, 
const char *name)
 
  941        size_t len = strlen(name);
 
  943        if (s - len <= *buf) {
 
  944                unsigned pathlen = *bufsize - (s - *buf);
 
  945                unsigned newbufsize = *bufsize;
 
  948                while (newbufsize < pathlen + len + 1) {
 
  949                        if (newbufsize >= 0x80000000)
 
  950                                newbufsize = 0xffffffff;
 
  955                newbuf = realloc(*buf, newbufsize);
 
  960                s = newbuf + newbufsize - pathlen;
 
  961                memmove(s, newbuf + *bufsize - pathlen, pathlen);
 
  962                *bufsize = newbufsize;
 
  965        memcpy(s, name, len);
 
  972static void unlock_path(
struct fuse *f, 
fuse_ino_t nodeid, 
struct node *wnode,
 
  978                assert(wnode->treelock == TREELOCK_WRITE);
 
  982        for (node = get_node(f, nodeid);
 
  983             node != end && node->nodeid != FUSE_ROOT_ID; node = node->parent) {
 
  984                assert(node->treelock != 0);
 
  985                assert(node->treelock != TREELOCK_WAIT_OFFSET);
 
  986                assert(node->treelock != TREELOCK_WRITE);
 
  988                if (node->treelock == TREELOCK_WAIT_OFFSET)
 
  993static int try_get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
  994                        char **path, 
struct node **wnodep, 
bool need_lock)
 
  996        unsigned bufsize = 256;
 
 1000        struct node *wnode = NULL;
 
 1006        buf = malloc(bufsize);
 
 1010        s = buf + bufsize - 1;
 
 1014                s = add_name(&buf, &bufsize, s, name);
 
 1022                wnode = lookup_node(f, nodeid, name);
 
 1024                        if (wnode->treelock != 0) {
 
 1025                                if (wnode->treelock > 0)
 
 1026                                        wnode->treelock += TREELOCK_WAIT_OFFSET;
 
 1030                        wnode->treelock = TREELOCK_WRITE;
 
 1034        for (node = get_node(f, nodeid); node->nodeid != FUSE_ROOT_ID;
 
 1035             node = node->parent) {
 
 1037                if (node->name == NULL || node->parent == NULL)
 
 1041                s = add_name(&buf, &bufsize, s, node->name);
 
 1047                        if (node->treelock < 0)
 
 1055                memmove(buf, s, bufsize - (s - buf));
 
 1067                unlock_path(f, nodeid, wnode, node);
 
 1075static int try_get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1077                         char **path1, 
char **path2,
 
 1078                         struct node **wnode1, 
struct node **wnode2)
 
 1083        err = try_get_path(f, nodeid1, name1, path1, wnode1, 
true);
 
 1085                err = try_get_path(f, nodeid2, name2, path2, wnode2, 
true);
 
 1087                        struct node *wn1 = wnode1 ? *wnode1 : NULL;
 
 1089                        unlock_path(f, nodeid1, wn1, NULL);
 
 1096static void queue_element_wakeup(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1102                if (get_node(f, qe->nodeid1)->treelock == 0)
 
 1103                        pthread_cond_signal(&qe->cond);
 
 1112                err = try_get_path(f, qe->nodeid1, qe->name1, qe->path1,
 
 1115                err = try_get_path2(f, qe->nodeid1, qe->name1, qe->nodeid2,
 
 1116                                    qe->name2, qe->path1, qe->path2, qe->wnode1,
 
 1125        pthread_cond_signal(&qe->cond);
 
 1128static void wake_up_queued(
struct fuse *f)
 
 1130        struct lock_queue_element *qe;
 
 1132        for (qe = f->lockq; qe != NULL; qe = qe->next)
 
 1133                queue_element_wakeup(f, qe);
 
 1136static void debug_path(
struct fuse *f, 
const char *msg, 
fuse_ino_t nodeid,
 
 1137                       const char *name, 
bool wr)
 
 1139        if (f->conf.debug) {
 
 1140                struct node *wnode = NULL;
 
 1143                        wnode = lookup_node(f, nodeid, name);
 
 1146                        fuse_log(FUSE_LOG_DEBUG, 
"%s %llu (w)\n",
 
 1147                                msg, (
unsigned long long) wnode->nodeid);
 
 1149                        fuse_log(FUSE_LOG_DEBUG, 
"%s %llu\n",
 
 1150                                msg, (
unsigned long long) nodeid);
 
 1155static void queue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1157        struct lock_queue_element **qp;
 
 1160        pthread_cond_init(&qe->cond, NULL);
 
 1162        for (qp = &f->lockq; *qp != NULL; qp = &(*qp)->next);
 
 1166static void dequeue_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1168        struct lock_queue_element **qp;
 
 1170        pthread_cond_destroy(&qe->cond);
 
 1171        for (qp = &f->lockq; *qp != qe; qp = &(*qp)->next);
 
 1175static int wait_path(
struct fuse *f, 
struct lock_queue_element *qe)
 
 1180                pthread_cond_wait(&qe->cond, &f->lock);
 
 1181        } 
while (!qe->done);
 
 1183        dequeue_path(f, qe);
 
 1188static int get_path_common(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1189                           char **path, 
struct node **wnode)
 
 1193        pthread_mutex_lock(&f->lock);
 
 1194        err = try_get_path(f, nodeid, name, path, wnode, 
true);
 
 1195        if (err == -EAGAIN) {
 
 1196                struct lock_queue_element qe = {
 
 1202                debug_path(f, 
"QUEUE PATH", nodeid, name, !!wnode);
 
 1203                err = wait_path(f, &qe);
 
 1204                debug_path(f, 
"DEQUEUE PATH", nodeid, name, !!wnode);
 
 1206        pthread_mutex_unlock(&f->lock);
 
 1211static int get_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1213        return get_path_common(f, nodeid, NULL, path, NULL);
 
 1216static int get_path_nullok(
struct fuse *f, 
fuse_ino_t nodeid, 
char **path)
 
 1220        if (f->conf.nullpath_ok) {
 
 1223                err = get_path_common(f, nodeid, NULL, path, NULL);
 
 1231static int get_path_name(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1234        return get_path_common(f, nodeid, name, path, NULL);
 
 1237static int get_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 1238                           char **path, 
struct node **wnode)
 
 1240        return get_path_common(f, nodeid, name, path, wnode);
 
 1243#if defined(__FreeBSD__) 
 1244#define CHECK_DIR_LOOP 
 1247#if defined(CHECK_DIR_LOOP) 
 1248static int check_dir_loop(
struct fuse *f,
 
 1252        struct node *node, *node1, *node2;
 
 1255        node1 = lookup_node(f, nodeid1, name1);
 
 1256        id1 = node1 ? node1->nodeid : nodeid1;
 
 1258        node2 = lookup_node(f, nodeid2, name2);
 
 1259        id2 = node2 ? node2->nodeid : nodeid2;
 
 1261        for (node = get_node(f, id2); node->nodeid != FUSE_ROOT_ID;
 
 1262             node = node->parent) {
 
 1263                if (node->name == NULL || node->parent == NULL)
 
 1266                if (node->nodeid != id2 && node->nodeid == id1)
 
 1272                for (node = get_node(f, id1); node->nodeid != FUSE_ROOT_ID;
 
 1273                     node = node->parent) {
 
 1274                        if (node->name == NULL || node->parent == NULL)
 
 1277                        if (node->nodeid != id1 && node->nodeid == id2)
 
 1286static int get_path2(
struct fuse *f, 
fuse_ino_t nodeid1, 
const char *name1,
 
 1288                     char **path1, 
char **path2,
 
 1289                     struct node **wnode1, 
struct node **wnode2)
 
 1293        pthread_mutex_lock(&f->lock);
 
 1295#if defined(CHECK_DIR_LOOP) 
 1299                err = check_dir_loop(f, nodeid1, name1, nodeid2, name2);
 
 1305        err = try_get_path2(f, nodeid1, name1, nodeid2, name2,
 
 1306                            path1, path2, wnode1, wnode2);
 
 1307        if (err == -EAGAIN) {
 
 1308                struct lock_queue_element qe = {
 
 1319                debug_path(f, 
"QUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1320                debug_path(f, 
"      PATH2", nodeid2, name2, !!wnode2);
 
 1321                err = wait_path(f, &qe);
 
 1322                debug_path(f, 
"DEQUEUE PATH1", nodeid1, name1, !!wnode1);
 
 1323                debug_path(f, 
"        PATH2", nodeid2, name2, !!wnode2);
 
 1326#if defined(CHECK_DIR_LOOP) 
 1329        pthread_mutex_unlock(&f->lock);
 
 1334static void free_path_wrlock(
struct fuse *f, 
fuse_ino_t nodeid,
 
 1335                             struct node *wnode, 
char *path)
 
 1337        pthread_mutex_lock(&f->lock);
 
 1338        unlock_path(f, nodeid, wnode, NULL);
 
 1341        pthread_mutex_unlock(&f->lock);
 
 1345static void free_path(
struct fuse *f, 
fuse_ino_t nodeid, 
char *path)
 
 1348                free_path_wrlock(f, nodeid, NULL, path);
 
 1352                       struct node *wnode1, 
struct node *wnode2,
 
 1353                       char *path1, 
char *path2)
 
 1355        pthread_mutex_lock(&f->lock);
 
 1356        unlock_path(f, nodeid1, wnode1, NULL);
 
 1357        unlock_path(f, nodeid2, wnode2, NULL);
 
 1359        pthread_mutex_unlock(&f->lock);
 
 1364static void forget_node(
struct fuse *f, 
fuse_ino_t nodeid, uint64_t nlookup)
 
 1367        if (nodeid == FUSE_ROOT_ID)
 
 1369        pthread_mutex_lock(&f->lock);
 
 1370        node = get_node(f, nodeid);
 
 1376        while (node->nlookup == nlookup && node->treelock) {
 
 1377                struct lock_queue_element qe = {
 
 1381                debug_path(f, 
"QUEUE PATH (forget)", nodeid, NULL, 
false);
 
 1385                        pthread_cond_wait(&qe.cond, &f->lock);
 
 1386                } 
while (node->nlookup == nlookup && node->treelock);
 
 1388                dequeue_path(f, &qe);
 
 1389                debug_path(f, 
"DEQUEUE_PATH (forget)", nodeid, NULL, 
false);
 
 1392        assert(node->nlookup >= nlookup);
 
 1393        node->nlookup -= nlookup;
 
 1394        if (!node->nlookup) {
 
 1395                unref_node(f, node);
 
 1396        } 
else if (lru_enabled(f) && node->nlookup == 1) {
 
 1397                set_forget_time(f, node);
 
 1399        pthread_mutex_unlock(&f->lock);
 
 1402static void unlink_node(
struct fuse *f, 
struct node *node)
 
 1404        if (f->conf.remember) {
 
 1405                assert(node->nlookup > 1);
 
 1408        unhash_name(f, node);
 
 1411static void remove_node(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 1415        pthread_mutex_lock(&f->lock);
 
 1416        node = lookup_node(f, dir, name);
 
 1418                unlink_node(f, node);
 
 1419        pthread_mutex_unlock(&f->lock);
 
 1422static int rename_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1423                       fuse_ino_t newdir, 
const char *newname, 
int hide)
 
 1426        struct node *newnode;
 
 1429        pthread_mutex_lock(&f->lock);
 
 1430        node  = lookup_node(f, olddir, oldname);
 
 1431        newnode  = lookup_node(f, newdir, newname);
 
 1435        if (newnode != NULL) {
 
 1437                        fuse_log(FUSE_LOG_ERR, 
"fuse: hidden file got created during hiding\n");
 
 1441                unlink_node(f, newnode);
 
 1444        unhash_name(f, node);
 
 1445        if (hash_name(f, node, newdir, newname) == -1) {
 
 1451                node->is_hidden = 1;
 
 1454        pthread_mutex_unlock(&f->lock);
 
 1458static int exchange_node(
struct fuse *f, 
fuse_ino_t olddir, 
const char *oldname,
 
 1461        struct node *oldnode;
 
 1462        struct node *newnode;
 
 1465        pthread_mutex_lock(&f->lock);
 
 1466        oldnode  = lookup_node(f, olddir, oldname);
 
 1467        newnode  = lookup_node(f, newdir, newname);
 
 1470                unhash_name(f, oldnode);
 
 1472                unhash_name(f, newnode);
 
 1476                if (hash_name(f, oldnode, newdir, newname) == -1)
 
 1480                if (hash_name(f, newnode, olddir, oldname) == -1)
 
 1485        pthread_mutex_unlock(&f->lock);
 
 1489static void set_stat(
struct fuse *f, 
fuse_ino_t nodeid, 
struct stat *stbuf)
 
 1491        if (!f->conf.use_ino)
 
 1492                stbuf->st_ino = nodeid;
 
 1493        if (f->conf.set_mode) {
 
 1494                if (f->conf.dmask && S_ISDIR(stbuf->st_mode))
 
 1495                        stbuf->st_mode = (stbuf->st_mode & S_IFMT) |
 
 1496                                         (0777 & ~f->conf.dmask);
 
 1497                else if (f->conf.fmask)
 
 1498                        stbuf->st_mode = (stbuf->st_mode & S_IFMT) |
 
 1499                                         (0777 & ~f->conf.fmask);
 
 1501                        stbuf->st_mode = (stbuf->st_mode & S_IFMT) |
 
 1502                                         (0777 & ~f->conf.umask);
 
 1504        if (f->conf.set_uid)
 
 1505                stbuf->st_uid = f->conf.uid;
 
 1506        if (f->conf.set_gid)
 
 1507                stbuf->st_gid = f->conf.gid;
 
 1515static void fuse_intr_sighandler(
int sig)
 
 1521struct fuse_intr_data {
 
 1523        pthread_cond_t cond;
 
 1527static void fuse_interrupt(
fuse_req_t req, 
void *d_)
 
 1529        struct fuse_intr_data *d = d_;
 
 1530        struct fuse *f = req_fuse(req);
 
 1532        if (d->id == pthread_self())
 
 1535        pthread_mutex_lock(&f->lock);
 
 1536        while (!d->finished) {
 
 1538                struct timespec timeout;
 
 1540                pthread_kill(d->id, f->conf.intr_signal);
 
 1541                gettimeofday(&now, NULL);
 
 1542                timeout.tv_sec = now.tv_sec + 1;
 
 1543                timeout.tv_nsec = now.tv_usec * 1000;
 
 1544                pthread_cond_timedwait(&d->cond, &f->lock, &timeout);
 
 1546        pthread_mutex_unlock(&f->lock);
 
 1549static void fuse_do_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1550                                     struct fuse_intr_data *d)
 
 1552        pthread_mutex_lock(&f->lock);
 
 1554        pthread_cond_broadcast(&d->cond);
 
 1555        pthread_mutex_unlock(&f->lock);
 
 1557        pthread_cond_destroy(&d->cond);
 
 1560static void fuse_do_prepare_interrupt(
fuse_req_t req, 
struct fuse_intr_data *d)
 
 1562        d->id = pthread_self();
 
 1563        pthread_cond_init(&d->cond, NULL);
 
 1568static inline void fuse_finish_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1569                                         struct fuse_intr_data *d)
 
 1572                fuse_do_finish_interrupt(f, req, d);
 
 1575static inline void fuse_prepare_interrupt(
struct fuse *f, 
fuse_req_t req,
 
 1576                                          struct fuse_intr_data *d)
 
 1579                fuse_do_prepare_interrupt(req, d);
 
 1583                              char* buf, 
size_t len)
 
 1587        snprintf(buf, len, 
"%llu", (
unsigned long long) fi->
fh);
 
 1591int fuse_fs_getattr(
struct fuse_fs *fs, 
const char *path, 
struct stat *buf,
 
 1595        if (fs->op.getattr) {
 
 1598                        fuse_log(FUSE_LOG_DEBUG, 
"getattr[%s] %s\n",
 
 1599                                file_info_string(fi, buf, 
sizeof(buf)),
 
 1602                return fs->op.getattr(path, buf, fi);
 
 1608int fuse_fs_rename(
struct fuse_fs *fs, 
const char *oldpath,
 
 1609                   const char *newpath, 
unsigned int flags)
 
 1612        if (fs->op.rename) {
 
 1614                        fuse_log(FUSE_LOG_DEBUG, 
"rename %s %s 0x%x\n", oldpath, newpath,
 
 1617                return fs->op.rename(oldpath, newpath, flags);
 
 1623int fuse_fs_unlink(
struct fuse_fs *fs, 
const char *path)
 
 1626        if (fs->op.unlink) {
 
 1628                        fuse_log(FUSE_LOG_DEBUG, 
"unlink %s\n", path);
 
 1630                return fs->op.unlink(path);
 
 1636int fuse_fs_rmdir(
struct fuse_fs *fs, 
const char *path)
 
 1641                        fuse_log(FUSE_LOG_DEBUG, 
"rmdir %s\n", path);
 
 1643                return fs->op.rmdir(path);
 
 1649int fuse_fs_symlink(
struct fuse_fs *fs, 
const char *linkname, 
const char *path)
 
 1652        if (fs->op.symlink) {
 
 1654                        fuse_log(FUSE_LOG_DEBUG, 
"symlink %s %s\n", linkname, path);
 
 1656                return fs->op.symlink(linkname, path);
 
 1662int fuse_fs_link(
struct fuse_fs *fs, 
const char *oldpath, 
const char *newpath)
 
 1667                        fuse_log(FUSE_LOG_DEBUG, 
"link %s %s\n", oldpath, newpath);
 
 1669                return fs->op.link(oldpath, newpath);
 
 1675int fuse_fs_release(
struct fuse_fs *fs,  
const char *path,
 
 1679        if (fs->op.release) {
 
 1681                        fuse_log(FUSE_LOG_DEBUG, 
"release%s[%llu] flags: 0x%x\n",
 
 1682                                fi->
flush ? 
"+flush" : 
"",
 
 1683                                (unsigned long long) fi->fh, fi->flags);
 
 1685                return fs->op.release(path, fi);
 
 1691int fuse_fs_opendir(
struct fuse_fs *fs, 
const char *path,
 
 1695        if (fs->op.opendir) {
 
 1699                        fuse_log(FUSE_LOG_DEBUG, 
"opendir flags: 0x%x %s\n", fi->
flags,
 
 1702                err = fs->op.opendir(path, fi);
 
 1704                if (fs->debug && !err)
 
 1705                        fuse_log(FUSE_LOG_DEBUG, 
"   opendir[%llu] flags: 0x%x %s\n",
 
 1706                                (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1714int fuse_fs_open(
struct fuse_fs *fs, 
const char *path,
 
 1722                        fuse_log(FUSE_LOG_DEBUG, 
"open flags: 0x%x %s\n", fi->
flags,
 
 1725                err = fs->op.open(path, fi);
 
 1727                if (fs->debug && !err)
 
 1728                        fuse_log(FUSE_LOG_DEBUG, 
"   open[%llu] flags: 0x%x %s\n",
 
 1729                                (
unsigned long long) fi->
fh, fi->
flags, path);
 
 1742                for (i = 0; i < buf->
count; i++)
 
 1749int fuse_fs_read_buf(
struct fuse_fs *fs, 
const char *path,
 
 1750                     struct fuse_bufvec **bufp, 
size_t size, off_t off,
 
 1754        if (fs->op.read || fs->op.read_buf) {
 
 1759                                "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1760                                (
unsigned long long) fi->
fh,
 
 1761                                size, (
unsigned long long) off, fi->
flags);
 
 1763                if (fs->op.read_buf) {
 
 1764                        res = fs->op.read_buf(path, bufp, size, off, fi);
 
 1778                        *
buf = FUSE_BUFVEC_INIT(size);
 
 1782                        res = fs->op.read(path, mem, size, 
off, fi);
 
 1787                if (fs->debug && res >= 0)
 
 1788                        fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %zu bytes from %llu\n",
 
 1789                                (
unsigned long long) fi->
fh,
 
 1791                                (
unsigned long long) 
off);
 
 1793                        fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1804int fuse_fs_read(
struct fuse_fs *fs, 
const char *path, 
char *mem, 
size_t size,
 
 1808        if (fs->op.read || fs->op.read_buf) {
 
 1813                                "read[%llu] %zu bytes from %llu flags: 0x%x\n",
 
 1814                                (
unsigned long long) fi->
fh,
 
 1815                                size, (
unsigned long long) 
off, fi->
flags);
 
 1817                if (fs->op.read_buf) {
 
 1820                        res = fs->op.read_buf(path, &
buf, size, 
off, fi);
 
 1829                        res = fs->op.read(path, mem, size, 
off, fi);
 
 1832                if (fs->debug && res >= 0)
 
 1833                        fuse_log(FUSE_LOG_DEBUG, 
"   read[%llu] %u bytes from %llu\n",
 
 1834                                (
unsigned long long) fi->
fh,
 
 1836                                (
unsigned long long) 
off);
 
 1837                if (res >= 0 && res > (
int) size)
 
 1838                        fuse_log(FUSE_LOG_ERR, 
"fuse: read too many bytes\n");
 
 1846int fuse_fs_write_buf(
struct fuse_fs *fs, 
const char *path,
 
 1851        if (fs->op.write_buf || fs->op.write) {
 
 1855                assert(
buf->idx == 0 && 
buf->off == 0);
 
 1858                                "write%s[%llu] %zu bytes to %llu flags: 0x%x\n",
 
 1860                                (unsigned long long) fi->fh,
 
 1862                                (unsigned long long) 
off,
 
 1865                if (fs->op.write_buf) {
 
 1866                        res = fs->op.write_buf(path, 
buf, 
off, fi);
 
 1872                        if (
buf->count == 1 &&
 
 1874                                flatbuf = &
buf->buf[0];
 
 1887                                flatbuf = &tmp.
buf[0];
 
 1890                        res = fs->op.write(path, flatbuf->
mem, flatbuf->
size,
 
 1896                if (fs->debug && res >= 0)
 
 1897                        fuse_log(FUSE_LOG_DEBUG, 
"   write%s[%llu] %u bytes to %llu\n",
 
 1899                                (unsigned long long) fi->fh, res,
 
 1900                                (unsigned long long) 
off);
 
 1901                if (res > (
int) size)
 
 1902                        fuse_log(FUSE_LOG_ERR, 
"fuse: wrote too many bytes\n");
 
 1910int fuse_fs_write(
struct fuse_fs *fs, 
const char *path, 
const char *mem,
 
 1915        bufv.
buf[0].
mem = (
void *) mem;
 
 1917        return fuse_fs_write_buf(fs, path, &bufv, 
off, fi);
 
 1920int fuse_fs_fsync(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1926                        fuse_log(FUSE_LOG_DEBUG, 
"fsync[%llu] datasync: %i\n",
 
 1927                                (
unsigned long long) fi->
fh, datasync);
 
 1929                return fs->op.fsync(path, datasync, fi);
 
 1935int fuse_fs_fsyncdir(
struct fuse_fs *fs, 
const char *path, 
int datasync,
 
 1939        if (fs->op.fsyncdir) {
 
 1941                        fuse_log(FUSE_LOG_DEBUG, 
"fsyncdir[%llu] datasync: %i\n",
 
 1942                                (
unsigned long long) fi->
fh, datasync);
 
 1944                return fs->op.fsyncdir(path, datasync, fi);
 
 1950int fuse_fs_flush(
struct fuse_fs *fs, 
const char *path,
 
 1956                        fuse_log(FUSE_LOG_DEBUG, 
"flush[%llu]\n",
 
 1957                                (
unsigned long long) fi->
fh);
 
 1959                return fs->op.flush(path, fi);
 
 1965int fuse_fs_statfs(
struct fuse_fs *fs, 
const char *path, 
struct statvfs *
buf)
 
 1968        if (fs->op.statfs) {
 
 1970                        fuse_log(FUSE_LOG_DEBUG, 
"statfs %s\n", path);
 
 1972                return fs->op.statfs(path, 
buf);
 
 1974                buf->f_namemax = 255;
 
 1980int fuse_fs_releasedir(
struct fuse_fs *fs, 
const char *path,
 
 1984        if (fs->op.releasedir) {
 
 1986                        fuse_log(FUSE_LOG_DEBUG, 
"releasedir[%llu] flags: 0x%x\n",
 
 1987                                (
unsigned long long) fi->
fh, fi->
flags);
 
 1989                return fs->op.releasedir(path, fi);
 
 1995int fuse_fs_readdir(
struct fuse_fs *fs, 
const char *path, 
void *
buf,
 
 2001        if (fs->op.readdir) {
 
 2003                        fuse_log(FUSE_LOG_DEBUG, 
"readdir%s[%llu] from %llu\n",
 
 2004                                (flags & FUSE_READDIR_PLUS) ? 
"plus" : 
"",
 
 2005                                (unsigned long long) fi->fh,
 
 2006                                (unsigned long long) 
off);
 
 2009                return fs->op.readdir(path, 
buf, filler, 
off, fi, flags);
 
 2015int fuse_fs_create(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2019        if (fs->op.create) {
 
 2024                                "create flags: 0x%x %s 0%o umask=0%03o\n",
 
 2025                                fi->
flags, path, mode,
 
 2028                err = fs->op.create(path, mode, fi);
 
 2030                if (fs->debug && !err)
 
 2031                        fuse_log(FUSE_LOG_DEBUG, 
"   create[%llu] flags: 0x%x %s\n",
 
 2032                                (
unsigned long long) fi->
fh, fi->
flags, path);
 
 2040int fuse_fs_lock(
struct fuse_fs *fs, 
const char *path,
 
 2046                        fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s %s start: %llu len: %llu pid: %llu\n",
 
 2047                                (
unsigned long long) fi->
fh,
 
 2048                                (cmd == F_GETLK ? 
"F_GETLK" :
 
 2049                                 (cmd == F_SETLK ? 
"F_SETLK" :
 
 2050                                  (cmd == F_SETLKW ? 
"F_SETLKW" : 
"???"))),
 
 2051                                (lock->l_type == F_RDLCK ? 
"F_RDLCK" :
 
 2052                                 (lock->l_type == F_WRLCK ? 
"F_WRLCK" :
 
 2053                                  (lock->l_type == F_UNLCK ? 
"F_UNLCK" :
 
 2055                                (unsigned long long) lock->l_start,
 
 2056                                (unsigned long long) lock->l_len,
 
 2057                                (unsigned long long) lock->l_pid);
 
 2059                return fs->op.lock(path, fi, cmd, lock);
 
 2065int fuse_fs_flock(
struct fuse_fs *fs, 
const char *path,
 
 2071                        int xop = op & ~LOCK_NB;
 
 2073                        fuse_log(FUSE_LOG_DEBUG, 
"lock[%llu] %s%s\n",
 
 2074                                (
unsigned long long) fi->
fh,
 
 2075                                xop == LOCK_SH ? 
"LOCK_SH" :
 
 2076                                (xop == LOCK_EX ? 
"LOCK_EX" :
 
 2077                                 (xop == LOCK_UN ? 
"LOCK_UN" : 
"???")),
 
 2078                                (op & LOCK_NB) ? 
"|LOCK_NB" : 
"");
 
 2080                return fs->op.flock(path, fi, op);
 
 2086int fuse_fs_chown(
struct fuse_fs *fs, 
const char *path, uid_t uid,
 
 2093                        fuse_log(FUSE_LOG_DEBUG, 
"chown[%s] %s %lu %lu\n",
 
 2094                                file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2095                                path, (
unsigned long) uid, (
unsigned long) gid);
 
 2097                return fs->op.chown(path, uid, gid, fi);
 
 2103int fuse_fs_truncate(
struct fuse_fs *fs, 
const char *path, off_t size,
 
 2107        if (fs->op.truncate) {
 
 2110                        fuse_log(FUSE_LOG_DEBUG, 
"truncate[%s] %llu\n",
 
 2111                                file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2112                                (
unsigned long long) size);
 
 2114                return fs->op.truncate(path, size, fi);
 
 2120int fuse_fs_utimens(
struct fuse_fs *fs, 
const char *path,
 
 2124        if (fs->op.utimens) {
 
 2127                        fuse_log(FUSE_LOG_DEBUG, 
"utimens[%s] %s %li.%09lu %li.%09lu\n",
 
 2128                                file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2129                                path, tv[0].tv_sec, tv[0].tv_nsec,
 
 2130                                tv[1].tv_sec, tv[1].tv_nsec);
 
 2132                return fs->op.utimens(path, tv, fi);
 
 2138int fuse_fs_access(
struct fuse_fs *fs, 
const char *path, 
int mask)
 
 2141        if (fs->op.access) {
 
 2143                        fuse_log(FUSE_LOG_DEBUG, 
"access %s 0%o\n", path, mask);
 
 2145                return fs->op.access(path, mask);
 
 2151int fuse_fs_readlink(
struct fuse_fs *fs, 
const char *path, 
char *
buf,
 
 2155        if (fs->op.readlink) {
 
 2157                        fuse_log(FUSE_LOG_DEBUG, 
"readlink %s %lu\n", path,
 
 2158                                (
unsigned long) len);
 
 2160                return fs->op.readlink(path, 
buf, len);
 
 2166int fuse_fs_mknod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2172                        fuse_log(FUSE_LOG_DEBUG, 
"mknod %s 0%o 0x%llx umask=0%03o\n",
 
 2173                                path, mode, (
unsigned long long) rdev,
 
 2176                return fs->op.mknod(path, mode, rdev);
 
 2182int fuse_fs_mkdir(
struct fuse_fs *fs, 
const char *path, mode_t mode)
 
 2187                        fuse_log(FUSE_LOG_DEBUG, 
"mkdir %s 0%o umask=0%03o\n",
 
 2190                return fs->op.mkdir(path, mode);
 
 2196int fuse_fs_setxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2197                     const char *value, 
size_t size, 
int flags)
 
 2200        if (fs->op.setxattr) {
 
 2202                        fuse_log(FUSE_LOG_DEBUG, 
"setxattr %s %s %lu 0x%x\n",
 
 2203                                path, name, (
unsigned long) size, flags);
 
 2205                return fs->op.setxattr(path, name, value, size, flags);
 
 2211int fuse_fs_getxattr(
struct fuse_fs *fs, 
const char *path, 
const char *name,
 
 2212                     char *value, 
size_t size)
 
 2215        if (fs->op.getxattr) {
 
 2217                        fuse_log(FUSE_LOG_DEBUG, 
"getxattr %s %s %lu\n",
 
 2218                                path, name, (
unsigned long) size);
 
 2220                return fs->op.getxattr(path, name, value, size);
 
 2226int fuse_fs_listxattr(
struct fuse_fs *fs, 
const char *path, 
char *list,
 
 2230        if (fs->op.listxattr) {
 
 2232                        fuse_log(FUSE_LOG_DEBUG, 
"listxattr %s %lu\n",
 
 2233                                path, (
unsigned long) size);
 
 2235                return fs->op.listxattr(path, list, size);
 
 2241int fuse_fs_bmap(
struct fuse_fs *fs, 
const char *path, 
size_t blocksize,
 
 2247                        fuse_log(FUSE_LOG_DEBUG, 
"bmap %s blocksize: %lu index: %llu\n",
 
 2248                                path, (
unsigned long) blocksize,
 
 2249                                (
unsigned long long) *
idx);
 
 2251                return fs->op.bmap(path, blocksize, 
idx);
 
 2257int fuse_fs_removexattr(
struct fuse_fs *fs, 
const char *path, 
const char *name)
 
 2260        if (fs->op.removexattr) {
 
 2262                        fuse_log(FUSE_LOG_DEBUG, 
"removexattr %s %s\n", path, name);
 
 2264                return fs->op.removexattr(path, name);
 
 2270int fuse_fs_ioctl(
struct fuse_fs *fs, 
const char *path, 
unsigned int cmd,
 
 2277                        fuse_log(FUSE_LOG_DEBUG, 
"ioctl[%llu] 0x%x flags: 0x%x\n",
 
 2278                                (
unsigned long long) fi->
fh, cmd, flags);
 
 2280                return fs->op.ioctl(path, cmd, arg, fi, flags, data);
 
 2285int fuse_fs_poll(
struct fuse_fs *fs, 
const char *path,
 
 2294                        fuse_log(FUSE_LOG_DEBUG, 
"poll[%llu] ph: %p, events 0x%x\n",
 
 2295                                (
unsigned long long) fi->
fh, ph,
 
 2298                res = fs->op.poll(path, fi, ph, reventsp);
 
 2300                if (fs->debug && !res)
 
 2301                        fuse_log(FUSE_LOG_DEBUG, 
"   poll[%llu] revents: 0x%x\n",
 
 2302                                (
unsigned long long) fi->
fh, *reventsp);
 
 2309int fuse_fs_fallocate(
struct fuse_fs *fs, 
const char *path, 
int mode,
 
 2313        if (fs->op.fallocate) {
 
 2315                        fuse_log(FUSE_LOG_DEBUG, 
"fallocate %s mode %x, offset: %llu, length: %llu\n",
 
 2318                                (
unsigned long long) offset,
 
 2319                                (
unsigned long long) length);
 
 2321                return fs->op.fallocate(path, mode, offset, length, fi);
 
 2326ssize_t fuse_fs_copy_file_range(
struct fuse_fs *fs, 
const char *path_in,
 
 2328                                const char *path_out,
 
 2330                                size_t len, 
int flags)
 
 2333        if (fs->op.copy_file_range) {
 
 2335                        fuse_log(FUSE_LOG_DEBUG, 
"copy_file_range from %s:%llu to " 
 2336                                        "%s:%llu, length: %llu\n",
 
 2338                                (
unsigned long long) off_in,
 
 2340                                (
unsigned long long) off_out,
 
 2341                                (
unsigned long long) len);
 
 2343                return fs->op.copy_file_range(path_in, fi_in, off_in, path_out,
 
 2344                                              fi_out, off_out, len, flags);
 
 2349off_t fuse_fs_lseek(
struct fuse_fs *fs, 
const char *path, off_t 
off, 
int whence,
 
 2356                        fuse_log(FUSE_LOG_DEBUG, 
"lseek[%s] %llu %d\n",
 
 2357                                file_info_string(fi, 
buf, 
sizeof(
buf)),
 
 2358                                (
unsigned long long) 
off, whence);
 
 2360                return fs->op.lseek(path, 
off, whence, fi);
 
 2366static int is_open(
struct fuse *f, 
fuse_ino_t dir, 
const char *name)
 
 2370        pthread_mutex_lock(&f->lock);
 
 2371        node = lookup_node(f, dir, name);
 
 2372        if (node && node->open_count > 0)
 
 2374        pthread_mutex_unlock(&f->lock);
 
 2378static char *hidden_name(
struct fuse *f, 
fuse_ino_t dir, 
const char *oldname,
 
 2379                         char *newname, 
size_t bufsize)
 
 2383        struct node *newnode;
 
 2389                pthread_mutex_lock(&f->lock);
 
 2390                node = lookup_node(f, dir, oldname);
 
 2392                        pthread_mutex_unlock(&f->lock);
 
 2397                        snprintf(newname, bufsize, 
".fuse_hidden%08x%08x",
 
 2398                                 (
unsigned int) node->nodeid, f->hidectr);
 
 2399                        newnode = lookup_node(f, dir, newname);
 
 2402                res = try_get_path(f, dir, newname, &newpath, NULL, 
false);
 
 2403                pthread_mutex_unlock(&f->lock);
 
 2407                memset(&buf, 0, 
sizeof(buf));
 
 2408                res = fuse_fs_getattr(f->fs, newpath, &buf, NULL);
 
 2413        } 
while(res == 0 && --failctr);
 
 2418static int hide_node(
struct fuse *f, 
const char *oldpath,
 
 2425        newpath = hidden_name(f, dir, oldname, newname, 
sizeof(newname));
 
 2427                err = fuse_fs_rename(f->fs, oldpath, newpath, 0);
 
 2429                        err = rename_node(f, dir, oldname, dir, newname, 1);
 
 2435static int mtime_eq(
const struct stat *stbuf, 
const struct timespec *ts)
 
 2437        return stbuf->st_mtime == ts->tv_sec &&
 
 2438                ST_MTIM_NSEC(stbuf) == ts->tv_nsec;
 
 2441#ifndef CLOCK_MONOTONIC 
 2442#define CLOCK_MONOTONIC CLOCK_REALTIME 
 2445static void curr_time(
struct timespec *now)
 
 2447        static clockid_t clockid = CLOCK_MONOTONIC;
 
 2448        int res = clock_gettime(clockid, now);
 
 2449        if (res == -1 && errno == EINVAL) {
 
 2450                clockid = CLOCK_REALTIME;
 
 2451                res = clock_gettime(clockid, now);
 
 2454                perror(
"fuse: clock_gettime");
 
 2459static void update_stat(
struct node *node, 
const struct stat *stbuf)
 
 2461        if (node->cache_valid && (!mtime_eq(stbuf, &node->mtime) ||
 
 2462                                  stbuf->st_size != node->size))
 
 2463                node->cache_valid = 0;
 
 2464        node->mtime.tv_sec = stbuf->st_mtime;
 
 2465        node->mtime.tv_nsec = ST_MTIM_NSEC(stbuf);
 
 2466        node->size = stbuf->st_size;
 
 2467        curr_time(&node->stat_updated);
 
 2470static int do_lookup(
struct fuse *f, 
fuse_ino_t nodeid, 
const char *name,
 
 2475        node = find_node(f, nodeid, name);
 
 2479        e->
ino = node->nodeid;
 
 2483        if (f->conf.auto_cache) {
 
 2484                pthread_mutex_lock(&f->lock);
 
 2485                update_stat(node, &e->
attr);
 
 2486                pthread_mutex_unlock(&f->lock);
 
 2488        set_stat(f, e->
ino, &e->
attr);
 
 2492static int lookup_path(
struct fuse *f, 
fuse_ino_t nodeid,
 
 2493                       const char *name, 
const char *path,
 
 2499        res = fuse_fs_getattr(f->fs, path, &e->
attr, fi);
 
 2501                res = do_lookup(f, nodeid, name, e);
 
 2502                if (res == 0 && f->conf.debug) {
 
 2503                        fuse_log(FUSE_LOG_DEBUG, 
"   NODEID: %llu\n",
 
 2504                                (
unsigned long long) e->
ino);
 
 2510static struct fuse_context_i *fuse_get_context_internal(
void)
 
 2512        return (
struct fuse_context_i *) pthread_getspecific(fuse_context_key);
 
 2515static struct fuse_context_i *fuse_create_context(
struct fuse *f)
 
 2517        struct fuse_context_i *c = fuse_get_context_internal();
 
 2519                c = (
struct fuse_context_i *)
 
 2520                        calloc(1, 
sizeof(
struct fuse_context_i));
 
 2526                        fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate thread specific data\n");
 
 2529                pthread_setspecific(fuse_context_key, c);
 
 2531                memset(c, 0, 
sizeof(*c));
 
 2538static void fuse_freecontext(
void *data)
 
 2543static int fuse_create_context_key(
void)
 
 2546        pthread_mutex_lock(&fuse_context_lock);
 
 2547        if (!fuse_context_ref) {
 
 2548                err = pthread_key_create(&fuse_context_key, fuse_freecontext);
 
 2550                        fuse_log(FUSE_LOG_ERR, 
"fuse: failed to create thread specific key: %s\n",
 
 2552                        pthread_mutex_unlock(&fuse_context_lock);
 
 2557        pthread_mutex_unlock(&fuse_context_lock);
 
 2561static void fuse_delete_context_key(
void)
 
 2563        pthread_mutex_lock(&fuse_context_lock);
 
 2565        if (!fuse_context_ref) {
 
 2566                free(pthread_getspecific(fuse_context_key));
 
 2567                pthread_key_delete(fuse_context_key);
 
 2569        pthread_mutex_unlock(&fuse_context_lock);
 
 2572static struct fuse *req_fuse_prepare(
fuse_req_t req)
 
 2574        struct fuse_context_i *c = fuse_create_context(req_fuse(req));
 
 2577        c->ctx.uid = ctx->
uid;
 
 2578        c->ctx.gid = ctx->
gid;
 
 2579        c->ctx.pid = ctx->
pid;
 
 2580        c->ctx.umask = ctx->
umask;
 
 2584static inline void reply_err(
fuse_req_t req, 
int err)
 
 2594                struct fuse *f = req_fuse(req);
 
 2598                                forget_node(f, e->
ino, 1);
 
 2601                reply_err(req, err);
 
 2604void fuse_fs_init(
struct fuse_fs *fs, 
struct fuse_conn_info *conn,
 
 2608        if (!fs->op.write_buf)
 
 2609                conn->
want &= ~FUSE_CAP_SPLICE_READ;
 
 2611                conn->
want &= ~FUSE_CAP_POSIX_LOCKS;
 
 2613                conn->
want &= ~FUSE_CAP_FLOCK_LOCKS;
 
 2615                fs->user_data = fs->op.init(conn, cfg);
 
 2618static int fuse_init_intr_signal(
int signum, 
int *installed);
 
 2620static void fuse_lib_init(
void *data, 
struct fuse_conn_info *conn)
 
 2622        struct fuse *f = (
struct fuse *) data;
 
 2624        fuse_create_context(f);
 
 2626        fuse_fs_init(f->fs, conn, &f->conf);
 
 2629                if (fuse_init_intr_signal(f->conf.intr_signal,
 
 2630                                &f->intr_installed) == -1)
 
 2631                        fuse_log(FUSE_LOG_ERR, 
"fuse: failed to init interrupt signal\n");
 
 2638void fuse_fs_destroy(
struct fuse_fs *fs)
 
 2642                fs->op.destroy(fs->user_data);
 
 2645static void fuse_lib_destroy(
void *data)
 
 2647        struct fuse *f = (
struct fuse *) data;
 
 2649        fuse_create_context(f);
 
 2650        fuse_fs_destroy(f->fs);
 
 2656        struct fuse *f = req_fuse_prepare(req);
 
 2660        struct node *dot = NULL;
 
 2662        if (name[0] == 
'.') {
 
 2663                int len = strlen(name);
 
 2665                if (len == 1 || (name[1] == 
'.' && len == 2)) {
 
 2666                        pthread_mutex_lock(&f->lock);
 
 2669                                        fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOT\n");
 
 2670                                dot = get_node_nocheck(f, parent);
 
 2672                                        pthread_mutex_unlock(&f->lock);
 
 2673                                        reply_entry(req, &e, -ESTALE);
 
 2679                                        fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP-DOTDOT\n");
 
 2680                                parent = get_node(f, parent)->parent->nodeid;
 
 2682                        pthread_mutex_unlock(&f->lock);
 
 2687        err = get_path_name(f, parent, name, &path);
 
 2689                struct fuse_intr_data d;
 
 2691                        fuse_log(FUSE_LOG_DEBUG, 
"LOOKUP %s\n", path);
 
 2692                fuse_prepare_interrupt(f, req, &d);
 
 2693                err = lookup_path(f, parent, name, path, &e, NULL);
 
 2694                if (err == -ENOENT && f->conf.negative_timeout != 0.0) {
 
 2699                fuse_finish_interrupt(f, req, &d);
 
 2700                free_path(f, parent, path);
 
 2703                pthread_mutex_lock(&f->lock);
 
 2705                pthread_mutex_unlock(&f->lock);
 
 2707        reply_entry(req, &e, err);
 
 2710static void do_forget(
struct fuse *f, 
fuse_ino_t ino, uint64_t nlookup)
 
 2713                fuse_log(FUSE_LOG_DEBUG, 
"FORGET %llu/%llu\n", (
unsigned long long)ino,
 
 2714                        (
unsigned long long) nlookup);
 
 2715        forget_node(f, ino, nlookup);
 
 2720        do_forget(req_fuse(req), ino, nlookup);
 
 2724static void fuse_lib_forget_multi(
fuse_req_t req, 
size_t count,
 
 2725                                  struct fuse_forget_data *forgets)
 
 2727        struct fuse *f = req_fuse(req);
 
 2730        for (i = 0; i < count; i++)
 
 2731                do_forget(f, forgets[i].ino, forgets[i].nlookup);
 
 2740        struct fuse *f = req_fuse_prepare(req);
 
 2745        memset(&buf, 0, 
sizeof(buf));
 
 2748                err = get_path_nullok(f, ino, &path);
 
 2750                err = get_path(f, ino, &path);
 
 2752                struct fuse_intr_data d;
 
 2753                fuse_prepare_interrupt(f, req, &d);
 
 2754                err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2755                fuse_finish_interrupt(f, req, &d);
 
 2756                free_path(f, ino, path);
 
 2761                pthread_mutex_lock(&f->lock);
 
 2762                node = get_node(f, ino);
 
 2763                if (node->is_hidden && buf.st_nlink > 0)
 
 2765                if (f->conf.auto_cache)
 
 2766                        update_stat(node, &buf);
 
 2767                pthread_mutex_unlock(&f->lock);
 
 2768                set_stat(f, ino, &buf);
 
 2771                reply_err(req, err);
 
 2774int fuse_fs_chmod(
struct fuse_fs *fs, 
const char *path, mode_t mode,
 
 2781                        fuse_log(FUSE_LOG_DEBUG, 
"chmod[%s] %s %llo\n",
 
 2782                                file_info_string(fi, buf, 
sizeof(buf)),
 
 2783                                path, (
unsigned long long) mode);
 
 2785                return fs->op.chmod(path, mode, fi);
 
 2794        struct fuse *f = req_fuse_prepare(req);
 
 2799        memset(&buf, 0, 
sizeof(buf));
 
 2801                err = get_path_nullok(f, ino, &path);
 
 2803                err = get_path(f, ino, &path);
 
 2805                struct fuse_intr_data d;
 
 2806                fuse_prepare_interrupt(f, req, &d);
 
 2808                if (!err && (valid & FUSE_SET_ATTR_MODE))
 
 2809                        err = fuse_fs_chmod(f->fs, path, attr->st_mode, fi);
 
 2810                if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) {
 
 2811                        uid_t uid = (valid & FUSE_SET_ATTR_UID) ?
 
 2812                                attr->st_uid : (uid_t) -1;
 
 2813                        gid_t gid = (valid & FUSE_SET_ATTR_GID) ?
 
 2814                                attr->st_gid : (gid_t) -1;
 
 2815                        err = fuse_fs_chown(f->fs, path, uid, gid, fi);
 
 2817                if (!err && (valid & FUSE_SET_ATTR_SIZE)) {
 
 2818                        err = fuse_fs_truncate(f->fs, path,
 
 2821#ifdef HAVE_UTIMENSAT 
 2823                    (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))) {
 
 2824                        struct timespec tv[2];
 
 2828                        tv[0].tv_nsec = UTIME_OMIT;
 
 2829                        tv[1].tv_nsec = UTIME_OMIT;
 
 2831                        if (valid & FUSE_SET_ATTR_ATIME_NOW)
 
 2832                                tv[0].tv_nsec = UTIME_NOW;
 
 2833                        else if (valid & FUSE_SET_ATTR_ATIME)
 
 2834                                tv[0] = attr->st_atim;
 
 2836                        if (valid & FUSE_SET_ATTR_MTIME_NOW)
 
 2837                                tv[1].tv_nsec = UTIME_NOW;
 
 2838                        else if (valid & FUSE_SET_ATTR_MTIME)
 
 2839                                tv[1] = attr->st_mtim;
 
 2841                        err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2845                    (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) ==
 
 2846                    (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) {
 
 2847                        struct timespec tv[2];
 
 2848                        tv[0].tv_sec = attr->st_atime;
 
 2849                        tv[0].tv_nsec = ST_ATIM_NSEC(attr);
 
 2850                        tv[1].tv_sec = attr->st_mtime;
 
 2851                        tv[1].tv_nsec = ST_MTIM_NSEC(attr);
 
 2852                        err = fuse_fs_utimens(f->fs, path, tv, fi);
 
 2855                        err = fuse_fs_getattr(f->fs, path, &buf, fi);
 
 2857                fuse_finish_interrupt(f, req, &d);
 
 2858                free_path(f, ino, path);
 
 2861                if (f->conf.auto_cache) {
 
 2862                        pthread_mutex_lock(&f->lock);
 
 2863                        update_stat(get_node(f, ino), &buf);
 
 2864                        pthread_mutex_unlock(&f->lock);
 
 2866                set_stat(f, ino, &buf);
 
 2869                reply_err(req, err);
 
 2874        struct fuse *f = req_fuse_prepare(req);
 
 2878        err = get_path(f, ino, &path);
 
 2880                struct fuse_intr_data d;
 
 2882                fuse_prepare_interrupt(f, req, &d);
 
 2883                err = fuse_fs_access(f->fs, path, mask);
 
 2884                fuse_finish_interrupt(f, req, &d);
 
 2885                free_path(f, ino, path);
 
 2887        reply_err(req, err);
 
 2892        struct fuse *f = req_fuse_prepare(req);
 
 2893        char linkname[PATH_MAX + 1];
 
 2897        err = get_path(f, ino, &path);
 
 2899                struct fuse_intr_data d;
 
 2900                fuse_prepare_interrupt(f, req, &d);
 
 2901                err = fuse_fs_readlink(f->fs, path, linkname, 
sizeof(linkname));
 
 2902                fuse_finish_interrupt(f, req, &d);
 
 2903                free_path(f, ino, path);
 
 2906                linkname[PATH_MAX] = 
'\0';
 
 2909                reply_err(req, err);
 
 2913                           mode_t mode, dev_t rdev)
 
 2915        struct fuse *f = req_fuse_prepare(req);
 
 2920        err = get_path_name(f, parent, name, &path);
 
 2922                struct fuse_intr_data d;
 
 2924                fuse_prepare_interrupt(f, req, &d);
 
 2926                if (S_ISREG(mode)) {
 
 2929                        memset(&fi, 0, 
sizeof(fi));
 
 2930                        fi.
flags = O_CREAT | O_EXCL | O_WRONLY;
 
 2931                        err = fuse_fs_create(f->fs, path, mode, &fi);
 
 2933                                err = lookup_path(f, parent, name, path, &e,
 
 2935                                fuse_fs_release(f->fs, path, &fi);
 
 2938                if (err == -ENOSYS) {
 
 2939                        err = fuse_fs_mknod(f->fs, path, mode, rdev);
 
 2941                                err = lookup_path(f, parent, name, path, &e,
 
 2944                fuse_finish_interrupt(f, req, &d);
 
 2945                free_path(f, parent, path);
 
 2947        reply_entry(req, &e, err);
 
 2953        struct fuse *f = req_fuse_prepare(req);
 
 2958        err = get_path_name(f, parent, name, &path);
 
 2960                struct fuse_intr_data d;
 
 2962                fuse_prepare_interrupt(f, req, &d);
 
 2963                err = fuse_fs_mkdir(f->fs, path, mode);
 
 2965                        err = lookup_path(f, parent, name, path, &e, NULL);
 
 2966                fuse_finish_interrupt(f, req, &d);
 
 2967                free_path(f, parent, path);
 
 2969        reply_entry(req, &e, err);
 
 2975        struct fuse *f = req_fuse_prepare(req);
 
 2980        err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 2982                struct fuse_intr_data d;
 
 2984                fuse_prepare_interrupt(f, req, &d);
 
 2985                if (!f->conf.hard_remove && is_open(f, parent, name)) {
 
 2986                        err = hide_node(f, path, parent, name);
 
 2989                                if (!is_open(f, parent, wnode->name)) {
 
 2993                                        if (try_get_path(f, wnode->nodeid, NULL, &unlinkpath, NULL, 
false) == 0) {
 
 2994                                                err = fuse_fs_unlink(f->fs, unlinkpath);
 
 2996                                                        remove_node(f, parent, wnode->name);
 
 3002                        err = fuse_fs_unlink(f->fs, path);
 
 3004                                remove_node(f, parent, name);
 
 3006                fuse_finish_interrupt(f, req, &d);
 
 3007                free_path_wrlock(f, parent, wnode, path);
 
 3009        reply_err(req, err);
 
 3014        struct fuse *f = req_fuse_prepare(req);
 
 3019        err = get_path_wrlock(f, parent, name, &path, &wnode);
 
 3021                struct fuse_intr_data d;
 
 3023                fuse_prepare_interrupt(f, req, &d);
 
 3024                err = fuse_fs_rmdir(f->fs, path);
 
 3025                fuse_finish_interrupt(f, req, &d);
 
 3027                        remove_node(f, parent, name);
 
 3028                free_path_wrlock(f, parent, wnode, path);
 
 3030        reply_err(req, err);
 
 3033static void fuse_lib_symlink(
fuse_req_t req, 
const char *linkname,
 
 3036        struct fuse *f = req_fuse_prepare(req);
 
 3041        err = get_path_name(f, parent, name, &path);
 
 3043                struct fuse_intr_data d;
 
 3045                fuse_prepare_interrupt(f, req, &d);
 
 3046                err = fuse_fs_symlink(f->fs, linkname, path);
 
 3048                        err = lookup_path(f, parent, name, path, &e, NULL);
 
 3049                fuse_finish_interrupt(f, req, &d);
 
 3050                free_path(f, parent, path);
 
 3052        reply_entry(req, &e, err);
 
 3057                            const char *newname, 
unsigned int flags)
 
 3059        struct fuse *f = req_fuse_prepare(req);
 
 3062        struct node *wnode1;
 
 3063        struct node *wnode2;
 
 3066        err = get_path2(f, olddir, oldname, newdir, newname,
 
 3067                        &oldpath, &newpath, &wnode1, &wnode2);
 
 3069                struct fuse_intr_data d;
 
 3071                fuse_prepare_interrupt(f, req, &d);
 
 3072                if (!f->conf.hard_remove && !(flags & RENAME_EXCHANGE) &&
 
 3073                    is_open(f, newdir, newname))
 
 3074                        err = hide_node(f, newpath, newdir, newname);
 
 3076                        err = fuse_fs_rename(f->fs, oldpath, newpath, flags);
 
 3078                                if (flags & RENAME_EXCHANGE) {
 
 3079                                        err = exchange_node(f, olddir, oldname,
 
 3082                                        err = rename_node(f, olddir, oldname,
 
 3083                                                          newdir, newname, 0);
 
 3087                fuse_finish_interrupt(f, req, &d);
 
 3088                free_path2(f, olddir, newdir, wnode1, wnode2, oldpath, newpath);
 
 3090        reply_err(req, err);
 
 3094                          const char *newname)
 
 3096        struct fuse *f = req_fuse_prepare(req);
 
 3102        err = get_path2(f, 
ino, NULL, newparent, newname,
 
 3103                        &oldpath, &newpath, NULL, NULL);
 
 3105                struct fuse_intr_data d;
 
 3107                fuse_prepare_interrupt(f, req, &d);
 
 3108                err = fuse_fs_link(f->fs, oldpath, newpath);
 
 3110                        err = lookup_path(f, newparent, newname, newpath,
 
 3112                fuse_finish_interrupt(f, req, &d);
 
 3113                free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath);
 
 3115        reply_entry(req, &e, err);
 
 3118static void fuse_do_release(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3122        int unlink_hidden = 0;
 
 3124        fuse_fs_release(f->fs, path, fi);
 
 3126        pthread_mutex_lock(&f->lock);
 
 3127        node = get_node(f, ino);
 
 3128        assert(node->open_count > 0);
 
 3130        if (node->is_hidden && !node->open_count) {
 
 3132                node->is_hidden = 0;
 
 3134        pthread_mutex_unlock(&f->lock);
 
 3138                        fuse_fs_unlink(f->fs, path);
 
 3139                } 
else if (f->conf.nullpath_ok) {
 
 3142                        if (get_path(f, ino, &unlinkpath) == 0)
 
 3143                                fuse_fs_unlink(f->fs, unlinkpath);
 
 3145                        free_path(f, ino, unlinkpath);
 
 3151                            const char *name, mode_t mode,
 
 3154        struct fuse *f = req_fuse_prepare(req);
 
 3155        struct fuse_intr_data d;
 
 3160        err = get_path_name(f, parent, name, &path);
 
 3162                fuse_prepare_interrupt(f, req, &d);
 
 3163                err = fuse_fs_create(f->fs, path, mode, fi);
 
 3165                        err = lookup_path(f, parent, name, path, &e, fi);
 
 3167                                fuse_fs_release(f->fs, path, fi);
 
 3168                        else if (!S_ISREG(e.
attr.st_mode)) {
 
 3170                                fuse_fs_release(f->fs, path, fi);
 
 3171                                forget_node(f, e.
ino, 1);
 
 3173                                if (f->conf.direct_io)
 
 3175                                if (f->conf.kernel_cache)
 
 3178                                    f->conf.parallel_direct_writes)
 
 3182                fuse_finish_interrupt(f, req, &d);
 
 3185                pthread_mutex_lock(&f->lock);
 
 3186                get_node(f, e.
ino)->open_count++;
 
 3187                pthread_mutex_unlock(&f->lock);
 
 3191                        fuse_do_release(f, e.
ino, path, fi);
 
 3192                        forget_node(f, e.
ino, 1);
 
 3195                reply_err(req, err);
 
 3198        free_path(f, parent, path);
 
 3201static double diff_timespec(
const struct timespec *t1,
 
 3202                            const struct timespec *t2)
 
 3204        return (t1->tv_sec - t2->tv_sec) +
 
 3205                ((double) t1->tv_nsec - (
double) t2->tv_nsec) / 1000000000.0;
 
 3208static void open_auto_cache(
struct fuse *f, 
fuse_ino_t ino, 
const char *path,
 
 3213        pthread_mutex_lock(&f->lock);
 
 3214        node = get_node(f, ino);
 
 3215        if (node->cache_valid) {
 
 3216                struct timespec now;
 
 3219                if (diff_timespec(&now, &node->stat_updated) >
 
 3220                    f->conf.ac_attr_timeout) {
 
 3223                        pthread_mutex_unlock(&f->lock);
 
 3224                        err = fuse_fs_getattr(f->fs, path, &stbuf, fi);
 
 3225                        pthread_mutex_lock(&f->lock);
 
 3227                                update_stat(node, &stbuf);
 
 3229                                node->cache_valid = 0;
 
 3232        if (node->cache_valid)
 
 3235        node->cache_valid = 1;
 
 3236        pthread_mutex_unlock(&f->lock);
 
 3242        struct fuse *f = req_fuse_prepare(req);
 
 3243        struct fuse_intr_data d;
 
 3247        err = get_path(f, ino, &path);
 
 3249                fuse_prepare_interrupt(f, req, &d);
 
 3250                err = fuse_fs_open(f->fs, path, fi);
 
 3252                        if (f->conf.direct_io)
 
 3254                        if (f->conf.kernel_cache)
 
 3257                        if (f->conf.auto_cache)
 
 3258                                open_auto_cache(f, ino, path, fi);
 
 3260                        if (f->conf.no_rofd_flush &&
 
 3261                            (fi->
flags & O_ACCMODE) == O_RDONLY)
 
 3264                        if (fi->
direct_io && f->conf.parallel_direct_writes)
 
 3268                fuse_finish_interrupt(f, req, &d);
 
 3271                pthread_mutex_lock(&f->lock);
 
 3272                get_node(f, ino)->open_count++;
 
 3273                pthread_mutex_unlock(&f->lock);
 
 3277                        fuse_do_release(f, ino, path, fi);
 
 3280                reply_err(req, err);
 
 3282        free_path(f, ino, path);
 
 3288        struct fuse *f = req_fuse_prepare(req);
 
 3293        res = get_path_nullok(f, ino, &path);
 
 3295                struct fuse_intr_data d;
 
 3297                fuse_prepare_interrupt(f, req, &d);
 
 3298                res = fuse_fs_read_buf(f->fs, path, &buf, size, off, fi);
 
 3299                fuse_finish_interrupt(f, req, &d);
 
 3300                free_path(f, ino, path);
 
 3306                reply_err(req, res);
 
 3315        struct fuse *f = req_fuse_prepare(req);
 
 3319        res = get_path_nullok(f, ino, &path);
 
 3321                struct fuse_intr_data d;
 
 3323                fuse_prepare_interrupt(f, req, &d);
 
 3324                res = fuse_fs_write_buf(f->fs, path, buf, off, fi);
 
 3325                fuse_finish_interrupt(f, req, &d);
 
 3326                free_path(f, ino, path);
 
 3332                reply_err(req, res);
 
 3338        struct fuse *f = req_fuse_prepare(req);
 
 3342        err = get_path_nullok(f, ino, &path);
 
 3344                struct fuse_intr_data d;
 
 3346                fuse_prepare_interrupt(f, req, &d);
 
 3347                err = fuse_fs_fsync(f->fs, path, datasync, fi);
 
 3348                fuse_finish_interrupt(f, req, &d);
 
 3349                free_path(f, ino, path);
 
 3351        reply_err(req, err);
 
 3354static struct fuse_dh *get_dirhandle(
const struct fuse_file_info *llfi,
 
 3357        struct fuse_dh *dh = (
struct fuse_dh *) (uintptr_t) llfi->
fh;
 
 3366        struct fuse *f = req_fuse_prepare(req);
 
 3367        struct fuse_intr_data d;
 
 3373        dh = (
struct fuse_dh *) malloc(
sizeof(
struct fuse_dh));
 
 3375                reply_err(req, -ENOMEM);
 
 3378        memset(dh, 0, 
sizeof(
struct fuse_dh));
 
 3380        dh->contents = NULL;
 
 3385        pthread_mutex_init(&dh->lock, NULL);
 
 3387        llfi->
fh = (uintptr_t) dh;
 
 3389        memset(&fi, 0, 
sizeof(fi));
 
 3392        err = get_path(f, ino, &path);
 
 3394                fuse_prepare_interrupt(f, req, &d);
 
 3395                err = fuse_fs_opendir(f->fs, path, &fi);
 
 3396                fuse_finish_interrupt(f, req, &d);
 
 3405                        fuse_fs_releasedir(f->fs, path, &fi);
 
 3406                        pthread_mutex_destroy(&dh->lock);
 
 3410                reply_err(req, err);
 
 3411                pthread_mutex_destroy(&dh->lock);
 
 3414        free_path(f, ino, path);
 
 3417static int extend_contents(
struct fuse_dh *dh, 
unsigned minsize)
 
 3419        if (minsize > dh->size) {
 
 3421                unsigned newsize = dh->size;
 
 3424                while (newsize < minsize) {
 
 3425                        if (newsize >= 0x80000000)
 
 3426                                newsize = 0xffffffff;
 
 3431                newptr = (
char *) realloc(dh->contents, newsize);
 
 3433                        dh->error = -ENOMEM;
 
 3436                dh->contents = newptr;
 
 3442static int fuse_add_direntry_to_dh(
struct fuse_dh *dh, 
const char *name,
 
 3445        struct fuse_direntry *de;
 
 3447        de = malloc(
sizeof(
struct fuse_direntry));
 
 3449                dh->error = -ENOMEM;
 
 3452        de->name = strdup(name);
 
 3454                dh->error = -ENOMEM;
 
 3463        dh->last = &de->next;
 
 3474        pthread_mutex_lock(&f->lock);
 
 3475        node = lookup_node(f, parent, name);
 
 3478        pthread_mutex_unlock(&f->lock);
 
 3483static int fill_dir(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3486        struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3489        if ((flags & ~FUSE_FILL_DIR_PLUS) != 0) {
 
 3497                memset(&stbuf, 0, 
sizeof(stbuf));
 
 3498                stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3501        if (!dh->fuse->conf.use_ino) {
 
 3502                stbuf.st_ino = FUSE_UNKNOWN_INO;
 
 3503                if (dh->fuse->conf.readdir_ino) {
 
 3504                        stbuf.st_ino = (ino_t)
 
 3505                                lookup_nodeid(dh->fuse, dh->nodeid, name);
 
 3522                if (extend_contents(dh, dh->needlen) == -1)
 
 3527                                          dh->needlen - dh->len, name,
 
 3529                if (newlen > dh->needlen)
 
 3536                if (fuse_add_direntry_to_dh(dh, name, &stbuf, flags) == -1)
 
 3542static int is_dot_or_dotdot(
const char *name)
 
 3544        return name[0] == 
'.' && (name[1] == 
'\0' ||
 
 3545                                  (name[1] == 
'.' && name[2] == 
'\0'));
 
 3548static int fill_dir_plus(
void *dh_, 
const char *name, 
const struct stat *statp,
 
 3551        struct fuse_dh *dh = (
struct fuse_dh *) dh_;
 
 3556        struct fuse *f = dh->fuse;
 
 3559        if ((flags & ~FUSE_FILL_DIR_PLUS) != 0) {
 
 3564        if (statp && (flags & FUSE_FILL_DIR_PLUS)) {
 
 3567                e.
attr.st_ino = FUSE_UNKNOWN_INO;
 
 3569                        e.
attr.st_mode = statp->st_mode;
 
 3570                        if (f->conf.use_ino)
 
 3571                                e.
attr.st_ino = statp->st_ino;
 
 3573                if (!f->conf.use_ino && f->conf.readdir_ino) {
 
 3574                        e.
attr.st_ino = (ino_t)
 
 3575                                lookup_nodeid(f, dh->nodeid, name);
 
 3591                if (extend_contents(dh, dh->needlen) == -1)
 
 3594                if (statp && (flags & FUSE_FILL_DIR_PLUS)) {
 
 3595                        if (!is_dot_or_dotdot(name)) {
 
 3596                                res = do_lookup(f, dh->nodeid, name, &e);
 
 3606                                               dh->needlen - dh->len, name,
 
 3608                if (newlen > dh->needlen)
 
 3614                if (fuse_add_direntry_to_dh(dh, name, &e.
attr, flags) == -1)
 
 3621static void free_direntries(
struct fuse_direntry *de)
 
 3624                struct fuse_direntry *next = de->next;
 
 3632                        size_t size, off_t off, 
struct fuse_dh *dh,
 
 3639        if (f->fs->op.readdir)
 
 3640                err = get_path_nullok(f, ino, &path);
 
 3642                err = get_path(f, ino, &path);
 
 3644                struct fuse_intr_data d;
 
 3647                if (flags & FUSE_READDIR_PLUS)
 
 3648                        filler = fill_dir_plus;
 
 3650                free_direntries(dh->first);
 
 3652                dh->last = &dh->first;
 
 3658                fuse_prepare_interrupt(f, req, &d);
 
 3659                err = fuse_fs_readdir(f->fs, path, dh, filler, off, fi, flags);
 
 3660                fuse_finish_interrupt(f, req, &d);
 
 3666                free_path(f, ino, path);
 
 3671static int readdir_fill_from_list(
fuse_req_t req, 
struct fuse_dh *dh,
 
 3675        struct fuse_direntry *de = dh->first;
 
 3680        if (extend_contents(dh, dh->needlen) == -1)
 
 3683        for (pos = 0; pos < off; pos++) {
 
 3690                char *p = dh->contents + dh->len;
 
 3691                unsigned rem = dh->needlen - dh->len;
 
 3696                if (flags & FUSE_READDIR_PLUS) {
 
 3702                        if (de->flags & FUSE_FILL_DIR_PLUS &&
 
 3703                            !is_dot_or_dotdot(de->name)) {
 
 3704                                res = do_lookup(dh->fuse, dh->nodeid,
 
 3716                                                    de->name, &de->stat, pos);
 
 3718                newlen = dh->len + thislen;
 
 3719                if (newlen > dh->needlen)
 
 3731        struct fuse *f = req_fuse_prepare(req);
 
 3733        struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3736        pthread_mutex_lock(&dh->lock);
 
 3743                err = readdir_fill(f, req, ino, size, off, dh, &fi, flags);
 
 3745                        reply_err(req, err);
 
 3751                err = readdir_fill_from_list(req, dh, off, flags);
 
 3753                        reply_err(req, err);
 
 3759        pthread_mutex_unlock(&dh->lock);
 
 3765        fuse_readdir_common(req, ino, size, off, llfi, 0);
 
 3771        fuse_readdir_common(req, ino, size, off, llfi, FUSE_READDIR_PLUS);
 
 3777        struct fuse *f = req_fuse_prepare(req);
 
 3778        struct fuse_intr_data d;
 
 3780        struct fuse_dh *dh = get_dirhandle(llfi, &fi);
 
 3783        get_path_nullok(f, ino, &path);
 
 3785        fuse_prepare_interrupt(f, req, &d);
 
 3786        fuse_fs_releasedir(f->fs, path, &fi);
 
 3787        fuse_finish_interrupt(f, req, &d);
 
 3788        free_path(f, ino, path);
 
 3790        pthread_mutex_lock(&dh->lock);
 
 3791        pthread_mutex_unlock(&dh->lock);
 
 3792        pthread_mutex_destroy(&dh->lock);
 
 3793        free_direntries(dh->first);
 
 3802        struct fuse *f = req_fuse_prepare(req);
 
 3807        get_dirhandle(llfi, &fi);
 
 3809        err = get_path_nullok(f, ino, &path);
 
 3811                struct fuse_intr_data d;
 
 3812                fuse_prepare_interrupt(f, req, &d);
 
 3813                err = fuse_fs_fsyncdir(f->fs, path, datasync, &fi);
 
 3814                fuse_finish_interrupt(f, req, &d);
 
 3815                free_path(f, ino, path);
 
 3817        reply_err(req, err);
 
 3822        struct fuse *f = req_fuse_prepare(req);
 
 3827        memset(&buf, 0, 
sizeof(buf));
 
 3829                err = get_path(f, ino, &path);
 
 3832                struct fuse_intr_data d;
 
 3833                fuse_prepare_interrupt(f, req, &d);
 
 3834                err = fuse_fs_statfs(f->fs, path ? path : 
"/", &buf);
 
 3835                fuse_finish_interrupt(f, req, &d);
 
 3836                free_path(f, ino, path);
 
 3842                reply_err(req, err);
 
 3846                              const char *value, 
size_t size, 
int flags)
 
 3848        struct fuse *f = req_fuse_prepare(req);
 
 3852        err = get_path(f, ino, &path);
 
 3854                struct fuse_intr_data d;
 
 3855                fuse_prepare_interrupt(f, req, &d);
 
 3856                err = fuse_fs_setxattr(f->fs, path, name, value, size, flags);
 
 3857                fuse_finish_interrupt(f, req, &d);
 
 3858                free_path(f, ino, path);
 
 3860        reply_err(req, err);
 
 3864                           const char *name, 
char *value, 
size_t size)
 
 3869        err = get_path(f, ino, &path);
 
 3871                struct fuse_intr_data d;
 
 3872                fuse_prepare_interrupt(f, req, &d);
 
 3873                err = fuse_fs_getxattr(f->fs, path, name, value, size);
 
 3874                fuse_finish_interrupt(f, req, &d);
 
 3875                free_path(f, ino, path);
 
 3883        struct fuse *f = req_fuse_prepare(req);
 
 3887                char *value = (
char *) malloc(size);
 
 3888                if (value == NULL) {
 
 3889                        reply_err(req, -ENOMEM);
 
 3892                res = common_getxattr(f, req, ino, name, value, size);
 
 3896                        reply_err(req, res);
 
 3899                res = common_getxattr(f, req, ino, name, NULL, 0);
 
 3903                        reply_err(req, res);
 
 3908                            char *list, 
size_t size)
 
 3913        err = get_path(f, ino, &path);
 
 3915                struct fuse_intr_data d;
 
 3916                fuse_prepare_interrupt(f, req, &d);
 
 3917                err = fuse_fs_listxattr(f->fs, path, list, size);
 
 3918                fuse_finish_interrupt(f, req, &d);
 
 3919                free_path(f, ino, path);
 
 3926        struct fuse *f = req_fuse_prepare(req);
 
 3930                char *list = (
char *) malloc(size);
 
 3932                        reply_err(req, -ENOMEM);
 
 3935                res = common_listxattr(f, req, ino, list, size);
 
 3939                        reply_err(req, res);
 
 3942                res = common_listxattr(f, req, ino, NULL, 0);
 
 3946                        reply_err(req, res);
 
 3953        struct fuse *f = req_fuse_prepare(req);
 
 3957        err = get_path(f, ino, &path);
 
 3959                struct fuse_intr_data d;
 
 3960                fuse_prepare_interrupt(f, req, &d);
 
 3961                err = fuse_fs_removexattr(f->fs, path, name);
 
 3962                fuse_finish_interrupt(f, req, &d);
 
 3963                free_path(f, ino, path);
 
 3965        reply_err(req, err);
 
 3968static struct lock *locks_conflict(
struct node *node, 
const struct lock *lock)
 
 3972        for (l = node->locks; l; l = l->next)
 
 3973                if (l->owner != lock->owner &&
 
 3974                    lock->start <= l->end && l->start <= lock->end &&
 
 3975                    (l->type == F_WRLCK || lock->type == F_WRLCK))
 
 3981static void delete_lock(
struct lock **lockp)
 
 3983        struct lock *l = *lockp;
 
 3988static void insert_lock(
struct lock **pos, 
struct lock *lock)
 
 3994static int locks_insert(
struct node *node, 
struct lock *lock)
 
 3997        struct lock *newl1 = NULL;
 
 3998        struct lock *newl2 = NULL;
 
 4000        if (lock->type != F_UNLCK || lock->start != 0 ||
 
 4001            lock->end != OFFSET_MAX) {
 
 4002                newl1 = malloc(
sizeof(
struct lock));
 
 4003                newl2 = malloc(
sizeof(
struct lock));
 
 4005                if (!newl1 || !newl2) {
 
 4012        for (lp = &node->locks; *lp;) {
 
 4013                struct lock *l = *lp;
 
 4014                if (l->owner != lock->owner)
 
 4017                if (lock->type == l->type) {
 
 4018                        if (l->end < lock->start - 1)
 
 4020                        if (lock->end < l->start - 1)
 
 4022                        if (l->start <= lock->start && lock->end <= l->end)
 
 4024                        if (l->start < lock->start)
 
 4025                                lock->start = l->start;
 
 4026                        if (lock->end < l->end)
 
 4030                        if (l->end < lock->start)
 
 4032                        if (lock->end < l->start)
 
 4034                        if (lock->start <= l->start && l->end <= lock->end)
 
 4036                        if (l->end <= lock->end) {
 
 4037                                l->end = lock->start - 1;
 
 4040                        if (lock->start <= l->start) {
 
 4041                                l->start = lock->end + 1;
 
 4045                        newl2->start = lock->end + 1;
 
 4046                        l->end = lock->start - 1;
 
 4047                        insert_lock(&l->next, newl2);
 
 4057        if (lock->type != F_UNLCK) {
 
 4059                insert_lock(lp, newl1);
 
 4068static void flock_to_lock(
struct flock *flock, 
struct lock *lock)
 
 4070        memset(lock, 0, 
sizeof(
struct lock));
 
 4071        lock->type = flock->l_type;
 
 4072        lock->start = flock->l_start;
 
 4074                flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX;
 
 4075        lock->pid = flock->l_pid;
 
 4078static void lock_to_flock(
struct lock *lock, 
struct flock *flock)
 
 4080        flock->l_type = lock->type;
 
 4081        flock->l_start = lock->start;
 
 4083                (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1;
 
 4084        flock->l_pid = lock->pid;
 
 4090        struct fuse_intr_data d;
 
 4096        fuse_prepare_interrupt(f, req, &d);
 
 4097        memset(&lock, 0, 
sizeof(lock));
 
 4098        lock.l_type = F_UNLCK;
 
 4099        lock.l_whence = SEEK_SET;
 
 4100        err = fuse_fs_flush(f->fs, path, fi);
 
 4101        errlock = fuse_fs_lock(f->fs, path, fi, F_SETLK, &lock);
 
 4102        fuse_finish_interrupt(f, req, &d);
 
 4104        if (errlock != -ENOSYS) {
 
 4105                flock_to_lock(&lock, &l);
 
 4107                pthread_mutex_lock(&f->lock);
 
 4108                locks_insert(get_node(f, ino), &l);
 
 4109                pthread_mutex_unlock(&f->lock);
 
 4122        struct fuse *f = req_fuse_prepare(req);
 
 4123        struct fuse_intr_data d;
 
 4127        get_path_nullok(f, ino, &path);
 
 4129                err = fuse_flush_common(f, req, ino, path, fi);
 
 4134        fuse_prepare_interrupt(f, req, &d);
 
 4135        fuse_do_release(f, ino, path, fi);
 
 4136        fuse_finish_interrupt(f, req, &d);
 
 4137        free_path(f, ino, path);
 
 4139        reply_err(req, err);
 
 4145        struct fuse *f = req_fuse_prepare(req);
 
 4149        get_path_nullok(f, ino, &path);
 
 4150        err = fuse_flush_common(f, req, ino, path, fi);
 
 4151        free_path(f, ino, path);
 
 4153        reply_err(req, err);
 
 4160        struct fuse *f = req_fuse_prepare(req);
 
 4164        err = get_path_nullok(f, ino, &path);
 
 4166                struct fuse_intr_data d;
 
 4167                fuse_prepare_interrupt(f, req, &d);
 
 4168                err = fuse_fs_lock(f->fs, path, fi, cmd, lock);
 
 4169                fuse_finish_interrupt(f, req, &d);
 
 4170                free_path(f, ino, path);
 
 4180        struct lock *conflict;
 
 4181        struct fuse *f = req_fuse(req);
 
 4183        flock_to_lock(lock, &l);
 
 4185        pthread_mutex_lock(&f->lock);
 
 4186        conflict = locks_conflict(get_node(f, ino), &l);
 
 4188                lock_to_flock(conflict, lock);
 
 4189        pthread_mutex_unlock(&f->lock);
 
 4191                err = fuse_lock_common(req, ino, fi, lock, F_GETLK);
 
 4198                reply_err(req, err);
 
 4205        int err = fuse_lock_common(req, ino, fi, lock,
 
 4206                                   sleep ? F_SETLKW : F_SETLK);
 
 4208                struct fuse *f = req_fuse(req);
 
 4210                flock_to_lock(lock, &l);
 
 4212                pthread_mutex_lock(&f->lock);
 
 4213                locks_insert(get_node(f, ino), &l);
 
 4214                pthread_mutex_unlock(&f->lock);
 
 4216        reply_err(req, err);
 
 4222        struct fuse *f = req_fuse_prepare(req);
 
 4226        err = get_path_nullok(f, ino, &path);
 
 4228                struct fuse_intr_data d;
 
 4229                fuse_prepare_interrupt(f, req, &d);
 
 4230                err = fuse_fs_flock(f->fs, path, fi, op);
 
 4231                fuse_finish_interrupt(f, req, &d);
 
 4232                free_path(f, ino, path);
 
 4234        reply_err(req, err);
 
 4240        struct fuse *f = req_fuse_prepare(req);
 
 4241        struct fuse_intr_data d;
 
 4245        err = get_path(f, ino, &path);
 
 4247                fuse_prepare_interrupt(f, req, &d);
 
 4248                err = fuse_fs_bmap(f->fs, path, blocksize, &idx);
 
 4249                fuse_finish_interrupt(f, req, &d);
 
 4250                free_path(f, ino, path);
 
 4255                reply_err(req, err);
 
 4260                           unsigned int flags, 
const void *in_buf,
 
 4261                           size_t in_bufsz, 
size_t out_bufsz)
 
 4263        struct fuse *f = req_fuse_prepare(req);
 
 4264        struct fuse_intr_data d;
 
 4266        char *path, *out_buf = NULL;
 
 4270        if (
flags & FUSE_IOCTL_UNRESTRICTED)
 
 4273        if (
flags & FUSE_IOCTL_DIR)
 
 4274                get_dirhandle(llfi, &fi);
 
 4280                out_buf = malloc(out_bufsz);
 
 4285        assert(!in_bufsz || !out_bufsz || in_bufsz == out_bufsz);
 
 4286        if (out_buf && in_bufsz)
 
 4287                memcpy(out_buf, in_buf, in_bufsz);
 
 4289        err = get_path_nullok(f, ino, &path);
 
 4293        fuse_prepare_interrupt(f, req, &d);
 
 4295        err = fuse_fs_ioctl(f->fs, path, cmd, arg, &fi, 
flags,
 
 4296                            out_buf ? out_buf : (void *)in_buf);
 
 4298        fuse_finish_interrupt(f, req, &d);
 
 4299        free_path(f, ino, path);
 
 4306        reply_err(req, err);
 
 4314        struct fuse *f = req_fuse_prepare(req);
 
 4315        struct fuse_intr_data d;
 
 4318        unsigned revents = 0;
 
 4320        err = get_path_nullok(f, ino, &path);
 
 4322                fuse_prepare_interrupt(f, req, &d);
 
 4323                err = fuse_fs_poll(f->fs, path, fi, ph, &revents);
 
 4324                fuse_finish_interrupt(f, req, &d);
 
 4325                free_path(f, ino, path);
 
 4330                reply_err(req, err);
 
 4336        struct fuse *f = req_fuse_prepare(req);
 
 4337        struct fuse_intr_data d;
 
 4341        err = get_path_nullok(f, ino, &path);
 
 4343                fuse_prepare_interrupt(f, req, &d);
 
 4344                err = fuse_fs_fallocate(f->fs, path, mode, offset, length, fi);
 
 4345                fuse_finish_interrupt(f, req, &d);
 
 4346                free_path(f, ino, path);
 
 4348        reply_err(req, err);
 
 4357        struct fuse *f = req_fuse_prepare(req);
 
 4358        struct fuse_intr_data d;
 
 4359        char *path_in, *path_out;
 
 4363        err = get_path_nullok(f, nodeid_in, &path_in);
 
 4365                reply_err(req, err);
 
 4369        err = get_path_nullok(f, nodeid_out, &path_out);
 
 4371                free_path(f, nodeid_in, path_in);
 
 4372                reply_err(req, err);
 
 4376        fuse_prepare_interrupt(f, req, &d);
 
 4377        res = fuse_fs_copy_file_range(f->fs, path_in, fi_in, off_in, path_out,
 
 4378                                      fi_out, off_out, len, flags);
 
 4379        fuse_finish_interrupt(f, req, &d);
 
 4384                reply_err(req, res);
 
 4386        free_path(f, nodeid_in, path_in);
 
 4387        free_path(f, nodeid_out, path_out);
 
 4393        struct fuse *f = req_fuse_prepare(req);
 
 4394        struct fuse_intr_data d;
 
 4399        err = get_path(f, ino, &path);
 
 4401                reply_err(req, err);
 
 4405        fuse_prepare_interrupt(f, req, &d);
 
 4406        res = fuse_fs_lseek(f->fs, path, off, whence, fi);
 
 4407        fuse_finish_interrupt(f, req, &d);
 
 4408        free_path(f, ino, path);
 
 4412                reply_err(req, res);
 
 4415static int clean_delay(
struct fuse *f)
 
 4423        int max_sleep = 3600;
 
 4424        int sleep_time = f->conf.remember / 10;
 
 4426        if (sleep_time > max_sleep)
 
 4428        if (sleep_time < min_sleep)
 
 4435        struct node_lru *lnode;
 
 4436        struct list_head *curr, *next;
 
 4438        struct timespec now;
 
 4440        pthread_mutex_lock(&f->lock);
 
 4444        for (curr = f->lru_table.next; curr != &f->lru_table; curr = next) {
 
 4448                lnode = list_entry(curr, 
struct node_lru, lru);
 
 4449                node = &lnode->node;
 
 4451                age = diff_timespec(&now, &lnode->forget_time);
 
 4452                if (age <= f->conf.remember)
 
 4455                assert(node->nlookup == 1);
 
 4458                if (node->refctr > 1)
 
 4462                unhash_name(f, node);
 
 4463                unref_node(f, node);
 
 4465        pthread_mutex_unlock(&f->lock);
 
 4467        return clean_delay(f);
 
 
 4471        .
init = fuse_lib_init,
 
 4472        .destroy = fuse_lib_destroy,
 
 4473        .lookup = fuse_lib_lookup,
 
 4474        .forget = fuse_lib_forget,
 
 4475        .forget_multi = fuse_lib_forget_multi,
 
 4476        .getattr = fuse_lib_getattr,
 
 4477        .setattr = fuse_lib_setattr,
 
 4478        .access = fuse_lib_access,
 
 4479        .readlink = fuse_lib_readlink,
 
 4480        .mknod = fuse_lib_mknod,
 
 4481        .mkdir = fuse_lib_mkdir,
 
 4482        .unlink = fuse_lib_unlink,
 
 4483        .rmdir = fuse_lib_rmdir,
 
 4484        .symlink = fuse_lib_symlink,
 
 4485        .rename = fuse_lib_rename,
 
 4486        .link = fuse_lib_link,
 
 4487        .create = fuse_lib_create,
 
 4488        .open = fuse_lib_open,
 
 4489        .read = fuse_lib_read,
 
 4490        .write_buf = fuse_lib_write_buf,
 
 4491        .flush = fuse_lib_flush,
 
 4492        .release = fuse_lib_release,
 
 4493        .fsync = fuse_lib_fsync,
 
 4494        .opendir = fuse_lib_opendir,
 
 4495        .readdir = fuse_lib_readdir,
 
 4496        .readdirplus = fuse_lib_readdirplus,
 
 4497        .releasedir = fuse_lib_releasedir,
 
 4498        .fsyncdir = fuse_lib_fsyncdir,
 
 4499        .statfs = fuse_lib_statfs,
 
 4500        .setxattr = fuse_lib_setxattr,
 
 4501        .getxattr = fuse_lib_getxattr,
 
 4502        .listxattr = fuse_lib_listxattr,
 
 4503        .removexattr = fuse_lib_removexattr,
 
 4504        .getlk = fuse_lib_getlk,
 
 4505        .setlk = fuse_lib_setlk,
 
 4506        .flock = fuse_lib_flock,
 
 4507        .bmap = fuse_lib_bmap,
 
 4508        .ioctl = fuse_lib_ioctl,
 
 4509        .poll = fuse_lib_poll,
 
 4510        .fallocate = fuse_lib_fallocate,
 
 4511        .copy_file_range = fuse_lib_copy_file_range,
 
 4512        .lseek = fuse_lib_lseek,
 
 4515int fuse_notify_poll(
struct fuse_pollhandle *ph)
 
 4525static int fuse_session_loop_remember(
struct fuse *f)
 
 4527        struct fuse_session *se = f->se;
 
 4529        struct timespec now;
 
 4531        struct pollfd fds = {
 
 4540        next_clean = now.tv_sec;
 
 4545                if (now.tv_sec < next_clean)
 
 4546                        timeout = next_clean - now.tv_sec;
 
 4550                res = poll(&fds, 1, timeout * 1000);
 
 4556                } 
else if (res > 0) {
 
 4557                        res = fuse_session_receive_buf_internal(se, &fbuf,
 
 4564                        fuse_session_process_buf_internal(se, &fbuf, NULL);
 
 4568                        next_clean = now.tv_sec + timeout;
 
 4574        return res < 0 ? -1 : 0;
 
 4583                return fuse_session_loop_remember(f);
 
 
 4588FUSE_SYMVER(
"fuse_loop_mt_312", 
"fuse_loop_mt@@FUSE_3.12")
 
 4603int fuse_loop_mt_32(
struct fuse *f, 
struct fuse_loop_config_v1 *config_v1);
 
 4604FUSE_SYMVER(
"fuse_loop_mt_32", 
"fuse_loop_mt@FUSE_3.2")
 
 4605int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config_v1 *config_v1)
 
 4611        fuse_loop_cfg_convert(config, config_v1);
 
 4613        int res = fuse_loop_mt_312(f, config);
 
 4615        fuse_loop_cfg_destroy(config);
 
 4620int fuse_loop_mt_31(
struct fuse *f, 
int clone_fd);
 
 4621FUSE_SYMVER(
"fuse_loop_mt_31", 
"fuse_loop_mt@FUSE_3.0")
 
 4622int fuse_loop_mt_31(struct fuse *f, 
int clone_fd)
 
 4630        fuse_loop_cfg_set_clone_fd(config, 
clone_fd);
 
 4632        err = fuse_loop_mt_312(f, config);
 
 4634        fuse_loop_cfg_destroy(config);
 
 4646        struct fuse_context_i *c = fuse_get_context_internal();
 
 
 4656        struct fuse_context_i *c = fuse_get_context_internal();
 
 
 4665        struct fuse_context_i *c = fuse_get_context_internal();
 
 
 4675        int err = lookup_path_in_cache(f, path, &ino);
 
 
 4683#define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } 
 4685static const struct fuse_opt fuse_lib_opts[] = {
 
 4688        FUSE_LIB_OPT(
"debug",                 debug, 1),
 
 4689        FUSE_LIB_OPT(
"-d",                    debug, 1),
 
 4690        FUSE_LIB_OPT(
"kernel_cache",          kernel_cache, 1),
 
 4691        FUSE_LIB_OPT(
"auto_cache",            auto_cache, 1),
 
 4692        FUSE_LIB_OPT(
"noauto_cache",          auto_cache, 0),
 
 4693        FUSE_LIB_OPT(
"no_rofd_flush",         no_rofd_flush, 1),
 
 4694        FUSE_LIB_OPT(
"umask=",                set_mode, 1),
 
 4695        FUSE_LIB_OPT(
"umask=%o",              umask, 0),
 
 4696        FUSE_LIB_OPT(
"fmask=",                set_mode, 1),
 
 4697        FUSE_LIB_OPT(
"fmask=%o",              fmask, 0),
 
 4698        FUSE_LIB_OPT(
"dmask=",                set_mode, 1),
 
 4699        FUSE_LIB_OPT(
"dmask=%o",              dmask, 0),
 
 4700        FUSE_LIB_OPT(
"uid=",                  set_uid, 1),
 
 4701        FUSE_LIB_OPT(
"uid=%d",                uid, 0),
 
 4702        FUSE_LIB_OPT(
"gid=",                  set_gid, 1),
 
 4703        FUSE_LIB_OPT(
"gid=%d",                gid, 0),
 
 4704        FUSE_LIB_OPT(
"entry_timeout=%lf",     entry_timeout, 0),
 
 4705        FUSE_LIB_OPT(
"attr_timeout=%lf",      attr_timeout, 0),
 
 4706        FUSE_LIB_OPT(
"ac_attr_timeout=%lf",   ac_attr_timeout, 0),
 
 4707        FUSE_LIB_OPT(
"ac_attr_timeout=",      ac_attr_timeout_set, 1),
 
 4708        FUSE_LIB_OPT(
"negative_timeout=%lf",  negative_timeout, 0),
 
 4709        FUSE_LIB_OPT(
"noforget",              remember, -1),
 
 4710        FUSE_LIB_OPT(
"remember=%u",           remember, 0),
 
 4711        FUSE_LIB_OPT(
"modules=%s",            modules, 0),
 
 4712        FUSE_LIB_OPT(
"parallel_direct_write=%d", parallel_direct_writes, 0),
 
 4716static int fuse_lib_opt_proc(
void *data, 
const char *arg, 
int key,
 
 4719        (void) arg; (void) outargs; (void) data; (void) key;
 
 4726static const struct fuse_opt fuse_help_opts[] = {
 
 4727        FUSE_LIB_OPT(
"modules=%s", modules, 1),
 
 4732static void print_module_help(
const char *name,
 
 4739        printf(
"\nOptions for %s module:\n", name);
 
 4749"    -o kernel_cache        cache files in kernel\n" 
 4750"    -o [no]auto_cache      enable caching based on modification times (off)\n" 
 4751"    -o no_rofd_flush       disable flushing of read-only fd on close (off)\n" 
 4752"    -o umask=M             set file permissions (octal)\n" 
 4753"    -o fmask=M             set file permissions (octal)\n" 
 4754"    -o dmask=M             set dir  permissions (octal)\n" 
 4755"    -o uid=N               set file owner\n" 
 4756"    -o gid=N               set file group\n" 
 4757"    -o entry_timeout=T     cache timeout for names (1.0s)\n" 
 4758"    -o negative_timeout=T  cache timeout for deleted names (0.0s)\n" 
 4759"    -o attr_timeout=T      cache timeout for attributes (1.0s)\n" 
 4760"    -o ac_attr_timeout=T   auto cache timeout for attributes (attr_timeout)\n" 
 4761"    -o noforget            never forget cached inodes\n" 
 4762"    -o remember=T          remember cached inodes for T seconds (0s)\n" 
 4763"    -o modules=M1[:M2...]  names of modules to push onto filesystem stack\n");
 
 4770        print_module_help(
"subdir", &fuse_module_subdir_factory);
 
 4772        print_module_help(
"iconv", &fuse_module_iconv_factory);
 
 4779                           fuse_lib_opt_proc) == -1
 
 4788        for (module = conf.modules; 
module; 
module = next) {
 
 4790                for (p = module; *p && *p != 
':'; p++);
 
 4791                next = *p ? p + 1 : NULL;
 
 4794                m = fuse_get_module(module);
 
 4796                        print_module_help(module, &m->factory);
 
 
 4800static int fuse_init_intr_signal(
int signum, 
int *installed)
 
 4802        struct sigaction old_sa;
 
 4804        if (sigaction(signum, NULL, &old_sa) == -1) {
 
 4805                perror(
"fuse: cannot get old signal handler");
 
 4809        if (old_sa.sa_handler == SIG_DFL) {
 
 4810                struct sigaction sa;
 
 4812                memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4813                sa.sa_handler = fuse_intr_sighandler;
 
 4814                sigemptyset(&sa.sa_mask);
 
 4816                if (sigaction(signum, &sa, NULL) == -1) {
 
 4817                        perror(
"fuse: cannot set interrupt signal handler");
 
 4825static void fuse_restore_intr_signal(
int signum)
 
 4827        struct sigaction sa;
 
 4829        memset(&sa, 0, 
sizeof(
struct sigaction));
 
 4830        sa.sa_handler = SIG_DFL;
 
 4831        sigaction(signum, &sa, NULL);
 
 4835static int fuse_push_module(
struct fuse *f, 
const char *module,
 
 4838        struct fuse_fs *fs[2] = { f->fs, NULL };
 
 4839        struct fuse_fs *newfs;
 
 4845        newfs = m->factory(args, fs);
 
 4860                fuse_log(FUSE_LOG_ERR, 
"fuse: warning: library too old, some operations may not not work\n");
 
 4864        fs = (
struct fuse_fs *) calloc(1, 
sizeof(
struct fuse_fs));
 
 4866                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse_fs object\n");
 
 4870        fs->user_data = user_data;
 
 4872                memcpy(&fs->op, op, op_size);
 
 
 4876static int node_table_init(
struct node_table *t)
 
 4878        t->size = NODE_TABLE_MIN_SIZE;
 
 4879        t->array = (
struct node **) calloc(1, 
sizeof(
struct node *) * t->size);
 
 4880        if (t->array == NULL) {
 
 4881                fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 4890static void *fuse_prune_nodes(
void *fuse)
 
 4892        struct fuse *f = fuse;
 
 4895        pthread_setname_np(pthread_self(), 
"fuse_prune_nodes");
 
 4907                return fuse_start_thread(&f->prune_thread, fuse_prune_nodes, f);
 
 
 4914        if (lru_enabled(f)) {
 
 4915                pthread_mutex_lock(&f->lock);
 
 4916                pthread_cancel(f->prune_thread);
 
 4917                pthread_mutex_unlock(&f->lock);
 
 4918                pthread_join(f->prune_thread, NULL);
 
 
 4926struct fuse *_fuse_new_31(
struct fuse_args *args,
 
 4930struct fuse *_fuse_new_31(
struct fuse_args *args,
 
 4940        f = (
struct fuse *) calloc(1, 
sizeof(
struct fuse));
 
 4942                fuse_log(FUSE_LOG_ERR, 
"fuse: failed to allocate fuse object\n");
 
 4946        f->conf.entry_timeout = 1.0;
 
 4947        f->conf.attr_timeout = 1.0;
 
 4948        f->conf.negative_timeout = 0.0;
 
 4949        f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL;
 
 4953                           fuse_lib_opt_proc) == -1)
 
 4956        pthread_mutex_lock(&fuse_context_lock);
 
 4957        static int builtin_modules_registered = 0;
 
 4959        if (builtin_modules_registered == 0) {
 
 4961                fuse_register_module(
"subdir", fuse_module_subdir_factory, NULL);
 
 4963                fuse_register_module(
"iconv", fuse_module_iconv_factory, NULL);
 
 4965                builtin_modules_registered= 1;
 
 4967        pthread_mutex_unlock(&fuse_context_lock);
 
 4969        if (fuse_create_context_key() == -1)
 
 4974                goto out_delete_context_key;
 
 4984        f->pagesize = getpagesize();
 
 4985        init_list_head(&f->partial_slabs);
 
 4986        init_list_head(&f->full_slabs);
 
 4987        init_list_head(&f->lru_table);
 
 4989        if (f->conf.modules) {
 
 4993                for (module = f->conf.modules; 
module; 
module = next) {
 
 4995                        for (p = module; *p && *p != 
':'; p++);
 
 4996                        next = *p ? p + 1 : NULL;
 
 4999                            fuse_push_module(f, module, args) == -1)
 
 5004        if (!f->conf.ac_attr_timeout_set)
 
 5005                f->conf.ac_attr_timeout = f->conf.attr_timeout;
 
 5007#if defined(__FreeBSD__) || defined(__NetBSD__) 
 5012        f->conf.readdir_ino = 1;
 
 5016        struct fuse_session *fuse_session_new_versioned(
 
 5020        f->se = fuse_session_new_versioned(args, &llop, 
sizeof(llop), version,
 
 5025        if (f->conf.debug) {
 
 5026                fuse_log(FUSE_LOG_DEBUG, 
"nullpath_ok: %i\n", f->conf.nullpath_ok);
 
 5030        f->fs->debug = f->conf.debug;
 
 5033        if (node_table_init(&f->name_table) == -1)
 
 5034                goto out_free_session;
 
 5036        if (node_table_init(&f->id_table) == -1)
 
 5037                goto out_free_name_table;
 
 5039        pthread_mutex_init(&f->lock, NULL);
 
 5041        root = alloc_node(f);
 
 5043                fuse_log(FUSE_LOG_ERR, 
"fuse: memory allocation failed\n");
 
 5044                goto out_free_id_table;
 
 5046        if (lru_enabled(f)) {
 
 5047                struct node_lru *lnode = node_lru(root);
 
 5048                init_list_head(&lnode->lru);
 
 5051        strcpy(root->inline_name, 
"/");
 
 5052        root->name = root->inline_name;
 
 5053        root->parent = NULL;
 
 5054        root->nodeid = FUSE_ROOT_ID;
 
 5061        free(f->id_table.array);
 
 5063        free(f->name_table.array);
 
 5068        free(f->conf.modules);
 
 5069out_delete_context_key:
 
 5070        fuse_delete_context_key();
 
 5082FUSE_SYMVER(
"_fuse_new_30", 
"_fuse_new@FUSE_3.0")
 
 5083struct fuse *_fuse_new_30(struct 
fuse_args *args,
 
 5092                FUSE_LIB_OPT(
"-h", show_help, 1),
 
 5093                FUSE_LIB_OPT(
"--help", show_help, 1),
 
 5098                           fuse_lib_opt_proc) == -1)
 
 5105                return _fuse_new_31(args, op, op_size, version, user_data);
 
 5110                         size_t op_size, 
void *user_data);
 
 5111FUSE_SYMVER(
"fuse_new_31", 
"fuse_new@FUSE_3.1")
 
 5112struct fuse *fuse_new_31(struct 
fuse_args *args,
 
 5114                         size_t op_size, 
void *user_data)
 
 5119        return _fuse_new_31(args, op, op_size, &version, user_data);
 
 5127                         size_t op_size, 
void *user_data);
 
 5128FUSE_SYMVER(
"fuse_new_30", 
"fuse_new@FUSE_3.0")
 
 5129struct fuse *fuse_new_30(struct 
fuse_args *args,
 
 5131                         size_t op_size, 
void *user_data)
 
 5136                FUSE_LIB_OPT(
"-h", show_help, 1),
 
 5137                FUSE_LIB_OPT(
"--help", show_help, 1),
 
 5142                           fuse_lib_opt_proc) == -1)
 
 5149                return fuse_new_31(args, op, op_size, user_data);
 
 5157        if (f->conf.intr && f->intr_installed)
 
 5158                fuse_restore_intr_signal(f->conf.intr_signal);
 
 5161                fuse_create_context(f);
 
 5163                for (i = 0; i < f->id_table.size; i++) {
 
 5166                        for (node = f->id_table.array[i]; node != NULL;
 
 5167                             node = node->id_next) {
 
 5168                                if (node->is_hidden) {
 
 5170                                        if (try_get_path(f, node->nodeid, NULL, &path, NULL, 
false) == 0) {
 
 5171                                                fuse_fs_unlink(f->fs, path);
 
 5178        for (i = 0; i < f->id_table.size; i++) {
 
 5182                for (node = f->id_table.array[i]; node != NULL; node = next) {
 
 5183                        next = node->id_next;
 
 5188        assert(list_empty(&f->partial_slabs));
 
 5189        assert(list_empty(&f->full_slabs));
 
 5191        while (fuse_modules) {
 
 5192                fuse_put_module(fuse_modules);
 
 5194        free(f->id_table.array);
 
 5195        free(f->name_table.array);
 
 5196        pthread_mutex_destroy(&f->lock);
 
 5199        free(f->conf.modules);
 
 5201        fuse_delete_context_key();
 
 
 5215        return FUSE_VERSION;
 
 
 5220        return PACKAGE_VERSION;
 
 
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_fs *(* fuse_module_factory_t)(struct fuse_args *args, struct fuse_fs *fs[])
struct fuse_context * fuse_get_context(void)
int fuse_loop(struct fuse *f)
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)
void fuse_lib_help(struct fuse_args *args)
struct fuse_session * fuse_get_session(struct fuse *f)
void fuse_unmount(struct fuse *f)
struct fuse_fs * fuse_fs_new(const struct fuse_operations *op, size_t op_size, void *private_data)
void fuse_stop_cleanup_thread(struct fuse *fuse)
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
const char * fuse_pkgversion(void)
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)
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
void * fuse_req_userdata(fuse_req_t req)
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)
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)
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)
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)
struct fuse_context * fuse_get_context(void)
#define FUSE_CAP_EXPORT_SUPPORT
enum fuse_buf_flags flags
uint32_t parallel_direct_writes
void(* getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock)
void(* init)(void *userdata, struct fuse_conn_info *conn)
void(* setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock, int sleep)