Lines Matching +full:fs +full:- +full:err
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
100 struct fuse_fs *fs; member
167 return -1; in fuse_load_so_name()
171 so->handle = dlopen(soname, RTLD_NOW); in fuse_load_so_name()
173 if (!so->handle) { in fuse_load_so_name()
175 goto err; in fuse_load_so_name()
177 if (!so->ctr) { in fuse_load_so_name()
179 goto err; in fuse_load_so_name()
183 err: in fuse_load_so_name()
184 if (so->handle) in fuse_load_so_name()
185 dlclose(so->handle); in fuse_load_so_name()
187 return -1; in fuse_load_so_name()
196 return -1; in fuse_load_so_module()
207 for (m = fuse_modules; m; m = m->next) { in fuse_find_module()
208 if (strcmp(module, m->name) == 0) { in fuse_find_module()
209 m->ctr++; in fuse_find_module()
223 int err = fuse_load_so_module(module); in fuse_get_module() local
224 if (!err) in fuse_get_module()
234 assert(m->ctr > 0); in fuse_put_module()
235 m->ctr--; in fuse_put_module()
236 if (!m->ctr && m->so) { in fuse_put_module()
237 struct fusemod_so *so = m->so; in fuse_put_module()
238 assert(so->ctr > 0); in fuse_put_module()
239 so->ctr--; in fuse_put_module()
240 if (!so->ctr) { in fuse_put_module()
243 if ((*mp)->so == so) in fuse_put_module()
244 *mp = (*mp)->next; in fuse_put_module()
246 mp = &(*mp)->next; in fuse_put_module()
248 dlclose(so->handle); in fuse_put_module()
258 size_t hash = nodeid % f->id_table_size; in get_node_nocheck()
261 for (node = f->id_table[hash]; node != NULL; node = node->id_next) in get_node_nocheck()
262 if (node->nodeid == nodeid) in get_node_nocheck()
281 free(node->name); in free_node()
287 size_t hash = node->nodeid % f->id_table_size; in unhash_id()
288 struct node **nodep = &f->id_table[hash]; in unhash_id()
290 for (; *nodep != NULL; nodep = &(*nodep)->id_next) in unhash_id()
292 *nodep = node->id_next; in unhash_id()
299 size_t hash = node->nodeid % f->id_table_size; in hash_id()
300 node->id_next = f->id_table[hash]; in hash_id()
301 f->id_table[hash] = node; in hash_id()
311 hash = (hash << 5) - hash + *name; in name_hash()
313 return (hash + parent) % f->name_table_size; in name_hash()
320 if (node->name) { in unhash_name()
321 size_t hash = name_hash(f, node->parent->nodeid, node->name); in unhash_name()
322 struct node **nodep = &f->name_table[hash]; in unhash_name()
324 for (; *nodep != NULL; nodep = &(*nodep)->name_next) in unhash_name()
326 *nodep = node->name_next; in unhash_name()
327 node->name_next = NULL; in unhash_name()
328 unref_node(f, node->parent); in unhash_name()
329 free(node->name); in unhash_name()
330 node->name = NULL; in unhash_name()
331 node->parent = NULL; in unhash_name()
335 (unsigned long long) node->nodeid); in unhash_name()
345 node->name = strdup(name); in hash_name()
346 if (node->name == NULL) in hash_name()
347 return -1; in hash_name()
349 parent->refctr ++; in hash_name()
350 node->parent = parent; in hash_name()
351 node->name_next = f->name_table[hash]; in hash_name()
352 f->name_table[hash] = node; in hash_name()
358 if (f->conf.debug) in delete_node()
359 fprintf(stderr, "delete: %llu\n", (unsigned long long) node->nodeid); in delete_node()
361 assert(!node->name); in delete_node()
368 assert(node->refctr > 0); in unref_node()
369 node->refctr --; in unref_node()
370 if (!node->refctr) in unref_node()
377 f->ctr = (f->ctr + 1) & 0xffffffff; in next_id()
378 if (!f->ctr) in next_id()
379 f->generation ++; in next_id()
380 } while (f->ctr == 0 || f->ctr == FUSE_UNKNOWN_INO || in next_id()
381 get_node_nocheck(f, f->ctr) != NULL); in next_id()
382 return f->ctr; in next_id()
391 for (node = f->name_table[hash]; node != NULL; node = node->name_next) in lookup_node()
392 if (node->parent->nodeid == parent && strcmp(node->name, name) == 0) in lookup_node()
403 pthread_mutex_lock(&f->lock); in find_node()
410 node->refctr = 1; in find_node()
411 node->nodeid = next_id(f); in find_node()
412 node->open_count = 0; in find_node()
413 node->is_hidden = 0; in find_node()
414 node->generation = f->generation; in find_node()
415 if (hash_name(f, node, parent, name) == -1) { in find_node()
422 node->nlookup ++; in find_node()
424 pthread_mutex_unlock(&f->lock); in find_node()
437 if (s - len <= *buf) { in add_name()
438 unsigned pathlen = *bufsize - (s - *buf); in add_name()
454 s = newbuf + newbufsize - pathlen; in add_name()
455 memmove(s, newbuf + *bufsize - pathlen, pathlen); in add_name()
458 s -= len; in add_name()
460 s -= len; in add_name()
467 s--; in add_name()
477 char *s = buf + FUSE_MAX_PATH - 1; in get_path_name()
488 pthread_mutex_lock(&f->lock); in get_path_name()
489 for (node = get_node(f, nodeid); node && node->nodeid != FUSE_ROOT_ID; in get_path_name()
490 node = node->parent) { in get_path_name()
491 if (node->name == NULL) { in get_path_name()
496 s = add_name(buf, s, node->name); in get_path_name()
500 pthread_mutex_unlock(&f->lock); in get_path_name()
520 s = buf + bufsize - 1; in get_path_name()
529 pthread_mutex_lock(&f->lock); in get_path_name()
530 for (node = get_node(f, nodeid); node && node->nodeid != FUSE_ROOT_ID; in get_path_name()
531 node = node->parent) { in get_path_name()
532 if (node->name == NULL) { in get_path_name()
537 s = add_name(&buf, &bufsize, s, node->name); in get_path_name()
541 pthread_mutex_unlock(&f->lock); in get_path_name()
547 memmove(buf, s, bufsize - (s - buf)); in get_path_name()
568 pthread_mutex_lock(&f->lock); in forget_node()
570 assert(node->nlookup >= nlookup); in forget_node()
571 node->nlookup -= nlookup; in forget_node()
572 if (!node->nlookup) { in forget_node()
576 pthread_mutex_unlock(&f->lock); in forget_node()
583 pthread_mutex_lock(&f->lock); in remove_node()
587 pthread_mutex_unlock(&f->lock); in remove_node()
595 int err = 0; in rename_node() local
597 pthread_mutex_lock(&f->lock); in rename_node()
606 err = -EBUSY; in rename_node()
613 if (hash_name(f, node, newdir, newname) == -1) { in rename_node()
614 err = -ENOMEM; in rename_node()
619 node->is_hidden = 1; in rename_node()
622 pthread_mutex_unlock(&f->lock); in rename_node()
623 return err; in rename_node()
628 if (!f->conf.use_ino) in set_stat()
629 stbuf->st_ino = nodeid; in set_stat()
630 if (f->conf.set_mode) in set_stat()
631 stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f->conf.umask); in set_stat()
632 if (f->conf.set_uid) in set_stat()
633 stbuf->st_uid = f->conf.uid; in set_stat()
634 if (f->conf.set_gid) in set_stat()
635 stbuf->st_gid = f->conf.gid; in set_stat()
660 if (d->id == pthread_self()) in fuse_interrupt()
663 pthread_mutex_lock(&f->lock); in fuse_interrupt()
664 while (!d->finished) { in fuse_interrupt()
668 pthread_kill(d->id, f->conf.intr_signal); in fuse_interrupt()
672 pthread_cond_timedwait(&d->cond, &f->lock, &timeout); in fuse_interrupt()
674 pthread_mutex_unlock(&f->lock); in fuse_interrupt()
680 pthread_mutex_lock(&f->lock); in fuse_do_finish_interrupt()
681 d->finished = 1; in fuse_do_finish_interrupt()
682 pthread_cond_broadcast(&d->cond); in fuse_do_finish_interrupt()
683 pthread_mutex_unlock(&f->lock); in fuse_do_finish_interrupt()
685 pthread_cond_destroy(&d->cond); in fuse_do_finish_interrupt()
690 d->id = pthread_self(); in fuse_do_prepare_interrupt()
691 pthread_cond_init(&d->cond, NULL); in fuse_do_prepare_interrupt()
692 d->finished = 0; in fuse_do_prepare_interrupt()
699 if (f->conf.intr) in fuse_finish_interrupt()
706 if (f->conf.intr) in fuse_prepare_interrupt()
710 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf) in fuse_fs_getattr() argument
712 fuse_get_context()->private_data = fs->user_data; in fuse_fs_getattr()
713 if (fs->op.getattr) in fuse_fs_getattr()
714 return fs->op.getattr(path, buf); in fuse_fs_getattr()
716 return -ENOSYS; in fuse_fs_getattr()
719 int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf, in fuse_fs_fgetattr() argument
722 fuse_get_context()->private_data = fs->user_data; in fuse_fs_fgetattr()
723 if (fs->op.fgetattr) in fuse_fs_fgetattr()
724 return fs->op.fgetattr(path, buf, fi); in fuse_fs_fgetattr()
725 else if (fs->op.getattr) in fuse_fs_fgetattr()
726 return fs->op.getattr(path, buf); in fuse_fs_fgetattr()
728 return -ENOSYS; in fuse_fs_fgetattr()
731 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, in fuse_fs_rename() argument
734 fuse_get_context()->private_data = fs->user_data; in fuse_fs_rename()
735 if (fs->op.rename) in fuse_fs_rename()
736 return fs->op.rename(oldpath, newpath); in fuse_fs_rename()
738 return -ENOSYS; in fuse_fs_rename()
741 int fuse_fs_unlink(struct fuse_fs *fs, const char *path) in fuse_fs_unlink() argument
743 fuse_get_context()->private_data = fs->user_data; in fuse_fs_unlink()
744 if (fs->op.unlink) in fuse_fs_unlink()
745 return fs->op.unlink(path); in fuse_fs_unlink()
747 return -ENOSYS; in fuse_fs_unlink()
750 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path) in fuse_fs_rmdir() argument
752 fuse_get_context()->private_data = fs->user_data; in fuse_fs_rmdir()
753 if (fs->op.rmdir) in fuse_fs_rmdir()
754 return fs->op.rmdir(path); in fuse_fs_rmdir()
756 return -ENOSYS; in fuse_fs_rmdir()
759 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, const char *path) in fuse_fs_symlink() argument
761 fuse_get_context()->private_data = fs->user_data; in fuse_fs_symlink()
762 if (fs->op.symlink) in fuse_fs_symlink()
763 return fs->op.symlink(linkname, path); in fuse_fs_symlink()
765 return -ENOSYS; in fuse_fs_symlink()
768 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath) in fuse_fs_link() argument
770 fuse_get_context()->private_data = fs->user_data; in fuse_fs_link()
771 if (fs->op.link) in fuse_fs_link()
772 return fs->op.link(oldpath, newpath); in fuse_fs_link()
774 return -ENOSYS; in fuse_fs_link()
777 int fuse_fs_release(struct fuse_fs *fs, const char *path, in fuse_fs_release() argument
780 fuse_get_context()->private_data = fs->user_data; in fuse_fs_release()
781 if (fs->op.release) in fuse_fs_release()
782 return fs->op.release(path, fi); in fuse_fs_release()
787 int fuse_fs_opendir(struct fuse_fs *fs, const char *path, in fuse_fs_opendir() argument
790 fuse_get_context()->private_data = fs->user_data; in fuse_fs_opendir()
791 if (fs->op.opendir) in fuse_fs_opendir()
792 return fs->op.opendir(path, fi); in fuse_fs_opendir()
797 int fuse_fs_open(struct fuse_fs *fs, const char *path, in fuse_fs_open() argument
800 fuse_get_context()->private_data = fs->user_data; in fuse_fs_open()
801 if (fs->op.open) in fuse_fs_open()
802 return fs->op.open(path, fi); in fuse_fs_open()
807 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size, in fuse_fs_read() argument
810 fuse_get_context()->private_data = fs->user_data; in fuse_fs_read()
811 if (fs->op.read) in fuse_fs_read()
812 return fs->op.read(path, buf, size, off, fi); in fuse_fs_read()
814 return -ENOSYS; in fuse_fs_read()
817 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf, in fuse_fs_write() argument
820 fuse_get_context()->private_data = fs->user_data; in fuse_fs_write()
821 if (fs->op.write) in fuse_fs_write()
822 return fs->op.write(path, buf, size, off, fi); in fuse_fs_write()
824 return -ENOSYS; in fuse_fs_write()
827 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync, in fuse_fs_fsync() argument
830 fuse_get_context()->private_data = fs->user_data; in fuse_fs_fsync()
831 if (fs->op.fsync) in fuse_fs_fsync()
832 return fs->op.fsync(path, datasync, fi); in fuse_fs_fsync()
834 return -ENOSYS; in fuse_fs_fsync()
837 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync, in fuse_fs_fsyncdir() argument
840 fuse_get_context()->private_data = fs->user_data; in fuse_fs_fsyncdir()
841 if (fs->op.fsyncdir) in fuse_fs_fsyncdir()
842 return fs->op.fsyncdir(path, datasync, fi); in fuse_fs_fsyncdir()
844 return -ENOSYS; in fuse_fs_fsyncdir()
847 int fuse_fs_flush(struct fuse_fs *fs, const char *path, in fuse_fs_flush() argument
850 fuse_get_context()->private_data = fs->user_data; in fuse_fs_flush()
851 if (fs->op.flush) in fuse_fs_flush()
852 return fs->op.flush(path, fi); in fuse_fs_flush()
854 return -ENOSYS; in fuse_fs_flush()
857 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf) in fuse_fs_statfs() argument
859 fuse_get_context()->private_data = fs->user_data; in fuse_fs_statfs()
860 if (fs->op.statfs) in fuse_fs_statfs()
861 return fs->op.statfs(path, buf); in fuse_fs_statfs()
863 buf->f_namemax = 255; in fuse_fs_statfs()
864 buf->f_bsize = 512; in fuse_fs_statfs()
869 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path, in fuse_fs_releasedir() argument
872 fuse_get_context()->private_data = fs->user_data; in fuse_fs_releasedir()
873 if (fs->op.releasedir) in fuse_fs_releasedir()
874 return fs->op.releasedir(path, fi); in fuse_fs_releasedir()
879 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf, in fuse_fs_readdir() argument
883 fuse_get_context()->private_data = fs->user_data; in fuse_fs_readdir()
884 if (fs->op.readdir) in fuse_fs_readdir()
885 return fs->op.readdir(path, buf, filler, off, fi); in fuse_fs_readdir()
887 return -ENOSYS; in fuse_fs_readdir()
890 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, in fuse_fs_create() argument
893 fuse_get_context()->private_data = fs->user_data; in fuse_fs_create()
894 if (fs->op.create) in fuse_fs_create()
895 return fs->op.create(path, mode, fi); in fuse_fs_create()
897 return -ENOSYS; in fuse_fs_create()
900 int fuse_fs_lock(struct fuse_fs *fs, const char *path, in fuse_fs_lock() argument
903 fuse_get_context()->private_data = fs->user_data; in fuse_fs_lock()
904 if (fs->op.lock) in fuse_fs_lock()
905 return fs->op.lock(path, fi, cmd, lock); in fuse_fs_lock()
907 return -ENOSYS; in fuse_fs_lock()
910 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid) in fuse_fs_chown() argument
912 fuse_get_context()->private_data = fs->user_data; in fuse_fs_chown()
913 if (fs->op.chown) in fuse_fs_chown()
914 return fs->op.chown(path, uid, gid); in fuse_fs_chown()
916 return -ENOSYS; in fuse_fs_chown()
919 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size) in fuse_fs_truncate() argument
921 fuse_get_context()->private_data = fs->user_data; in fuse_fs_truncate()
922 if (fs->op.truncate) in fuse_fs_truncate()
923 return fs->op.truncate(path, size); in fuse_fs_truncate()
925 return -ENOSYS; in fuse_fs_truncate()
928 int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size, in fuse_fs_ftruncate() argument
931 fuse_get_context()->private_data = fs->user_data; in fuse_fs_ftruncate()
932 if (fs->op.ftruncate) in fuse_fs_ftruncate()
933 return fs->op.ftruncate(path, size, fi); in fuse_fs_ftruncate()
934 else if (fs->op.truncate) in fuse_fs_ftruncate()
935 return fs->op.truncate(path, size); in fuse_fs_ftruncate()
937 return -ENOSYS; in fuse_fs_ftruncate()
940 int fuse_fs_utimens(struct fuse_fs *fs, const char *path, in fuse_fs_utimens() argument
943 fuse_get_context()->private_data = fs->user_data; in fuse_fs_utimens()
944 if (fs->op.utimens) in fuse_fs_utimens()
945 return fs->op.utimens(path, tv); in fuse_fs_utimens()
946 else if(fs->op.utime) { in fuse_fs_utimens()
950 return fs->op.utime(path, &buf); in fuse_fs_utimens()
952 return -ENOSYS; in fuse_fs_utimens()
955 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask) in fuse_fs_access() argument
957 fuse_get_context()->private_data = fs->user_data; in fuse_fs_access()
958 if (fs->op.access) in fuse_fs_access()
959 return fs->op.access(path, mask); in fuse_fs_access()
961 return -ENOSYS; in fuse_fs_access()
964 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf, in fuse_fs_readlink() argument
967 fuse_get_context()->private_data = fs->user_data; in fuse_fs_readlink()
968 if (fs->op.readlink) in fuse_fs_readlink()
969 return fs->op.readlink(path, buf, len); in fuse_fs_readlink()
971 return -ENOSYS; in fuse_fs_readlink()
974 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode, in fuse_fs_mknod() argument
977 fuse_get_context()->private_data = fs->user_data; in fuse_fs_mknod()
978 if (fs->op.mknod) in fuse_fs_mknod()
979 return fs->op.mknod(path, mode, rdev); in fuse_fs_mknod()
981 return -ENOSYS; in fuse_fs_mknod()
984 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode) in fuse_fs_mkdir() argument
986 fuse_get_context()->private_data = fs->user_data; in fuse_fs_mkdir()
987 if (fs->op.mkdir) in fuse_fs_mkdir()
988 return fs->op.mkdir(path, mode); in fuse_fs_mkdir()
990 return -ENOSYS; in fuse_fs_mkdir()
993 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name, in fuse_fs_setxattr() argument
996 fuse_get_context()->private_data = fs->user_data; in fuse_fs_setxattr()
997 if (fs->op.setxattr) in fuse_fs_setxattr()
998 return fs->op.setxattr(path, name, value, size, flags); in fuse_fs_setxattr()
1000 return -ENOSYS; in fuse_fs_setxattr()
1003 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name, in fuse_fs_getxattr() argument
1006 fuse_get_context()->private_data = fs->user_data; in fuse_fs_getxattr()
1007 if (fs->op.getxattr) in fuse_fs_getxattr()
1008 return fs->op.getxattr(path, name, value, size); in fuse_fs_getxattr()
1010 return -ENOSYS; in fuse_fs_getxattr()
1013 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list, in fuse_fs_listxattr() argument
1016 fuse_get_context()->private_data = fs->user_data; in fuse_fs_listxattr()
1017 if (fs->op.listxattr) in fuse_fs_listxattr()
1018 return fs->op.listxattr(path, list, size); in fuse_fs_listxattr()
1020 return -ENOSYS; in fuse_fs_listxattr()
1023 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, in fuse_fs_bmap() argument
1026 fuse_get_context()->private_data = fs->user_data; in fuse_fs_bmap()
1027 if (fs->op.bmap) in fuse_fs_bmap()
1028 return fs->op.bmap(path, blocksize, idx); in fuse_fs_bmap()
1030 return -ENOSYS; in fuse_fs_bmap()
1033 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, const char *name) in fuse_fs_removexattr() argument
1035 fuse_get_context()->private_data = fs->user_data; in fuse_fs_removexattr()
1036 if (fs->op.removexattr) in fuse_fs_removexattr()
1037 return fs->op.removexattr(path, name); in fuse_fs_removexattr()
1039 return -ENOSYS; in fuse_fs_removexattr()
1042 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg, in fuse_fs_ioctl() argument
1045 fuse_get_context()->private_data = fs->user_data; in fuse_fs_ioctl()
1046 if (fs->op.ioctl) { in fuse_fs_ioctl()
1048 if (fs->debug) in fuse_fs_ioctl()
1050 (unsigned long long) fi->fh, cmd, flags); in fuse_fs_ioctl()
1052 return fs->op.ioctl(path, cmd, arg, fi, flags, data); in fuse_fs_ioctl()
1054 return -ENOSYS; in fuse_fs_ioctl()
1061 pthread_mutex_lock(&f->lock); in is_open()
1063 if (node && node->open_count > 0) in is_open()
1065 pthread_mutex_unlock(&f->lock); in is_open()
1080 pthread_mutex_lock(&f->lock); in hidden_name()
1083 pthread_mutex_unlock(&f->lock); in hidden_name()
1087 f->hidectr ++; in hidden_name()
1089 (unsigned int) node->nodeid, f->hidectr); in hidden_name()
1092 pthread_mutex_unlock(&f->lock); in hidden_name()
1098 res = fuse_fs_getattr(f->fs, newpath, &buf); in hidden_name()
1099 if (res == -ENOENT) in hidden_name()
1103 } while(res == 0 && --failctr); in hidden_name()
1113 int err = -EBUSY; in hide_node() local
1117 err = fuse_fs_rename(f->fs, oldpath, newpath); in hide_node()
1118 if (!err) in hide_node()
1119 err = rename_node(f, dir, oldname, dir, newname, 1); in hide_node()
1122 return err; in hide_node()
1129 return stbuf->st_mtime == ts->tv_sec && ST_MTIM_NSEC(stbuf) == ts->tv_nsec; in mtime_eq()
1140 if (res == -1 && errno == EINVAL) { in curr_time()
1144 if (res == -1) { in curr_time()
1152 if (node->cache_valid && (!mtime_eq(stbuf, &node->mtime) || in update_stat()
1153 stbuf->st_size != node->size)) in update_stat()
1154 node->cache_valid = 0; in update_stat()
1155 node->mtime.tv_sec = stbuf->st_mtime; in update_stat()
1156 node->mtime.tv_nsec = ST_MTIM_NSEC(stbuf); in update_stat()
1157 node->size = stbuf->st_size; in update_stat()
1158 curr_time(&node->stat_updated); in update_stat()
1171 res = fuse_fs_fgetattr(f->fs, path, &e->attr, fi); in lookup_path()
1173 res = fuse_fs_getattr(f->fs, path, &e->attr); in lookup_path()
1179 res = -ENOMEM; in lookup_path()
1181 e->ino = node->nodeid; in lookup_path()
1182 e->generation = node->generation; in lookup_path()
1183 e->entry_timeout = f->conf.entry_timeout; in lookup_path()
1184 e->attr_timeout = f->conf.attr_timeout; in lookup_path()
1186 if (f->conf.auto_cache) { in lookup_path()
1187 pthread_mutex_lock(&f->lock); in lookup_path()
1188 update_stat(node, &e->attr); in lookup_path()
1189 pthread_mutex_unlock(&f->lock); in lookup_path()
1192 set_stat(f, e->ino, &e->attr); in lookup_path()
1193 if (f->conf.debug) in lookup_path()
1194 fprintf(stderr, " NODEID: %lu\n", (unsigned long) e->ino); in lookup_path()
1226 int err = 0; in fuse_create_context_key() local
1229 err = pthread_key_create(&fuse_context_key, fuse_freecontext); in fuse_create_context_key()
1230 if (err) { in fuse_create_context_key()
1232 strerror(err)); in fuse_create_context_key()
1234 return -1; in fuse_create_context_key()
1245 fuse_context_ref--; in fuse_delete_context_key()
1257 c->req = req; in req_fuse_prepare()
1258 c->ctx.fuse = req_fuse(req); in req_fuse_prepare()
1259 c->ctx.uid = ctx->uid; in req_fuse_prepare()
1260 c->ctx.gid = ctx->gid; in req_fuse_prepare()
1261 c->ctx.pid = ctx->pid; in req_fuse_prepare()
1263 c->ctx.umask = ctx->umask; in req_fuse_prepare()
1265 return c->ctx.fuse; in req_fuse_prepare()
1269 static void reply_err(fuse_req_t req, int err) in reply_err() argument
1271 static inline void reply_err(fuse_req_t req, int err) in reply_err()
1274 /* fuse_reply_err() uses non-negated errno values */ in reply_err()
1275 fuse_reply_err(req, -err); in reply_err()
1279 int err) in reply_entry() argument
1281 if (!err) { in reply_entry()
1285 if ((fuse_reply_entry(req, e) == -ENOENT) in reply_entry()
1286 && (e->ino != 0)) in reply_entry()
1287 forget_node(f, e->ino, 1); in reply_entry()
1289 if (fuse_reply_entry(req, e) == -ENOENT) in reply_entry()
1290 forget_node(f, e->ino, 1); in reply_entry()
1293 reply_err(req, err); in reply_entry()
1296 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn) in fuse_fs_init() argument
1298 fuse_get_context()->private_data = fs->user_data; in fuse_fs_init()
1299 if (fs->op.init) in fuse_fs_init()
1300 fs->user_data = fs->op.init(conn); in fuse_fs_init()
1309 c->ctx.fuse = f; in fuse_lib_init()
1310 fuse_fs_init(f->fs, conn); in fuse_lib_init()
1313 void fuse_fs_destroy(struct fuse_fs *fs) in fuse_fs_destroy() argument
1315 fuse_get_context()->private_data = fs->user_data; in fuse_fs_destroy()
1316 if (fs->op.destroy) in fuse_fs_destroy()
1317 fs->op.destroy(fs->user_data); in fuse_fs_destroy()
1319 if (fs->m) in fuse_fs_destroy()
1320 fuse_put_module(fs->m); in fuse_fs_destroy()
1322 free(fs); in fuse_fs_destroy()
1331 c->ctx.fuse = f; in fuse_lib_destroy()
1332 fuse_fs_destroy(f->fs); in fuse_lib_destroy()
1333 f->fs = NULL; in fuse_lib_destroy()
1342 int err; in fuse_lib_lookup() local
1344 err = -ENOENT; in fuse_lib_lookup()
1345 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_lookup()
1349 if (f->conf.debug) in fuse_lib_lookup()
1352 err = lookup_path(f, parent, name, path, &e, NULL); in fuse_lib_lookup()
1353 if (err == -ENOENT && f->conf.negative_timeout != 0.0) { in fuse_lib_lookup()
1355 e.entry_timeout = f->conf.negative_timeout; in fuse_lib_lookup()
1356 err = 0; in fuse_lib_lookup()
1361 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_lookup()
1362 reply_entry(req, &e, err); in fuse_lib_lookup()
1369 if (f->conf.debug) in fuse_lib_forget()
1381 int err; in fuse_lib_getattr() local
1386 err = -ENOENT; in fuse_lib_getattr()
1387 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_getattr()
1392 err = fuse_fs_getattr(f->fs, path, &buf); in fuse_lib_getattr()
1396 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_getattr()
1397 if (!err) { in fuse_lib_getattr()
1399 if (f->conf.auto_cache) { in fuse_lib_getattr()
1400 pthread_mutex_lock(&f->lock); in fuse_lib_getattr()
1402 pthread_mutex_unlock(&f->lock); in fuse_lib_getattr()
1406 fuse_reply_attr(req, &buf, f->conf.attr_timeout); in fuse_lib_getattr()
1408 reply_err(req, err); in fuse_lib_getattr()
1411 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode) in fuse_fs_chmod() argument
1413 fuse_get_context()->private_data = fs->user_data; in fuse_fs_chmod()
1414 if (fs->op.chmod) in fuse_fs_chmod()
1415 return fs->op.chmod(path, mode); in fuse_fs_chmod()
1417 return -ENOSYS; in fuse_fs_chmod()
1426 int err; in fuse_lib_setattr() local
1428 err = -ENOENT; in fuse_lib_setattr()
1429 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_setattr()
1434 err = 0; in fuse_lib_setattr()
1435 if (!err && (valid & FUSE_SET_ATTR_MODE)) in fuse_lib_setattr()
1436 err = fuse_fs_chmod(f->fs, path, attr->st_mode); in fuse_lib_setattr()
1437 if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) { in fuse_lib_setattr()
1439 (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : (uid_t) -1; in fuse_lib_setattr()
1441 (valid & FUSE_SET_ATTR_GID) ? attr->st_gid : (gid_t) -1; in fuse_lib_setattr()
1442 err = fuse_fs_chown(f->fs, path, uid, gid); in fuse_lib_setattr()
1444 if (!err && (valid & FUSE_SET_ATTR_SIZE)) { in fuse_lib_setattr()
1446 err = fuse_fs_ftruncate(f->fs, path, attr->st_size, fi); in fuse_lib_setattr()
1448 err = fuse_fs_truncate(f->fs, path, attr->st_size); in fuse_lib_setattr()
1451 if (!err && in fuse_lib_setattr()
1463 tv[0] = attr->st_atim; in fuse_lib_setattr()
1468 tv[1] = attr->st_mtim; in fuse_lib_setattr()
1470 err = fuse_fs_utimens(f->fs, path, tv); in fuse_lib_setattr()
1473 if (!err && (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) == in fuse_lib_setattr()
1476 tv[0].tv_sec = attr->st_atime; in fuse_lib_setattr()
1478 tv[1].tv_sec = attr->st_mtime; in fuse_lib_setattr()
1480 err = fuse_fs_utimens(f->fs, path, tv); in fuse_lib_setattr()
1482 if (!err) in fuse_lib_setattr()
1483 err = fuse_fs_getattr(f->fs, path, &buf); in fuse_lib_setattr()
1487 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_setattr()
1488 if (!err) { in fuse_lib_setattr()
1490 if (f->conf.auto_cache) { in fuse_lib_setattr()
1491 pthread_mutex_lock(&f->lock); in fuse_lib_setattr()
1493 pthread_mutex_unlock(&f->lock); in fuse_lib_setattr()
1497 fuse_reply_attr(req, &buf, f->conf.attr_timeout); in fuse_lib_setattr()
1499 reply_err(req, err); in fuse_lib_setattr()
1506 int err; in fuse_lib_access() local
1508 err = -ENOENT; in fuse_lib_access()
1509 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_access()
1513 if (f->conf.debug) in fuse_lib_access()
1516 err = fuse_fs_access(f->fs, path, mask); in fuse_lib_access()
1520 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_access()
1521 reply_err(req, err); in fuse_lib_access()
1529 int err; in fuse_lib_readlink() local
1531 err = -ENOENT; in fuse_lib_readlink()
1532 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_readlink()
1537 err = fuse_fs_readlink(f->fs, path, linkname, sizeof(linkname)); in fuse_lib_readlink()
1541 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_readlink()
1542 if (!err) { in fuse_lib_readlink()
1546 reply_err(req, err); in fuse_lib_readlink()
1555 int err; in fuse_lib_mknod() local
1557 err = -ENOENT; in fuse_lib_mknod()
1558 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_mknod()
1562 if (f->conf.debug) in fuse_lib_mknod()
1565 err = -ENOSYS; in fuse_lib_mknod()
1571 err = fuse_fs_create(f->fs, path, mode, &fi); in fuse_lib_mknod()
1572 if (!err) { in fuse_lib_mknod()
1573 err = lookup_path(f, parent, name, path, &e, &fi); in fuse_lib_mknod()
1574 fuse_fs_release(f->fs, path, &fi); in fuse_lib_mknod()
1577 if (err == -ENOSYS) { in fuse_lib_mknod()
1578 err = fuse_fs_mknod(f->fs, path, mode, rdev); in fuse_lib_mknod()
1579 if (!err) in fuse_lib_mknod()
1580 err = lookup_path(f, parent, name, path, &e, NULL); in fuse_lib_mknod()
1585 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_mknod()
1586 reply_entry(req, &e, err); in fuse_lib_mknod()
1595 int err; in fuse_lib_mkdir() local
1597 err = -ENOENT; in fuse_lib_mkdir()
1598 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_mkdir()
1602 if (f->conf.debug) in fuse_lib_mkdir()
1605 err = fuse_fs_mkdir(f->fs, path, mode); in fuse_lib_mkdir()
1606 if (!err) in fuse_lib_mkdir()
1607 err = lookup_path(f, parent, name, path, &e, NULL); in fuse_lib_mkdir()
1611 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_mkdir()
1612 reply_entry(req, &e, err); in fuse_lib_mkdir()
1620 int err; in fuse_lib_unlink() local
1622 err = -ENOENT; in fuse_lib_unlink()
1623 pthread_rwlock_wrlock(&f->tree_lock); in fuse_lib_unlink()
1627 if (f->conf.debug) in fuse_lib_unlink()
1630 if (!f->conf.hard_remove && is_open(f, parent, name)) in fuse_lib_unlink()
1631 err = hide_node(f, path, parent, name); in fuse_lib_unlink()
1633 err = fuse_fs_unlink(f->fs, path); in fuse_lib_unlink()
1634 if (!err) in fuse_lib_unlink()
1640 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_unlink()
1641 reply_err(req, err); in fuse_lib_unlink()
1648 int err; in fuse_lib_rmdir() local
1650 err = -ENOENT; in fuse_lib_rmdir()
1651 pthread_rwlock_wrlock(&f->tree_lock); in fuse_lib_rmdir()
1655 if (f->conf.debug) in fuse_lib_rmdir()
1658 err = fuse_fs_rmdir(f->fs, path); in fuse_lib_rmdir()
1660 if (!err) in fuse_lib_rmdir()
1664 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_rmdir()
1665 reply_err(req, err); in fuse_lib_rmdir()
1674 int err; in fuse_lib_symlink() local
1676 err = -ENOENT; in fuse_lib_symlink()
1677 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_symlink()
1681 if (f->conf.debug) in fuse_lib_symlink()
1684 err = fuse_fs_symlink(f->fs, linkname, path); in fuse_lib_symlink()
1685 if (!err) in fuse_lib_symlink()
1686 err = lookup_path(f, parent, name, path, &e, NULL); in fuse_lib_symlink()
1690 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_symlink()
1691 reply_entry(req, &e, err); in fuse_lib_symlink()
1701 int err; in fuse_lib_rename() local
1703 err = -ENOENT; in fuse_lib_rename()
1704 pthread_rwlock_wrlock(&f->tree_lock); in fuse_lib_rename()
1710 if (f->conf.debug) in fuse_lib_rename()
1711 fprintf(stderr, "RENAME %s -> %s\n", oldpath, newpath); in fuse_lib_rename()
1712 err = 0; in fuse_lib_rename()
1714 if (!f->conf.hard_remove && is_open(f, newdir, newname)) in fuse_lib_rename()
1715 err = hide_node(f, newpath, newdir, newname); in fuse_lib_rename()
1716 if (!err) { in fuse_lib_rename()
1717 err = fuse_fs_rename(f->fs, oldpath, newpath); in fuse_lib_rename()
1718 if (!err) in fuse_lib_rename()
1719 err = rename_node(f, olddir, oldname, newdir, newname, 0); in fuse_lib_rename()
1726 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_rename()
1727 reply_err(req, err); in fuse_lib_rename()
1737 int err; in fuse_lib_link() local
1739 err = -ENOENT; in fuse_lib_link()
1740 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_link()
1746 if (f->conf.debug) in fuse_lib_link()
1749 err = fuse_fs_link(f->fs, oldpath, newpath); in fuse_lib_link()
1750 if (!err) in fuse_lib_link()
1751 err = lookup_path(f, newparent, newname, newpath, &e, NULL); in fuse_lib_link()
1757 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_link()
1758 reply_entry(req, &e, err); in fuse_lib_link()
1767 fuse_fs_release(f->fs, path ? path : "-", fi); in fuse_do_release()
1769 pthread_mutex_lock(&f->lock); in fuse_do_release()
1771 assert(node->open_count > 0); in fuse_do_release()
1772 --node->open_count; in fuse_do_release()
1773 if (node->is_hidden && !node->open_count) { in fuse_do_release()
1775 node->is_hidden = 0; in fuse_do_release()
1777 pthread_mutex_unlock(&f->lock); in fuse_do_release()
1780 fuse_fs_unlink(f->fs, path); in fuse_do_release()
1791 int err; in fuse_lib_create() local
1793 err = -ENOENT; in fuse_lib_create()
1794 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_create()
1798 err = fuse_fs_create(f->fs, path, mode, fi); in fuse_lib_create()
1799 if (!err) { in fuse_lib_create()
1800 err = lookup_path(f, parent, name, path, &e, fi); in fuse_lib_create()
1801 if (err) in fuse_lib_create()
1802 fuse_fs_release(f->fs, path, fi); in fuse_lib_create()
1804 err = -EIO; in fuse_lib_create()
1805 fuse_fs_release(f->fs, path, fi); in fuse_lib_create()
1808 if (f->conf.direct_io) in fuse_lib_create()
1809 fi->direct_io = 1; in fuse_lib_create()
1810 if (f->conf.kernel_cache) in fuse_lib_create()
1811 fi->keep_cache = 1; in fuse_lib_create()
1817 if (!err) { in fuse_lib_create()
1818 pthread_mutex_lock(&f->lock); in fuse_lib_create()
1819 get_node(f, e.ino)->open_count++; in fuse_lib_create()
1820 pthread_mutex_unlock(&f->lock); in fuse_lib_create()
1821 if (fuse_reply_create(req, &e, fi) == -ENOENT) { in fuse_lib_create()
1827 } else if (f->conf.debug) { in fuse_lib_create()
1829 (unsigned long long) fi->fh, fi->flags, path); in fuse_lib_create()
1832 reply_err(req, err); in fuse_lib_create()
1837 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_create()
1845 return (t1->tv_sec - t2->tv_sec) + in diff_timespec()
1846 ((double) t1->tv_nsec - (double) t2->tv_nsec) / 1000000000.0; in diff_timespec()
1854 pthread_mutex_lock(&f->lock); in open_auto_cache()
1856 if (node->cache_valid) { in open_auto_cache()
1860 if (diff_timespec(&now, &node->stat_updated) > f->conf.ac_attr_timeout) { in open_auto_cache()
1862 int err; in open_auto_cache() local
1863 pthread_mutex_unlock(&f->lock); in open_auto_cache()
1864 err = fuse_fs_fgetattr(f->fs, path, &stbuf, fi); in open_auto_cache()
1865 pthread_mutex_lock(&f->lock); in open_auto_cache()
1866 if (!err) in open_auto_cache()
1869 node->cache_valid = 0; in open_auto_cache()
1872 if (node->cache_valid) in open_auto_cache()
1873 fi->keep_cache = 1; in open_auto_cache()
1875 node->cache_valid = 1; in open_auto_cache()
1876 pthread_mutex_unlock(&f->lock); in open_auto_cache()
1887 int err = 0; in fuse_lib_open() local
1889 err = -ENOENT; in fuse_lib_open()
1890 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_open()
1894 err = fuse_fs_open(f->fs, path, fi); in fuse_lib_open()
1895 if (!err) { in fuse_lib_open()
1896 if (f->conf.direct_io) in fuse_lib_open()
1897 fi->direct_io = 1; in fuse_lib_open()
1898 if (f->conf.kernel_cache) in fuse_lib_open()
1899 fi->keep_cache = 1; in fuse_lib_open()
1902 if (f->conf.auto_cache) in fuse_lib_open()
1908 if (!err) { in fuse_lib_open()
1909 pthread_mutex_lock(&f->lock); in fuse_lib_open()
1910 get_node(f, ino)->open_count++; in fuse_lib_open()
1911 pthread_mutex_unlock(&f->lock); in fuse_lib_open()
1912 if (fuse_reply_open(req, fi) == -ENOENT) { in fuse_lib_open()
1917 } else if (f->conf.debug) { in fuse_lib_open()
1919 (unsigned long long) fi->fh, fi->flags, path); in fuse_lib_open()
1922 reply_err(req, err); in fuse_lib_open()
1926 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_open()
1939 reply_err(req, -ENOMEM); in fuse_lib_read()
1943 res = -ENOENT; in fuse_lib_read()
1944 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_read()
1948 if (f->conf.debug) in fuse_lib_read()
1950 (unsigned long long) fi->fh, (unsigned long) size, in fuse_lib_read()
1954 res = fuse_fs_read(f->fs, path, buf, size, off, fi); in fuse_lib_read()
1958 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_read()
1961 if (f->conf.debug) in fuse_lib_read()
1963 (unsigned long long)fi->fh, res); in fuse_lib_read()
1980 res = -ENOENT; in fuse_lib_write()
1981 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_write()
1985 if (f->conf.debug) in fuse_lib_write()
1987 fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, in fuse_lib_write()
1991 res = fuse_fs_write(f->fs, path, buf, size, off, fi); in fuse_lib_write()
1995 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_write()
1998 if (f->conf.debug) in fuse_lib_write()
2000 fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, in fuse_lib_write()
2014 int err; in fuse_lib_fsync() local
2016 err = -ENOENT; in fuse_lib_fsync()
2017 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_fsync()
2021 if (f->conf.debug) in fuse_lib_fsync()
2022 fprintf(stderr, "FSYNC[%llu]\n", (unsigned long long) fi->fh); in fuse_lib_fsync()
2024 err = fuse_fs_fsync(f->fs, path, datasync, fi); in fuse_lib_fsync()
2028 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_fsync()
2029 reply_err(req, err); in fuse_lib_fsync()
2035 struct fuse_dh *dh = (struct fuse_dh *) (uintptr_t) llfi->fh; in get_dirhandle()
2037 fi->fh = dh->fh; in get_dirhandle()
2038 fi->fh_old = dh->fh; in get_dirhandle()
2050 int err; in fuse_lib_opendir() local
2054 reply_err(req, -ENOMEM); in fuse_lib_opendir()
2058 dh->fuse = f; in fuse_lib_opendir()
2059 dh->contents = NULL; in fuse_lib_opendir()
2060 dh->len = 0; in fuse_lib_opendir()
2061 dh->filled = 0; in fuse_lib_opendir()
2062 dh->nodeid = ino; in fuse_lib_opendir()
2063 fuse_mutex_init(&dh->lock); in fuse_lib_opendir()
2065 llfi->fh = (uintptr_t) dh; in fuse_lib_opendir()
2068 fi.flags = llfi->flags; in fuse_lib_opendir()
2070 err = -ENOENT; in fuse_lib_opendir()
2071 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_opendir()
2075 err = fuse_fs_opendir(f->fs, path, &fi); in fuse_lib_opendir()
2077 dh->fh = fi.fh; in fuse_lib_opendir()
2079 if (!err) { in fuse_lib_opendir()
2080 if (fuse_reply_open(req, llfi) == -ENOENT) { in fuse_lib_opendir()
2083 fuse_fs_releasedir(f->fs, path, &fi); in fuse_lib_opendir()
2085 pthread_mutex_destroy(&dh->lock); in fuse_lib_opendir()
2089 reply_err(req, err); in fuse_lib_opendir()
2090 pthread_mutex_destroy(&dh->lock); in fuse_lib_opendir()
2094 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_opendir()
2099 if (minsize > dh->size) { in extend_contents()
2101 unsigned newsize = dh->size; in extend_contents()
2116 newptr = (char *) realloc(dh->contents, newsize); in extend_contents()
2118 dh->error = -ENOMEM; in extend_contents()
2119 return -1; in extend_contents()
2121 dh->contents = newptr; in extend_contents()
2122 dh->size = newsize; in extend_contents()
2141 if (!dh->fuse->conf.use_ino) { in fill_dir()
2143 if (dh->fuse->conf.readdir_ino) { in fill_dir()
2145 pthread_mutex_lock(&dh->fuse->lock); in fill_dir()
2146 node = lookup_node(dh->fuse, dh->nodeid, name); in fill_dir()
2148 stbuf.st_ino = (ino_t) node->nodeid; in fill_dir()
2149 pthread_mutex_unlock(&dh->fuse->lock); in fill_dir()
2154 if (extend_contents(dh, dh->needlen) == -1) in fill_dir()
2157 dh->filled = 0; in fill_dir()
2158 newlen = dh->len + fuse_add_direntry(dh->req, dh->contents + dh->len, in fill_dir()
2159 dh->needlen - dh->len, name, in fill_dir()
2161 if (newlen > dh->needlen) in fill_dir()
2164 newlen = dh->len + fuse_add_direntry(dh->req, NULL, 0, name, NULL, 0); in fill_dir()
2165 if (extend_contents(dh, newlen) == -1) in fill_dir()
2168 fuse_add_direntry(dh->req, dh->contents + dh->len, dh->size - dh->len, in fill_dir()
2171 dh->len = newlen; in fill_dir()
2179 int err = -ENOENT; in readdir_fill() local
2181 pthread_rwlock_rdlock(&f->tree_lock); in readdir_fill()
2186 dh->len = 0; in readdir_fill()
2187 dh->error = 0; in readdir_fill()
2188 dh->needlen = size; in readdir_fill()
2189 dh->filled = 1; in readdir_fill()
2190 dh->req = req; in readdir_fill()
2192 err = fuse_fs_readdir(f->fs, path, dh, fill_dir, off, fi); in readdir_fill()
2194 dh->req = NULL; in readdir_fill()
2195 if (!err) in readdir_fill()
2196 err = dh->error; in readdir_fill()
2197 if (err) in readdir_fill()
2198 dh->filled = 0; in readdir_fill()
2201 pthread_rwlock_unlock(&f->tree_lock); in readdir_fill()
2202 return err; in readdir_fill()
2212 pthread_mutex_lock(&dh->lock); in fuse_lib_readdir()
2216 dh->filled = 0; in fuse_lib_readdir()
2218 if (!dh->filled) { in fuse_lib_readdir()
2219 int err = readdir_fill(f, req, ino, size, off, dh, &fi); in fuse_lib_readdir() local
2220 if (err) { in fuse_lib_readdir()
2221 reply_err(req, err); in fuse_lib_readdir()
2225 if (dh->filled) { in fuse_lib_readdir()
2226 if ((off >= 0) && (off < dh->len)) { in fuse_lib_readdir()
2227 if (off + size > dh->len) in fuse_lib_readdir()
2228 size = dh->len - off; in fuse_lib_readdir()
2232 size = dh->len; in fuse_lib_readdir()
2235 fuse_reply_buf(req, dh->contents + off, size); in fuse_lib_readdir()
2237 pthread_mutex_unlock(&dh->lock); in fuse_lib_readdir()
2249 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_releasedir()
2252 fuse_fs_releasedir(f->fs, path ? path : "-", &fi); in fuse_lib_releasedir()
2256 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_releasedir()
2257 pthread_mutex_lock(&dh->lock); in fuse_lib_releasedir()
2258 pthread_mutex_unlock(&dh->lock); in fuse_lib_releasedir()
2259 pthread_mutex_destroy(&dh->lock); in fuse_lib_releasedir()
2260 free(dh->contents); in fuse_lib_releasedir()
2271 int err; in fuse_lib_fsyncdir() local
2275 err = -ENOENT; in fuse_lib_fsyncdir()
2276 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_fsyncdir()
2281 err = fuse_fs_fsyncdir(f->fs, path, datasync, &fi); in fuse_lib_fsyncdir()
2285 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_fsyncdir()
2286 reply_err(req, err); in fuse_lib_fsyncdir()
2294 int err; in fuse_lib_statfs() local
2297 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_statfs()
2299 err = -ENOMEM; in fuse_lib_statfs()
2302 err = -ENOENT; in fuse_lib_statfs()
2308 err = fuse_fs_statfs(f->fs, path, &buf); in fuse_lib_statfs()
2312 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_statfs()
2314 if (!err) in fuse_lib_statfs()
2317 reply_err(req, err); in fuse_lib_statfs()
2325 int err; in fuse_lib_setxattr() local
2327 err = -ENOENT; in fuse_lib_setxattr()
2328 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_setxattr()
2333 err = fuse_fs_setxattr(f->fs, path, name, value, size, flags); in fuse_lib_setxattr()
2337 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_setxattr()
2338 reply_err(req, err); in fuse_lib_setxattr()
2344 int err; in common_getxattr() local
2347 err = -ENOENT; in common_getxattr()
2348 pthread_rwlock_rdlock(&f->tree_lock); in common_getxattr()
2353 err = fuse_fs_getxattr(f->fs, path, name, value, size); in common_getxattr()
2357 pthread_rwlock_unlock(&f->tree_lock); in common_getxattr()
2358 return err; in common_getxattr()
2370 reply_err(req, -ENOMEM); in fuse_lib_getxattr()
2392 int err; in common_listxattr() local
2394 err = -ENOENT; in common_listxattr()
2395 pthread_rwlock_rdlock(&f->tree_lock); in common_listxattr()
2400 err = fuse_fs_listxattr(f->fs, path, list, size); in common_listxattr()
2404 pthread_rwlock_unlock(&f->tree_lock); in common_listxattr()
2405 return err; in common_listxattr()
2416 reply_err(req, -ENOMEM); in fuse_lib_listxattr()
2439 int err; in fuse_lib_removexattr() local
2441 err = -ENOENT; in fuse_lib_removexattr()
2442 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_removexattr()
2447 err = fuse_fs_removexattr(f->fs, path, name); in fuse_lib_removexattr()
2451 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_removexattr()
2452 reply_err(req, err); in fuse_lib_removexattr()
2459 for (l = node->locks; l; l = l->next) in locks_conflict()
2460 if (l->owner != lock->owner && in locks_conflict()
2461 lock->start <= l->end && l->start <= lock->end && in locks_conflict()
2462 (l->type == F_WRLCK || lock->type == F_WRLCK)) in locks_conflict()
2471 *lockp = l->next; in delete_lock()
2477 lock->next = *pos; in insert_lock()
2487 if (lock->type != F_UNLCK || lock->start != 0 || lock->end != OFFSET_MAX) { in locks_insert()
2494 return -ENOLCK; in locks_insert()
2498 for (lp = &node->locks; *lp;) { in locks_insert()
2500 if (l->owner != lock->owner) in locks_insert()
2503 if (lock->type == l->type) { in locks_insert()
2504 if (l->end < lock->start - 1) in locks_insert()
2506 if (lock->end < l->start - 1) in locks_insert()
2508 if (l->start <= lock->start && lock->end <= l->end) in locks_insert()
2510 if (l->start < lock->start) in locks_insert()
2511 lock->start = l->start; in locks_insert()
2512 if (lock->end < l->end) in locks_insert()
2513 lock->end = l->end; in locks_insert()
2516 if (l->end < lock->start) in locks_insert()
2518 if (lock->end < l->start) in locks_insert()
2520 if (lock->start <= l->start && l->end <= lock->end) in locks_insert()
2522 if (l->end <= lock->end) { in locks_insert()
2523 l->end = lock->start - 1; in locks_insert()
2526 if (lock->start <= l->start) { in locks_insert()
2527 l->start = lock->end + 1; in locks_insert()
2531 newl2->start = lock->end + 1; in locks_insert()
2532 l->end = lock->start - 1; in locks_insert()
2533 insert_lock(&l->next, newl2); in locks_insert()
2537 lp = &l->next; in locks_insert()
2543 if (lock->type != F_UNLCK) { in locks_insert()
2557 lock->type = flock->l_type; in flock_to_lock()
2558 lock->start = flock->l_start; in flock_to_lock()
2559 lock->end = flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX; in flock_to_lock()
2560 lock->pid = flock->l_pid; in flock_to_lock()
2565 flock->l_type = lock->type; in lock_to_flock()
2566 flock->l_start = lock->start; in lock_to_flock()
2567 flock->l_len = (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1; in lock_to_flock()
2568 flock->l_pid = lock->pid; in lock_to_flock()
2577 int err; in fuse_flush_common() local
2584 err = fuse_fs_flush(f->fs, path, fi); in fuse_flush_common()
2585 errlock = fuse_fs_lock(f->fs, path, fi, F_SETLK, &lock); in fuse_flush_common()
2588 if (errlock != -ENOSYS) { in fuse_flush_common()
2590 l.owner = fi->lock_owner; in fuse_flush_common()
2591 pthread_mutex_lock(&f->lock); in fuse_flush_common()
2593 pthread_mutex_unlock(&f->lock); in fuse_flush_common()
2596 if (err == -ENOSYS) in fuse_flush_common()
2597 err = 0; in fuse_flush_common()
2599 return err; in fuse_flush_common()
2608 int err = 0; in fuse_lib_release() local
2610 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_release()
2612 if (f->conf.debug) in fuse_lib_release()
2614 fi->flush ? "+FLUSH" : "", in fuse_lib_release()
2615 (unsigned long long) fi->fh, fi->flags); in fuse_lib_release()
2617 if (fi->flush) { in fuse_lib_release()
2618 err = fuse_flush_common(f, req, ino, path, fi); in fuse_lib_release()
2619 if (err == -ENOSYS) in fuse_lib_release()
2620 err = 0; in fuse_lib_release()
2627 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_release()
2629 reply_err(req, err); in fuse_lib_release()
2637 int err; in fuse_lib_flush() local
2639 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_flush()
2641 if (path && f->conf.debug) in fuse_lib_flush()
2642 fprintf(stderr, "FLUSH[%llu]\n", (unsigned long long) fi->fh); in fuse_lib_flush()
2643 err = fuse_flush_common(f, req, ino, path, fi); in fuse_lib_flush()
2645 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_flush()
2646 reply_err(req, err); in fuse_lib_flush()
2655 int err; in fuse_lock_common() local
2657 err = -ENOENT; in fuse_lock_common()
2658 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lock_common()
2663 err = fuse_fs_lock(f->fs, path, fi, cmd, lock); in fuse_lock_common()
2667 pthread_rwlock_unlock(&f->tree_lock); in fuse_lock_common()
2668 return err; in fuse_lock_common()
2674 int err; in fuse_lib_getlk() local
2680 l.owner = fi->lock_owner; in fuse_lib_getlk()
2681 pthread_mutex_lock(&f->lock); in fuse_lib_getlk()
2685 pthread_mutex_unlock(&f->lock); in fuse_lib_getlk()
2687 err = fuse_lock_common(req, ino, fi, lock, F_GETLK); in fuse_lib_getlk()
2689 err = 0; in fuse_lib_getlk()
2691 if (!err) in fuse_lib_getlk()
2694 reply_err(req, err); in fuse_lib_getlk()
2701 int err = fuse_lock_common(req, ino, fi, lock, should_sleep ? F_SETLKW : F_SETLK); in fuse_lib_setlk() local
2702 if (!err) { in fuse_lib_setlk()
2706 l.owner = fi->lock_owner; in fuse_lib_setlk()
2707 pthread_mutex_lock(&f->lock); in fuse_lib_setlk()
2709 pthread_mutex_unlock(&f->lock); in fuse_lib_setlk()
2711 reply_err(req, err); in fuse_lib_setlk()
2720 int err; in fuse_lib_bmap() local
2722 err = -ENOENT; in fuse_lib_bmap()
2723 pthread_rwlock_rdlock(&f->tree_lock); in fuse_lib_bmap()
2727 err = fuse_fs_bmap(f->fs, path, blocksize, &idx); in fuse_lib_bmap()
2731 pthread_rwlock_unlock(&f->tree_lock); in fuse_lib_bmap()
2732 if (!err) in fuse_lib_bmap()
2735 reply_err(req, err); in fuse_lib_bmap()
2747 int err; in fuse_lib_ioctl() local
2749 err = -EPERM; in fuse_lib_ioctl()
2751 goto err; in fuse_lib_ioctl()
2759 err = -ENOMEM; in fuse_lib_ioctl()
2762 goto err; in fuse_lib_ioctl()
2771 err = ENOENT; in fuse_lib_ioctl()
2772 goto err; in fuse_lib_ioctl()
2778 err = fuse_fs_ioctl(f->fs, path, cmd, arg, &fi, flags, in fuse_lib_ioctl()
2784 if (err >= 0) { /* not an error */ in fuse_lib_ioctl()
2785 fuse_reply_ioctl(req, err, out_buf, out_bufsz); in fuse_lib_ioctl()
2788 err: in fuse_lib_ioctl()
2789 reply_err(req, err); in fuse_lib_ioctl()
2834 return f->se; in fuse_get_session()
2840 return fuse_session_loop(f->se); in fuse_loop()
2842 return -1; in fuse_loop()
2847 fuse_session_exit(f->se); in fuse_exit()
2852 return &fuse_get_context_internal()->ctx; in fuse_get_context()
2857 return fuse_req_interrupted(fuse_get_context_internal()->req); in fuse_interrupted()
2867 FUSE_OPT_KEY("-h", KEY_HELP),
2868 FUSE_OPT_KEY("--help", KEY_HELP),
2870 FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
2872 FUSE_LIB_OPT("-d", debug, 1),
2904 " -o hard_remove immediate removal (don't hide files)\n" in fuse_lib_help()
2905 " -o use_ino let filesystem set inode numbers\n" in fuse_lib_help()
2906 " -o readdir_ino try to fill in d_ino in readdir\n" in fuse_lib_help()
2907 " -o direct_io use direct I/O\n" in fuse_lib_help()
2908 " -o kernel_cache cache files in kernel\n" in fuse_lib_help()
2910 " -o [no]auto_cache enable caching based on modification times (off)\n" in fuse_lib_help()
2912 " -o umask=M set file permissions (octal)\n" in fuse_lib_help()
2913 " -o uid=N set file owner\n" in fuse_lib_help()
2914 " -o gid=N set file group\n" in fuse_lib_help()
2915 " -o entry_timeout=T cache timeout for names (1.0s)\n" in fuse_lib_help()
2916 " -o negative_timeout=T cache timeout for deleted names (0.0s)\n" in fuse_lib_help()
2917 " -o attr_timeout=T cache timeout for attributes (1.0s)\n" in fuse_lib_help()
2918 " -o ac_attr_timeout=T auto cache timeout for attributes (attr_timeout)\n" in fuse_lib_help()
2919 " -o intr allow requests to be interrupted\n" in fuse_lib_help()
2920 " -o intr_signal=NUM signal to send on interrupt (%i)\n" in fuse_lib_help()
2922 " -o modules=M1[:M2...] names of modules to push onto filesystem stack\n" in fuse_lib_help()
2934 for (m = fuse_modules; m; m = m->next) { in fuse_lib_help_modules()
2935 struct fuse_fs *fs = NULL; in fuse_lib_help_modules() local
2938 if (fuse_opt_add_arg(&args, "") != -1 && in fuse_lib_help_modules()
2939 fuse_opt_add_arg(&args, "-h") != -1) { in fuse_lib_help_modules()
2940 fprintf(stderr, "\n[%s]\n", m->name); in fuse_lib_help_modules()
2941 newfs = m->factory(&args, &fs); in fuse_lib_help_modules()
2965 conf->help = 1; in fuse_lib_opt_proc()
2975 if (sigaction(signum, NULL, &old_sa) == -1) { in fuse_init_intr_signal()
2977 return -1; in fuse_init_intr_signal()
2987 if (sigaction(signum, &sa, NULL) == -1) { in fuse_init_intr_signal()
2989 return -1; in fuse_init_intr_signal()
3012 struct fuse_fs *fs[2]; in fuse_push_module() local
3014 fs[0] = f->fs; in fuse_push_module()
3015 fs[1] = NULL; in fuse_push_module()
3017 return -1; in fuse_push_module()
3019 newfs = m->factory(args, fs); in fuse_push_module()
3022 return -1; in fuse_push_module()
3024 newfs->m = m; in fuse_push_module()
3025 f->fs = newfs; in fuse_push_module()
3034 struct fuse_fs *fs; in fuse_fs_new() local
3041 fs = (struct fuse_fs *) calloc(1, sizeof(struct fuse_fs)); in fuse_fs_new()
3042 if (!fs) { in fuse_fs_new()
3047 fs->user_data = user_data; in fuse_fs_new()
3049 memcpy(&fs->op, op, op_size); in fuse_fs_new()
3050 return fs; in fuse_fs_new()
3059 struct fuse_fs *fs; in fuse_new() local
3062 if (fuse_create_context_key() == -1) in fuse_new()
3071 fs = fuse_fs_new(op, op_size, user_data); in fuse_new()
3072 if (!fs) in fuse_new()
3075 f->fs = fs; in fuse_new()
3078 if (!fs->op.lock) { in fuse_new()
3083 f->conf.entry_timeout = 1.0; in fuse_new()
3084 f->conf.attr_timeout = 1.0; in fuse_new()
3085 f->conf.negative_timeout = 0.0; in fuse_new()
3086 f->conf.hard_remove = 1; in fuse_new()
3087 f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL; in fuse_new()
3089 if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, fuse_lib_opt_proc) == -1) in fuse_new()
3093 if (f->conf.modules) { in fuse_new()
3097 for (module = f->conf.modules; module; module = next) { in fuse_new()
3102 if (module[0] && fuse_push_module(f, module, args) == -1) in fuse_new()
3108 if (!f->conf.ac_attr_timeout_set) in fuse_new()
3109 f->conf.ac_attr_timeout = f->conf.attr_timeout; in fuse_new()
3116 f->conf.readdir_ino = 1; in fuse_new()
3119 f->se = fuse_lowlevel_new(args, &llop, sizeof(llop), f); in fuse_new()
3121 if (f->se == NULL) { in fuse_new()
3123 if (f->conf.help) in fuse_new()
3129 fuse_session_add_chan(f->se, ch); in fuse_new()
3131 f->ctr = 0; in fuse_new()
3132 f->generation = 0; in fuse_new()
3134 f->name_table_size = 14057; in fuse_new()
3135 f->name_table = (struct node **) in fuse_new()
3136 calloc(1, sizeof(struct node *) * f->name_table_size); in fuse_new()
3137 if (f->name_table == NULL) { in fuse_new()
3142 f->id_table_size = 14057; in fuse_new()
3143 f->id_table = (struct node **) in fuse_new()
3144 calloc(1, sizeof(struct node *) * f->id_table_size); in fuse_new()
3145 if (f->id_table == NULL) { in fuse_new()
3150 fuse_mutex_init(&f->lock); in fuse_new()
3151 pthread_rwlock_init(&f->tree_lock, NULL); in fuse_new()
3159 root->name = strdup("/"); in fuse_new()
3160 if (root->name == NULL) { in fuse_new()
3165 if (f->conf.intr && in fuse_new()
3166 fuse_init_intr_signal(f->conf.intr_signal, &f->intr_installed) == -1) in fuse_new()
3169 root->parent = NULL; in fuse_new()
3170 root->nodeid = FUSE_ROOT_ID; in fuse_new()
3171 root->generation = 0; in fuse_new()
3172 root->refctr = 1; in fuse_new()
3173 root->nlookup = 1; in fuse_new()
3179 free(root->name); in fuse_new()
3183 free(f->id_table); in fuse_new()
3185 free(f->name_table); in fuse_new()
3187 fuse_session_destroy(f->se); in fuse_new()
3191 fs->op.destroy = NULL; in fuse_new()
3192 fuse_fs_destroy(f->fs); in fuse_new()
3194 free(f->conf.modules); in fuse_new()
3208 if (f->conf.intr && f->intr_installed) in fuse_destroy()
3209 fuse_restore_intr_signal(f->conf.intr_signal); in fuse_destroy()
3211 if (f->fs) { in fuse_destroy()
3215 c->ctx.fuse = f; in fuse_destroy()
3217 for (i = 0; i < f->id_table_size; i++) { in fuse_destroy()
3220 for (node = f->id_table[i]; node != NULL; node = node->id_next) { in fuse_destroy()
3221 if (node->is_hidden) { in fuse_destroy()
3222 char *path = get_path(f, node->nodeid); in fuse_destroy()
3224 fuse_fs_unlink(f->fs, path); in fuse_destroy()
3231 for (i = 0; i < f->id_table_size; i++) { in fuse_destroy()
3235 for (node = f->id_table[i]; node != NULL; node = next) { in fuse_destroy()
3236 next = node->id_next; in fuse_destroy()
3240 free(f->id_table); in fuse_destroy()
3241 free(f->name_table); in fuse_destroy()
3242 pthread_mutex_destroy(&f->lock); in fuse_destroy()
3243 pthread_rwlock_destroy(&f->tree_lock); in fuse_destroy()
3244 fuse_session_destroy(f->se); in fuse_destroy()
3246 free(f->conf.modules); in fuse_destroy()