Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 4 | |
Miklos Szeredi | 8b39a9f | 2002-10-25 12:41:16 +0000 | [diff] [blame] | 5 | This program can be distributed under the terms of the GNU LGPL. |
| 6 | See the file COPYING.LIB |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 9 | |
| 10 | /* For pthread_rwlock_t */ |
| 11 | #define _GNU_SOURCE |
| 12 | |
Miklos Szeredi | 178451d | 2005-08-15 13:19:07 +0000 | [diff] [blame] | 13 | #include "fuse_i.h" |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 14 | #include "fuse_lowlevel.h" |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 15 | #include "fuse_opt.h" |
Miklos Szeredi | 38f152c | 2006-09-03 18:28:52 +0000 | [diff] [blame] | 16 | #include "fuse_misc.h" |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 17 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 19 | #include <string.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 21 | #include <stddef.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 23 | #include <time.h> |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 24 | #include <fcntl.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 25 | #include <limits.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 26 | #include <errno.h> |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 27 | #include <signal.h> |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 28 | #include <assert.h> |
Miklos Szeredi | 019b4e9 | 2001-12-26 18:08:09 +0000 | [diff] [blame] | 29 | #include <sys/param.h> |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 30 | #include <sys/uio.h> |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 31 | #include <sys/time.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 32 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 33 | #define FUSE_MAX_PATH 4096 |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 34 | #define FUSE_DEFAULT_INTR_SIGNAL SIGUSR1 |
Miklos Szeredi | 30e093a | 2005-04-03 17:44:54 +0000 | [diff] [blame] | 35 | |
Miklos Szeredi | e248e4b | 2005-12-14 16:18:32 +0000 | [diff] [blame] | 36 | #define FUSE_UNKNOWN_INO 0xffffffff |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 37 | #define OFFSET_MAX 0x7fffffffffffffffLL |
Miklos Szeredi | e248e4b | 2005-12-14 16:18:32 +0000 | [diff] [blame] | 38 | |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 39 | struct fuse_config { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 40 | unsigned int uid; |
| 41 | unsigned int gid; |
| 42 | unsigned int umask; |
| 43 | double entry_timeout; |
| 44 | double negative_timeout; |
| 45 | double attr_timeout; |
Miklos Szeredi | 6e806e9 | 2006-02-16 16:59:39 +0000 | [diff] [blame] | 46 | double ac_attr_timeout; |
| 47 | int ac_attr_timeout_set; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 48 | int debug; |
| 49 | int hard_remove; |
| 50 | int use_ino; |
| 51 | int readdir_ino; |
| 52 | int set_mode; |
| 53 | int set_uid; |
| 54 | int set_gid; |
| 55 | int direct_io; |
| 56 | int kernel_cache; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 57 | int auto_cache; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 58 | int intr; |
| 59 | int intr_signal; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 62 | struct fuse { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 63 | struct fuse_session *se; |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 64 | struct fuse_operations op; |
| 65 | int compat; |
| 66 | struct node **name_table; |
| 67 | size_t name_table_size; |
| 68 | struct node **id_table; |
| 69 | size_t id_table_size; |
| 70 | fuse_ino_t ctr; |
| 71 | unsigned int generation; |
| 72 | unsigned int hidectr; |
| 73 | pthread_mutex_t lock; |
| 74 | pthread_rwlock_t tree_lock; |
| 75 | void *user_data; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 76 | struct fuse_config conf; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 77 | int intr_installed; |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 80 | struct lock { |
| 81 | int type; |
| 82 | off_t start; |
| 83 | off_t end; |
| 84 | pid_t pid; |
| 85 | uint64_t owner; |
| 86 | struct lock *next; |
| 87 | }; |
| 88 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 89 | struct node { |
| 90 | struct node *name_next; |
| 91 | struct node *id_next; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 92 | fuse_ino_t nodeid; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 93 | unsigned int generation; |
| 94 | int refctr; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 95 | fuse_ino_t parent; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 96 | char *name; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 97 | uint64_t nlookup; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 98 | int open_count; |
| 99 | int is_hidden; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 100 | struct timespec stat_updated; |
| 101 | struct timespec mtime; |
| 102 | off_t size; |
| 103 | int cache_valid; |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 104 | struct lock *locks; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | struct fuse_dirhandle { |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 108 | pthread_mutex_t lock; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 109 | struct fuse *fuse; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 110 | fuse_req_t req; |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 111 | char *contents; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 112 | int allocated; |
Miklos Szeredi | b92d978 | 2005-02-07 16:10:49 +0000 | [diff] [blame] | 113 | unsigned len; |
Miklos Szeredi | c4c12ae | 2005-10-20 14:48:50 +0000 | [diff] [blame] | 114 | unsigned size; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 115 | unsigned needlen; |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 116 | int filled; |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 117 | uint64_t fh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 118 | int error; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 119 | fuse_ino_t nodeid; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 122 | struct fuse_context_i { |
| 123 | struct fuse_context ctx; |
| 124 | fuse_req_t req; |
| 125 | }; |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 126 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 127 | static pthread_key_t fuse_context_key; |
| 128 | static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER; |
| 129 | static int fuse_context_ref; |
| 130 | |
| 131 | static int fuse_compat_open(struct fuse *, fuse_req_t, char *, |
| 132 | struct fuse_file_info *); |
| 133 | static void fuse_compat_release(struct fuse *, fuse_req_t, char *, |
| 134 | struct fuse_file_info *); |
| 135 | static int fuse_compat_opendir(struct fuse *, fuse_req_t, char *, |
| 136 | struct fuse_file_info *); |
| 137 | static int fuse_compat_statfs(struct fuse *, fuse_req_t, struct statvfs *); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 138 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 139 | static struct node *get_node_nocheck(struct fuse *f, fuse_ino_t nodeid) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 140 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 141 | size_t hash = nodeid % f->id_table_size; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 142 | struct node *node; |
| 143 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 144 | for (node = f->id_table[hash]; node != NULL; node = node->id_next) |
| 145 | if (node->nodeid == nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 146 | return node; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 147 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 148 | return NULL; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 151 | static struct node *get_node(struct fuse *f, fuse_ino_t nodeid) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 152 | { |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 153 | struct node *node = get_node_nocheck(f, nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 154 | if (!node) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 155 | fprintf(stderr, "fuse internal error: node %llu not found\n", |
| 156 | (unsigned long long) nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 157 | abort(); |
| 158 | } |
| 159 | return node; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 162 | static void free_node(struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 163 | { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 164 | free(node->name); |
| 165 | free(node); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 168 | static void unhash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 169 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 170 | size_t hash = node->nodeid % f->id_table_size; |
| 171 | struct node **nodep = &f->id_table[hash]; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 172 | |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 173 | for (; *nodep != NULL; nodep = &(*nodep)->id_next) |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 174 | if (*nodep == node) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 175 | *nodep = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 176 | return; |
| 177 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 180 | static void hash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 181 | { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 182 | size_t hash = node->nodeid % f->id_table_size; |
| 183 | node->id_next = f->id_table[hash]; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 184 | f->id_table[hash] = node; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 187 | static unsigned int name_hash(struct fuse *f, fuse_ino_t parent, const char *name) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 188 | { |
| 189 | unsigned int hash = *name; |
| 190 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 191 | if (hash) |
| 192 | for (name += 1; *name != '\0'; name++) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 193 | hash = (hash << 5) - hash + *name; |
| 194 | |
| 195 | return (hash + parent) % f->name_table_size; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 198 | static void unref_node(struct fuse *f, struct node *node); |
| 199 | |
| 200 | static void unhash_name(struct fuse *f, struct node *node) |
| 201 | { |
| 202 | if (node->name) { |
| 203 | size_t hash = name_hash(f, node->parent, node->name); |
| 204 | struct node **nodep = &f->name_table[hash]; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 205 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 206 | for (; *nodep != NULL; nodep = &(*nodep)->name_next) |
| 207 | if (*nodep == node) { |
| 208 | *nodep = node->name_next; |
| 209 | node->name_next = NULL; |
| 210 | unref_node(f, get_node(f, node->parent)); |
| 211 | free(node->name); |
| 212 | node->name = NULL; |
| 213 | node->parent = 0; |
| 214 | return; |
| 215 | } |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 216 | fprintf(stderr, "fuse internal error: unable to unhash node: %llu\n", |
| 217 | (unsigned long long) node->nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 218 | abort(); |
| 219 | } |
| 220 | } |
| 221 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 222 | static int hash_name(struct fuse *f, struct node *node, fuse_ino_t parent, |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 223 | const char *name) |
| 224 | { |
| 225 | size_t hash = name_hash(f, parent, name); |
| 226 | node->name = strdup(name); |
| 227 | if (node->name == NULL) |
| 228 | return -1; |
| 229 | |
| 230 | get_node(f, parent)->refctr ++; |
| 231 | node->parent = parent; |
| 232 | node->name_next = f->name_table[hash]; |
| 233 | f->name_table[hash] = node; |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static void delete_node(struct fuse *f, struct node *node) |
| 238 | { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 239 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 240 | printf("delete: %llu\n", (unsigned long long) node->nodeid); |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 241 | fflush(stdout); |
| 242 | } |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 243 | assert(!node->name); |
| 244 | unhash_id(f, node); |
| 245 | free_node(node); |
| 246 | } |
| 247 | |
| 248 | static void unref_node(struct fuse *f, struct node *node) |
| 249 | { |
| 250 | assert(node->refctr > 0); |
| 251 | node->refctr --; |
| 252 | if (!node->refctr) |
| 253 | delete_node(f, node); |
| 254 | } |
| 255 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 256 | static fuse_ino_t next_id(struct fuse *f) |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 257 | { |
| 258 | do { |
| 259 | f->ctr++; |
| 260 | if (!f->ctr) |
| 261 | f->generation ++; |
| 262 | } while (f->ctr == 0 || get_node_nocheck(f, f->ctr) != NULL); |
| 263 | return f->ctr; |
| 264 | } |
| 265 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 266 | static struct node *lookup_node(struct fuse *f, fuse_ino_t parent, |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 267 | const char *name) |
| 268 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 269 | size_t hash = name_hash(f, parent, name); |
| 270 | struct node *node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 271 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 272 | for (node = f->name_table[hash]; node != NULL; node = node->name_next) |
| 273 | if (node->parent == parent && strcmp(node->name, name) == 0) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 274 | return node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 275 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 276 | return NULL; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 279 | static struct node *find_node(struct fuse *f, fuse_ino_t parent, |
| 280 | const char *name) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 281 | { |
| 282 | struct node *node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 283 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 284 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 285 | node = lookup_node(f, parent, name); |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 286 | if (node == NULL) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 287 | node = (struct node *) calloc(1, sizeof(struct node)); |
| 288 | if (node == NULL) |
| 289 | goto out_err; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 290 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 291 | node->refctr = 1; |
| 292 | node->nodeid = next_id(f); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 293 | node->open_count = 0; |
| 294 | node->is_hidden = 0; |
| 295 | node->generation = f->generation; |
| 296 | if (hash_name(f, node, parent, name) == -1) { |
| 297 | free(node); |
| 298 | node = NULL; |
| 299 | goto out_err; |
| 300 | } |
| 301 | hash_id(f, node); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 302 | } |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 303 | node->nlookup ++; |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 304 | out_err: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 305 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 306 | return node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 309 | static char *add_name(char *buf, char *s, const char *name) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 310 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 311 | size_t len = strlen(name); |
| 312 | s -= len; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 313 | if (s <= buf) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 314 | fprintf(stderr, "fuse: path too long: ...%s\n", s + len); |
| 315 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 316 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 317 | strncpy(s, name, len); |
| 318 | s--; |
| 319 | *s = '/'; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 320 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 321 | return s; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 324 | static char *get_path_name(struct fuse *f, fuse_ino_t nodeid, const char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 325 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 326 | char buf[FUSE_MAX_PATH]; |
| 327 | char *s = buf + FUSE_MAX_PATH - 1; |
| 328 | struct node *node; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 329 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 330 | *s = '\0'; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 331 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 332 | if (name != NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 333 | s = add_name(buf, s, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 334 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 335 | return NULL; |
| 336 | } |
| 337 | |
| 338 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 339 | for (node = get_node(f, nodeid); node && node->nodeid != FUSE_ROOT_ID; |
| 340 | node = get_node(f, node->parent)) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 341 | if (node->name == NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 342 | s = NULL; |
| 343 | break; |
| 344 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 345 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 346 | s = add_name(buf, s, node->name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 347 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 348 | break; |
| 349 | } |
| 350 | pthread_mutex_unlock(&f->lock); |
| 351 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 352 | if (node == NULL || s == NULL) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 353 | return NULL; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 354 | else if (*s == '\0') |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 355 | return strdup("/"); |
| 356 | else |
| 357 | return strdup(s); |
| 358 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 359 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 360 | static char *get_path(struct fuse *f, fuse_ino_t nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 361 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 362 | return get_path_name(f, nodeid, NULL); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 365 | static void forget_node(struct fuse *f, fuse_ino_t nodeid, uint64_t nlookup) |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 366 | { |
| 367 | struct node *node; |
| 368 | if (nodeid == FUSE_ROOT_ID) |
| 369 | return; |
| 370 | pthread_mutex_lock(&f->lock); |
| 371 | node = get_node(f, nodeid); |
| 372 | assert(node->nlookup >= nlookup); |
| 373 | node->nlookup -= nlookup; |
| 374 | if (!node->nlookup) { |
| 375 | unhash_name(f, node); |
| 376 | unref_node(f, node); |
| 377 | } |
| 378 | pthread_mutex_unlock(&f->lock); |
| 379 | } |
| 380 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 381 | static void remove_node(struct fuse *f, fuse_ino_t dir, const char *name) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 382 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 383 | struct node *node; |
| 384 | |
| 385 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 386 | node = lookup_node(f, dir, name); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 387 | if (node != NULL) |
| 388 | unhash_name(f, node); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 389 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 392 | static int rename_node(struct fuse *f, fuse_ino_t olddir, const char *oldname, |
| 393 | fuse_ino_t newdir, const char *newname, int hide) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 394 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 395 | struct node *node; |
| 396 | struct node *newnode; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 397 | int err = 0; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 398 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 399 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 400 | node = lookup_node(f, olddir, oldname); |
| 401 | newnode = lookup_node(f, newdir, newname); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 402 | if (node == NULL) |
| 403 | goto out; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 404 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 405 | if (newnode != NULL) { |
| 406 | if (hide) { |
| 407 | fprintf(stderr, "fuse: hidden file got created during hiding\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 408 | err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 409 | goto out; |
| 410 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 411 | unhash_name(f, newnode); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 412 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 413 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 414 | unhash_name(f, node); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 415 | if (hash_name(f, node, newdir, newname) == -1) { |
| 416 | err = -ENOMEM; |
| 417 | goto out; |
| 418 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 419 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 420 | if (hide) |
| 421 | node->is_hidden = 1; |
| 422 | |
| 423 | out: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 424 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 425 | return err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 428 | static void set_stat(struct fuse *f, fuse_ino_t nodeid, struct stat *stbuf) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 429 | { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 430 | if (!f->conf.use_ino) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 431 | stbuf->st_ino = nodeid; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 432 | if (f->conf.set_mode) |
| 433 | stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f->conf.umask); |
| 434 | if (f->conf.set_uid) |
| 435 | stbuf->st_uid = f->conf.uid; |
| 436 | if (f->conf.set_gid) |
| 437 | stbuf->st_gid = f->conf.gid; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 440 | static struct fuse *req_fuse(fuse_req_t req) |
| 441 | { |
| 442 | return (struct fuse *) fuse_req_userdata(req); |
| 443 | } |
| 444 | |
| 445 | static void fuse_intr_sighandler(int sig) |
| 446 | { |
| 447 | (void) sig; |
| 448 | /* Nothing to do */ |
| 449 | } |
| 450 | |
| 451 | struct fuse_intr_data { |
| 452 | pthread_t id; |
| 453 | pthread_cond_t cond; |
| 454 | int finished; |
| 455 | }; |
| 456 | |
| 457 | static void fuse_interrupt(fuse_req_t req, void *d_) |
| 458 | { |
| 459 | struct fuse_intr_data *d = d_; |
| 460 | struct fuse *f = req_fuse(req); |
| 461 | |
| 462 | if (d->id == pthread_self()) |
| 463 | return; |
| 464 | |
| 465 | pthread_mutex_lock(&f->lock); |
| 466 | while (!d->finished) { |
| 467 | struct timeval now; |
| 468 | struct timespec timeout; |
| 469 | |
| 470 | pthread_kill(d->id, f->conf.intr_signal); |
| 471 | gettimeofday(&now, NULL); |
| 472 | timeout.tv_sec = now.tv_sec + 1; |
| 473 | timeout.tv_nsec = now.tv_usec * 1000; |
| 474 | pthread_cond_timedwait(&d->cond, &f->lock, &timeout); |
| 475 | } |
| 476 | pthread_mutex_unlock(&f->lock); |
| 477 | } |
| 478 | |
| 479 | static void fuse_do_finish_interrupt(struct fuse *f, fuse_req_t req, |
| 480 | struct fuse_intr_data *d) |
| 481 | { |
| 482 | pthread_mutex_lock(&f->lock); |
| 483 | d->finished = 1; |
| 484 | pthread_cond_broadcast(&d->cond); |
| 485 | pthread_mutex_unlock(&f->lock); |
| 486 | fuse_req_interrupt_func(req, NULL, NULL); |
| 487 | pthread_cond_destroy(&d->cond); |
| 488 | } |
| 489 | |
| 490 | static void fuse_do_prepare_interrupt(fuse_req_t req, struct fuse_intr_data *d) |
| 491 | { |
| 492 | d->id = pthread_self(); |
| 493 | pthread_cond_init(&d->cond, NULL); |
| 494 | d->finished = 0; |
| 495 | fuse_req_interrupt_func(req, fuse_interrupt, d); |
| 496 | } |
| 497 | |
| 498 | static inline void fuse_finish_interrupt(struct fuse *f, fuse_req_t req, |
| 499 | struct fuse_intr_data *d) |
| 500 | { |
| 501 | if (f->conf.intr) |
| 502 | fuse_do_finish_interrupt(f, req, d); |
| 503 | } |
| 504 | |
| 505 | static inline void fuse_prepare_interrupt(struct fuse *f, fuse_req_t req, |
| 506 | struct fuse_intr_data *d) |
| 507 | { |
| 508 | if (f->conf.intr) |
| 509 | fuse_do_prepare_interrupt(req, d); |
| 510 | } |
| 511 | |
| 512 | static int fuse_do_getattr(struct fuse *f, fuse_req_t req, const char *path, |
| 513 | struct stat *buf) |
| 514 | { |
| 515 | int res; |
| 516 | struct fuse_intr_data d; |
| 517 | fuse_prepare_interrupt(f, req, &d); |
| 518 | res = f->op.getattr(path, buf); |
| 519 | fuse_finish_interrupt(f, req, &d); |
| 520 | return res; |
| 521 | } |
| 522 | |
| 523 | static int fuse_do_fgetattr(struct fuse *f, fuse_req_t req, const char *path, |
| 524 | struct stat *buf, struct fuse_file_info *fi) |
| 525 | { |
| 526 | int res; |
| 527 | struct fuse_intr_data d; |
| 528 | fuse_prepare_interrupt(f, req, &d); |
| 529 | res = f->op.fgetattr(path, buf, fi); |
| 530 | fuse_finish_interrupt(f, req, &d); |
| 531 | return res; |
| 532 | } |
| 533 | |
| 534 | static int fuse_do_rename(struct fuse *f, fuse_req_t req, const char *oldpath, |
| 535 | const char *newpath) |
| 536 | { |
| 537 | int res; |
| 538 | struct fuse_intr_data d; |
| 539 | fuse_prepare_interrupt(f, req, &d); |
| 540 | res = f->op.rename(oldpath, newpath); |
| 541 | fuse_finish_interrupt(f, req, &d); |
| 542 | return res; |
| 543 | } |
| 544 | |
| 545 | static int fuse_do_unlink(struct fuse *f, fuse_req_t req, const char *path) |
| 546 | { |
| 547 | int res; |
| 548 | struct fuse_intr_data d; |
| 549 | fuse_prepare_interrupt(f, req, &d); |
| 550 | res = f->op.unlink(path); |
| 551 | fuse_finish_interrupt(f, req, &d); |
| 552 | return res; |
| 553 | } |
| 554 | |
| 555 | static void fuse_do_release(struct fuse *f, fuse_req_t req, const char *path, |
| 556 | struct fuse_file_info *fi) |
| 557 | { |
| 558 | struct fuse_intr_data d; |
| 559 | fuse_prepare_interrupt(f, req, &d); |
| 560 | f->op.release(path, fi); |
| 561 | fuse_finish_interrupt(f, req, &d); |
| 562 | } |
| 563 | |
| 564 | static int fuse_do_opendir(struct fuse *f, fuse_req_t req, char *path, |
| 565 | struct fuse_file_info *fi) |
| 566 | { |
| 567 | int res; |
| 568 | struct fuse_intr_data d; |
| 569 | fuse_prepare_interrupt(f, req, &d); |
| 570 | res = f->op.opendir(path, fi); |
| 571 | fuse_finish_interrupt(f, req, &d); |
| 572 | return res; |
| 573 | } |
| 574 | |
| 575 | static int fuse_do_open(struct fuse *f, fuse_req_t req, char *path, |
| 576 | struct fuse_file_info *fi) |
| 577 | { |
| 578 | int res; |
| 579 | struct fuse_intr_data d; |
| 580 | fuse_prepare_interrupt(f, req, &d); |
| 581 | res = f->op.open(path, fi); |
| 582 | fuse_finish_interrupt(f, req, &d); |
| 583 | return res; |
| 584 | } |
| 585 | |
| 586 | static int fuse_do_statfs(struct fuse *f, fuse_req_t req, const char *path, |
| 587 | struct statvfs *buf) |
| 588 | { |
| 589 | int res; |
| 590 | struct fuse_intr_data d; |
| 591 | fuse_prepare_interrupt(f, req, &d); |
| 592 | res = f->op.statfs(path, buf); |
| 593 | fuse_finish_interrupt(f, req, &d); |
| 594 | return res; |
| 595 | } |
| 596 | |
| 597 | static void fuse_do_releasedir(struct fuse *f, fuse_req_t req, |
| 598 | const char *path, struct fuse_file_info *fi) |
| 599 | { |
| 600 | struct fuse_intr_data d; |
| 601 | fuse_prepare_interrupt(f, req, &d); |
| 602 | f->op.releasedir(path, fi); |
| 603 | fuse_finish_interrupt(f, req, &d); |
| 604 | } |
| 605 | |
| 606 | static int fuse_do_create(struct fuse *f, fuse_req_t req, const char *path, |
| 607 | mode_t mode, struct fuse_file_info *fi) |
| 608 | { |
| 609 | int res; |
| 610 | struct fuse_intr_data d; |
| 611 | fuse_prepare_interrupt(f, req, &d); |
| 612 | res = f->op.create(path, mode, fi); |
| 613 | fuse_finish_interrupt(f, req, &d); |
| 614 | return res; |
| 615 | } |
| 616 | |
| 617 | static int fuse_do_lock(struct fuse *f, fuse_req_t req, const char *path, |
| 618 | struct fuse_file_info *fi, int cmd, struct flock *lock, |
| 619 | uint64_t owner) |
| 620 | { |
| 621 | int res; |
| 622 | struct fuse_intr_data d; |
| 623 | fuse_prepare_interrupt(f, req, &d); |
| 624 | res = f->op.lock(path, fi, cmd, lock, owner); |
| 625 | fuse_finish_interrupt(f, req, &d); |
| 626 | return res; |
| 627 | } |
| 628 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 629 | static int is_open(struct fuse *f, fuse_ino_t dir, const char *name) |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 630 | { |
| 631 | struct node *node; |
| 632 | int isopen = 0; |
| 633 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 634 | node = lookup_node(f, dir, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 635 | if (node && node->open_count > 0) |
| 636 | isopen = 1; |
| 637 | pthread_mutex_unlock(&f->lock); |
| 638 | return isopen; |
| 639 | } |
| 640 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 641 | static char *hidden_name(struct fuse *f, fuse_req_t req, fuse_ino_t dir, |
| 642 | const char *oldname, char *newname, size_t bufsize) |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 643 | { |
| 644 | struct stat buf; |
| 645 | struct node *node; |
| 646 | struct node *newnode; |
| 647 | char *newpath; |
| 648 | int res; |
| 649 | int failctr = 10; |
| 650 | |
| 651 | if (!f->op.getattr) |
| 652 | return NULL; |
| 653 | |
| 654 | do { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 655 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 656 | node = lookup_node(f, dir, oldname); |
| 657 | if (node == NULL) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 658 | pthread_mutex_unlock(&f->lock); |
| 659 | return NULL; |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 660 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 661 | do { |
| 662 | f->hidectr ++; |
| 663 | snprintf(newname, bufsize, ".fuse_hidden%08x%08x", |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 664 | (unsigned int) node->nodeid, f->hidectr); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 665 | newnode = lookup_node(f, dir, newname); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 666 | } while(newnode); |
| 667 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 668 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 669 | newpath = get_path_name(f, dir, newname); |
| 670 | if (!newpath) |
| 671 | break; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 672 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 673 | res = fuse_do_getattr(f, req, newpath, &buf); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 674 | if (res != 0) |
| 675 | break; |
| 676 | free(newpath); |
| 677 | newpath = NULL; |
| 678 | } while(--failctr); |
| 679 | |
| 680 | return newpath; |
| 681 | } |
| 682 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 683 | static int hide_node(struct fuse *f, fuse_req_t req, const char *oldpath, |
| 684 | fuse_ino_t dir, const char *oldname) |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 685 | { |
| 686 | char newname[64]; |
| 687 | char *newpath; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 688 | int err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 689 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 690 | if (f->op.rename && f->op.unlink) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 691 | newpath = hidden_name(f, req, dir, oldname, newname, sizeof(newname)); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 692 | if (newpath) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 693 | int res = fuse_do_rename(f, req, oldpath, newpath); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 694 | if (res == 0) |
| 695 | err = rename_node(f, dir, oldname, dir, newname, 1); |
| 696 | free(newpath); |
| 697 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 698 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 699 | return err; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 702 | static int mtime_eq(const struct stat *stbuf, const struct timespec *ts) |
| 703 | { |
| 704 | return stbuf->st_mtime == ts->tv_sec |
Csaba Henk | 3e3a125 | 2006-09-24 14:53:29 +0000 | [diff] [blame] | 705 | #ifdef FUSE_STAT_HAS_NANOSEC |
| 706 | && ST_MTIM(stbuf).tv_nsec == ts->tv_nsec |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 707 | #endif |
| 708 | ; |
| 709 | } |
| 710 | |
| 711 | static void mtime_set(const struct stat *stbuf, struct timespec *ts) |
| 712 | { |
Csaba Henk | 3e3a125 | 2006-09-24 14:53:29 +0000 | [diff] [blame] | 713 | #ifdef FUSE_STAT_HAS_NANOSEC |
| 714 | *ts = ST_MTIM(stbuf); |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 715 | #else |
| 716 | ts->tv_sec = stbuf->st_mtime; |
| 717 | #endif |
| 718 | } |
| 719 | |
Miklos Szeredi | 2512aaa | 2006-05-03 14:54:59 +0000 | [diff] [blame] | 720 | #ifndef CLOCK_MONOTONIC |
| 721 | #define CLOCK_MONOTONIC CLOCK_REALTIME |
| 722 | #endif |
| 723 | |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 724 | static void curr_time(struct timespec *now) |
| 725 | { |
| 726 | static clockid_t clockid = CLOCK_MONOTONIC; |
| 727 | int res = clock_gettime(clockid, now); |
| 728 | if (res == -1 && errno == EINVAL) { |
| 729 | clockid = CLOCK_REALTIME; |
| 730 | res = clock_gettime(clockid, now); |
| 731 | } |
| 732 | if (res == -1) { |
| 733 | perror("fuse: clock_gettime"); |
| 734 | abort(); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | static void update_stat(struct node *node, const struct stat *stbuf) |
| 739 | { |
| 740 | if (node->cache_valid && (!mtime_eq(stbuf, &node->mtime) || |
| 741 | stbuf->st_size != node->size)) |
| 742 | node->cache_valid = 0; |
| 743 | mtime_set(stbuf, &node->mtime); |
| 744 | node->size = stbuf->st_size; |
| 745 | curr_time(&node->stat_updated); |
| 746 | } |
| 747 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 748 | static int lookup_path(struct fuse *f, fuse_req_t req, fuse_ino_t nodeid, |
| 749 | const char *name, const char *path, |
| 750 | struct fuse_entry_param *e, struct fuse_file_info *fi) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 751 | { |
| 752 | int res; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 753 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 754 | memset(e, 0, sizeof(struct fuse_entry_param)); |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 755 | if (fi && f->op.fgetattr) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 756 | res = fuse_do_fgetattr(f, req, path, &e->attr, fi); |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 757 | else |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 758 | res = fuse_do_getattr(f, req, path, &e->attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 759 | if (res == 0) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 760 | struct node *node; |
| 761 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 762 | node = find_node(f, nodeid, name); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 763 | if (node == NULL) |
| 764 | res = -ENOMEM; |
| 765 | else { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 766 | e->ino = node->nodeid; |
| 767 | e->generation = node->generation; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 768 | e->entry_timeout = f->conf.entry_timeout; |
| 769 | e->attr_timeout = f->conf.attr_timeout; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 770 | if (f->conf.auto_cache) { |
| 771 | pthread_mutex_lock(&f->lock); |
| 772 | update_stat(node, &e->attr); |
| 773 | pthread_mutex_unlock(&f->lock); |
| 774 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 775 | set_stat(f, e->ino, &e->attr); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 776 | if (f->conf.debug) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 777 | printf(" NODEID: %lu\n", (unsigned long) e->ino); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 778 | fflush(stdout); |
| 779 | } |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | return res; |
| 783 | } |
| 784 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 785 | static struct fuse_context_i *fuse_get_context_internal(void) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 786 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 787 | struct fuse_context_i *c; |
| 788 | |
| 789 | c = (struct fuse_context_i *) pthread_getspecific(fuse_context_key); |
| 790 | if (c == NULL) { |
| 791 | c = (struct fuse_context_i *) malloc(sizeof(struct fuse_context_i)); |
| 792 | if (c == NULL) { |
| 793 | /* This is hard to deal with properly, so just abort. If |
| 794 | memory is so low that the context cannot be allocated, |
| 795 | there's not much hope for the filesystem anyway */ |
| 796 | fprintf(stderr, "fuse: failed to allocate thread specific data\n"); |
| 797 | abort(); |
| 798 | } |
| 799 | pthread_setspecific(fuse_context_key, c); |
| 800 | } |
| 801 | return c; |
| 802 | } |
| 803 | |
| 804 | static void fuse_freecontext(void *data) |
| 805 | { |
| 806 | free(data); |
| 807 | } |
| 808 | |
| 809 | static int fuse_create_context_key(void) |
| 810 | { |
| 811 | int err = 0; |
| 812 | pthread_mutex_lock(&fuse_context_lock); |
| 813 | if (!fuse_context_ref) { |
| 814 | err = pthread_key_create(&fuse_context_key, fuse_freecontext); |
| 815 | if (err) { |
| 816 | fprintf(stderr, "fuse: failed to create thread specific key: %s\n", |
| 817 | strerror(err)); |
| 818 | pthread_mutex_unlock(&fuse_context_lock); |
| 819 | return -1; |
| 820 | } |
| 821 | } |
| 822 | fuse_context_ref++; |
| 823 | pthread_mutex_unlock(&fuse_context_lock); |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | static void fuse_delete_context_key(void) |
| 828 | { |
| 829 | pthread_mutex_lock(&fuse_context_lock); |
| 830 | fuse_context_ref--; |
| 831 | if (!fuse_context_ref) { |
| 832 | free(pthread_getspecific(fuse_context_key)); |
| 833 | pthread_key_delete(fuse_context_key); |
| 834 | } |
| 835 | pthread_mutex_unlock(&fuse_context_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 836 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 837 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 838 | static struct fuse *req_fuse_prepare(fuse_req_t req) |
| 839 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 840 | struct fuse_context_i *c = fuse_get_context_internal(); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 841 | const struct fuse_ctx *ctx = fuse_req_ctx(req); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 842 | c->req = req; |
| 843 | c->ctx.fuse = req_fuse(req); |
| 844 | c->ctx.uid = ctx->uid; |
| 845 | c->ctx.gid = ctx->gid; |
| 846 | c->ctx.pid = ctx->pid; |
| 847 | c->ctx.private_data = c->ctx.fuse->user_data; |
| 848 | return c->ctx.fuse; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static inline void reply_err(fuse_req_t req, int err) |
| 852 | { |
| 853 | /* fuse_reply_err() uses non-negated errno values */ |
| 854 | fuse_reply_err(req, -err); |
| 855 | } |
| 856 | |
| 857 | static void reply_entry(fuse_req_t req, const struct fuse_entry_param *e, |
| 858 | int err) |
| 859 | { |
| 860 | if (!err) { |
Miklos Szeredi | b67f216 | 2006-02-20 10:55:33 +0000 | [diff] [blame] | 861 | struct fuse *f = req_fuse(req); |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 862 | if (fuse_reply_entry(req, e) == -ENOENT) |
Miklos Szeredi | b67f216 | 2006-02-20 10:55:33 +0000 | [diff] [blame] | 863 | forget_node(f, e->ino, 1); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 864 | } else |
| 865 | reply_err(req, err); |
| 866 | } |
| 867 | |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 868 | static void fuse_data_init(void *data, struct fuse_conn_info *conn) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 869 | { |
| 870 | struct fuse *f = (struct fuse *) data; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 871 | struct fuse_context_i *c = fuse_get_context_internal(); |
Miklos Szeredi | 4f5df5e | 2005-10-07 12:39:58 +0000 | [diff] [blame] | 872 | |
| 873 | memset(c, 0, sizeof(*c)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 874 | c->ctx.fuse = f; |
| 875 | c->ctx.private_data = f->user_data; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 876 | |
| 877 | if (f->op.init) |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 878 | f->user_data = f->op.init(conn); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static void fuse_data_destroy(void *data) |
| 882 | { |
| 883 | struct fuse *f = (struct fuse *) data; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 884 | struct fuse_context_i *c = fuse_get_context_internal(); |
Miklos Szeredi | 4f5df5e | 2005-10-07 12:39:58 +0000 | [diff] [blame] | 885 | |
| 886 | memset(c, 0, sizeof(*c)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 887 | c->ctx.fuse = f; |
| 888 | c->ctx.private_data = f->user_data; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 889 | |
| 890 | if (f->op.destroy) |
| 891 | f->op.destroy(f->user_data); |
| 892 | } |
| 893 | |
| 894 | static void fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) |
| 895 | { |
| 896 | struct fuse *f = req_fuse_prepare(req); |
| 897 | struct fuse_entry_param e; |
| 898 | char *path; |
| 899 | int err; |
| 900 | |
| 901 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 902 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 903 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 904 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 905 | if (f->conf.debug) { |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 906 | printf("LOOKUP %s\n", path); |
| 907 | fflush(stdout); |
| 908 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 909 | err = -ENOSYS; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 910 | if (f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 911 | err = lookup_path(f, req, parent, name, path, &e, NULL); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 912 | if (err == -ENOENT && f->conf.negative_timeout != 0.0) { |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 913 | e.ino = 0; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 914 | e.entry_timeout = f->conf.negative_timeout; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 915 | err = 0; |
| 916 | } |
| 917 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 918 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 919 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 920 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 921 | reply_entry(req, &e, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 924 | static void fuse_forget(fuse_req_t req, fuse_ino_t ino, unsigned long nlookup) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 925 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 926 | struct fuse *f = req_fuse(req); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 927 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 928 | printf("FORGET %llu/%lu\n", (unsigned long long) ino, nlookup); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 929 | fflush(stdout); |
| 930 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 931 | forget_node(f, ino, nlookup); |
| 932 | fuse_reply_none(req); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 935 | static void fuse_getattr(fuse_req_t req, fuse_ino_t ino, |
| 936 | struct fuse_file_info *fi) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 937 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 938 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 939 | struct stat buf; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 940 | char *path; |
| 941 | int err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 942 | |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 943 | (void) fi; |
Miklos Szeredi | 16dbf94 | 2006-09-02 13:20:40 +0000 | [diff] [blame] | 944 | memset(&buf, 0, sizeof(buf)); |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 945 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 946 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 947 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 948 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 949 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 950 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 951 | if (f->op.getattr) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 952 | err = fuse_do_getattr(f, req, path, &buf); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 953 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 954 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 955 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 956 | if (!err) { |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 957 | if (f->conf.auto_cache) { |
| 958 | pthread_mutex_lock(&f->lock); |
| 959 | update_stat(get_node(f, ino), &buf); |
| 960 | pthread_mutex_unlock(&f->lock); |
| 961 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 962 | set_stat(f, ino, &buf); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 963 | fuse_reply_attr(req, &buf, f->conf.attr_timeout); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 964 | } else |
| 965 | reply_err(req, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 968 | static int do_chmod(struct fuse *f, fuse_req_t req, const char *path, |
| 969 | struct stat *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 970 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 971 | int err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 972 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 973 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 974 | if (f->op.chmod) { |
| 975 | struct fuse_intr_data d; |
| 976 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 977 | err = f->op.chmod(path, attr->st_mode); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 978 | fuse_finish_interrupt(f, req, &d); |
| 979 | } |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 980 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 981 | return err; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 982 | } |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 983 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 984 | static int do_chown(struct fuse *f, fuse_req_t req, const char *path, |
| 985 | struct stat *attr, int valid) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 986 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 987 | int err; |
| 988 | uid_t uid = (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : (uid_t) -1; |
| 989 | gid_t gid = (valid & FUSE_SET_ATTR_GID) ? attr->st_gid : (gid_t) -1; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 990 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 991 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 992 | if (f->op.chown) { |
| 993 | struct fuse_intr_data d; |
| 994 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 995 | err = f->op.chown(path, uid, gid); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 996 | fuse_finish_interrupt(f, req, &d); |
| 997 | } |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 998 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 999 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1002 | static int do_truncate(struct fuse *f, fuse_req_t req, const char *path, |
| 1003 | struct stat *attr, struct fuse_file_info *fi) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1004 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1005 | int err; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1006 | struct fuse_intr_data d; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1007 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1008 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1009 | if (fi && f->op.ftruncate) { |
| 1010 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 11509ce | 2005-10-26 16:04:04 +0000 | [diff] [blame] | 1011 | err = f->op.ftruncate(path, attr->st_size, fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1012 | fuse_finish_interrupt(f, req, &d); |
| 1013 | } else if (f->op.truncate) { |
| 1014 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1015 | err = f->op.truncate(path, attr->st_size); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1016 | fuse_finish_interrupt(f, req, &d); |
| 1017 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1018 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1021 | static int do_utimens(struct fuse *f, fuse_req_t req, const char *path, |
| 1022 | struct stat *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1023 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1024 | int err; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1025 | struct fuse_intr_data d; |
Miklos Szeredi | fa44077 | 2006-09-02 09:51:08 +0000 | [diff] [blame] | 1026 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1027 | err = -ENOSYS; |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1028 | if (f->op.utimens) { |
Miklos Szeredi | fa44077 | 2006-09-02 09:51:08 +0000 | [diff] [blame] | 1029 | struct timespec tv[2]; |
Csaba Henk | 3e3a125 | 2006-09-24 14:53:29 +0000 | [diff] [blame] | 1030 | #ifdef FUSE_STAT_HAS_NANOSEC |
| 1031 | tv[0] = ST_ATIM(attr); |
| 1032 | tv[1] = ST_MTIM(attr); |
| 1033 | #else |
| 1034 | tv[0].tv_sec = attr->st_atime; |
| 1035 | tv[0].tv_nsec = 0; |
| 1036 | tv[1].tv_sec = attr->st_mtime; |
| 1037 | tv[1].tv_nsec = 0; |
| 1038 | #endif |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1039 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1040 | err = f->op.utimens(path, tv); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1041 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | fa44077 | 2006-09-02 09:51:08 +0000 | [diff] [blame] | 1042 | } else if (f->op.utime) { |
| 1043 | struct utimbuf buf; |
| 1044 | buf.actime = attr->st_atime; |
| 1045 | buf.modtime = attr->st_mtime; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1046 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1047 | err = f->op.utime(path, &buf); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1048 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | fa44077 | 2006-09-02 09:51:08 +0000 | [diff] [blame] | 1049 | } |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1050 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1051 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1054 | static void fuse_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr, |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 1055 | int valid, struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1056 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1057 | struct fuse *f = req_fuse_prepare(req); |
| 1058 | struct stat buf; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1059 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1060 | int err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1061 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1062 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1063 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1064 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1065 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1066 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1067 | if (f->op.getattr) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1068 | err = 0; |
| 1069 | if (!err && (valid & FUSE_SET_ATTR_MODE)) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1070 | err = do_chmod(f, req, path, attr); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1071 | if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1072 | err = do_chown(f, req, path, attr, valid); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1073 | if (!err && (valid & FUSE_SET_ATTR_SIZE)) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1074 | err = do_truncate(f, req, path, attr, fi); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1075 | if (!err && (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) == (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1076 | err = do_utimens(f, req, path, attr); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1077 | if (!err) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1078 | err = fuse_do_getattr(f, req, path, &buf); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1079 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1080 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1081 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1082 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1083 | if (!err) { |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1084 | if (f->conf.auto_cache) { |
| 1085 | pthread_mutex_lock(&f->lock); |
| 1086 | update_stat(get_node(f, ino), &buf); |
| 1087 | pthread_mutex_unlock(&f->lock); |
| 1088 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1089 | set_stat(f, ino, &buf); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1090 | fuse_reply_attr(req, &buf, f->conf.attr_timeout); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1091 | } else |
| 1092 | reply_err(req, err); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 1095 | static void fuse_access(fuse_req_t req, fuse_ino_t ino, int mask) |
| 1096 | { |
| 1097 | struct fuse *f = req_fuse_prepare(req); |
| 1098 | char *path; |
| 1099 | int err; |
| 1100 | |
| 1101 | err = -ENOENT; |
| 1102 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1103 | path = get_path(f, ino); |
| 1104 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1105 | if (f->conf.debug) { |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 1106 | printf("ACCESS %s 0%o\n", path, mask); |
| 1107 | fflush(stdout); |
| 1108 | } |
| 1109 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1110 | if (f->op.access) { |
| 1111 | struct fuse_intr_data d; |
| 1112 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 1113 | err = f->op.access(path, mask); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1114 | fuse_finish_interrupt(f, req, &d); |
| 1115 | } |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 1116 | free(path); |
| 1117 | } |
| 1118 | pthread_rwlock_unlock(&f->tree_lock); |
| 1119 | reply_err(req, err); |
| 1120 | } |
| 1121 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1122 | static void fuse_readlink(fuse_req_t req, fuse_ino_t ino) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1123 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1124 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1125 | char linkname[PATH_MAX + 1]; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1126 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1127 | int err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1128 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1129 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1130 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1131 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1132 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1133 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1134 | if (f->op.readlink) { |
| 1135 | struct fuse_intr_data d; |
| 1136 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1137 | err = f->op.readlink(path, linkname, sizeof(linkname)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1138 | fuse_finish_interrupt(f, req, &d); |
| 1139 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1140 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1141 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1142 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1143 | if (!err) { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1144 | linkname[PATH_MAX] = '\0'; |
| 1145 | fuse_reply_readlink(req, linkname); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1146 | } else |
| 1147 | reply_err(req, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1150 | static void fuse_mknod(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 1151 | mode_t mode, dev_t rdev) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1152 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1153 | struct fuse *f = req_fuse_prepare(req); |
| 1154 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1155 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1156 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1157 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1158 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1159 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1160 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1161 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1162 | if (f->conf.debug) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1163 | printf("MKNOD %s\n", path); |
| 1164 | fflush(stdout); |
| 1165 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1166 | err = -ENOSYS; |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 1167 | if (S_ISREG(mode) && f->op.create && f->op.getattr) { |
| 1168 | struct fuse_file_info fi; |
| 1169 | |
| 1170 | memset(&fi, 0, sizeof(fi)); |
| 1171 | fi.flags = O_CREAT | O_EXCL | O_WRONLY; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1172 | err = fuse_do_create(f, req, path, mode, &fi); |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 1173 | if (!err) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1174 | err = lookup_path(f, req, parent, name, path, &e, &fi); |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 1175 | if (f->op.release) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1176 | fuse_do_release(f, req, path, &fi); |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 1177 | } |
| 1178 | } else if (f->op.mknod && f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1179 | struct fuse_intr_data d; |
| 1180 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1181 | err = f->op.mknod(path, mode, rdev); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1182 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1183 | if (!err) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1184 | err = lookup_path(f, req, parent, name, path, &e, NULL); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1185 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1186 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1187 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1188 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1189 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1192 | static void fuse_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 1193 | mode_t mode) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1194 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1195 | struct fuse *f = req_fuse_prepare(req); |
| 1196 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1197 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1198 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1199 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1200 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1201 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1202 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1203 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1204 | if (f->conf.debug) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1205 | printf("MKDIR %s\n", path); |
| 1206 | fflush(stdout); |
| 1207 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1208 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1209 | if (f->op.mkdir && f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1210 | struct fuse_intr_data d; |
| 1211 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1212 | err = f->op.mkdir(path, mode); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1213 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1214 | if (!err) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1215 | err = lookup_path(f, req, parent, name, path, &e, NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1216 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1217 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1218 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1219 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1220 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1223 | static void fuse_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1224 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1225 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1226 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1227 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1228 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1229 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1230 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1231 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1232 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1233 | if (f->conf.debug) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1234 | printf("UNLINK %s\n", path); |
| 1235 | fflush(stdout); |
| 1236 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1237 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1238 | if (f->op.unlink) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1239 | if (!f->conf.hard_remove && is_open(f, parent, name)) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1240 | err = hide_node(f, req, path, parent, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1241 | else { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1242 | err = fuse_do_unlink(f, req, path); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1243 | if (!err) |
| 1244 | remove_node(f, parent, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1245 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1246 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1247 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1248 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1249 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1250 | reply_err(req, err); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1253 | static void fuse_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1254 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1255 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1256 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1257 | int err; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1258 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1259 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1260 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1261 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1262 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1263 | if (f->conf.debug) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1264 | printf("RMDIR %s\n", path); |
| 1265 | fflush(stdout); |
| 1266 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1267 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1268 | if (f->op.rmdir) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1269 | struct fuse_intr_data d; |
| 1270 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1271 | err = f->op.rmdir(path); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1272 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1273 | if (!err) |
| 1274 | remove_node(f, parent, name); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1275 | } |
| 1276 | free(path); |
| 1277 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1278 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1279 | reply_err(req, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1282 | static void fuse_symlink(fuse_req_t req, const char *linkname, |
| 1283 | fuse_ino_t parent, const char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1284 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1285 | struct fuse *f = req_fuse_prepare(req); |
| 1286 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1287 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1288 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1289 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1290 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1291 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1292 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1293 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1294 | if (f->conf.debug) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1295 | printf("SYMLINK %s\n", path); |
| 1296 | fflush(stdout); |
| 1297 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1298 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1299 | if (f->op.symlink && f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1300 | struct fuse_intr_data d; |
| 1301 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1302 | err = f->op.symlink(linkname, path); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1303 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1304 | if (!err) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1305 | err = lookup_path(f, req, parent, name, path, &e, NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1306 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1307 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1308 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1309 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1310 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1313 | static void fuse_rename(fuse_req_t req, fuse_ino_t olddir, const char *oldname, |
| 1314 | fuse_ino_t newdir, const char *newname) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1315 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1316 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1317 | char *oldpath; |
| 1318 | char *newpath; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1319 | int err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1320 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1321 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1322 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1323 | oldpath = get_path_name(f, olddir, oldname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1324 | if (oldpath != NULL) { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1325 | newpath = get_path_name(f, newdir, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1326 | if (newpath != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1327 | if (f->conf.debug) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1328 | printf("RENAME %s -> %s\n", oldpath, newpath); |
| 1329 | fflush(stdout); |
| 1330 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1331 | err = -ENOSYS; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1332 | if (f->op.rename) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1333 | err = 0; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1334 | if (!f->conf.hard_remove && |
Miklos Szeredi | 2529ca2 | 2004-07-13 15:36:52 +0000 | [diff] [blame] | 1335 | is_open(f, newdir, newname)) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1336 | err = hide_node(f, req, newpath, newdir, newname); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1337 | if (!err) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1338 | fuse_do_rename(f, req, oldpath, newpath); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1339 | if (!err) |
| 1340 | err = rename_node(f, olddir, oldname, newdir, newname, 0); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1341 | } |
| 1342 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1343 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1344 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1345 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1346 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1347 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1348 | reply_err(req, err); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1351 | static void fuse_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, |
| 1352 | const char *newname) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1353 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1354 | struct fuse *f = req_fuse_prepare(req); |
| 1355 | struct fuse_entry_param e; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1356 | char *oldpath; |
| 1357 | char *newpath; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1358 | int err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1359 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1360 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1361 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1362 | oldpath = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1363 | if (oldpath != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1364 | newpath = get_path_name(f, newparent, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1365 | if (newpath != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1366 | if (f->conf.debug) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1367 | printf("LINK %s\n", newpath); |
| 1368 | fflush(stdout); |
| 1369 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1370 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1371 | if (f->op.link && f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1372 | struct fuse_intr_data d; |
| 1373 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1374 | err = f->op.link(oldpath, newpath); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1375 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1376 | if (!err) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1377 | err = lookup_path(f, req, newparent, newname, newpath, &e, |
| 1378 | NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1379 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1380 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1381 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1382 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1383 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1384 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1385 | reply_entry(req, &e, err); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1388 | static void fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 1389 | mode_t mode, struct fuse_file_info *fi) |
| 1390 | { |
| 1391 | struct fuse *f = req_fuse_prepare(req); |
| 1392 | struct fuse_entry_param e; |
| 1393 | char *path; |
| 1394 | int err; |
| 1395 | |
| 1396 | err = -ENOENT; |
| 1397 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1398 | path = get_path_name(f, parent, name); |
| 1399 | if (path != NULL) { |
| 1400 | err = -ENOSYS; |
| 1401 | if (f->op.create && f->op.getattr) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1402 | err = fuse_do_create(f, req, path, mode, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1403 | if (!err) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1404 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1405 | printf("CREATE[%llu] flags: 0x%x %s\n", |
| 1406 | (unsigned long long) fi->fh, fi->flags, path); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1407 | fflush(stdout); |
| 1408 | } |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1409 | err = lookup_path(f, req, parent, name, path, &e, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1410 | if (err) { |
| 1411 | if (f->op.release) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1412 | fuse_do_release(f, req, path, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1413 | } else if (!S_ISREG(e.attr.st_mode)) { |
| 1414 | err = -EIO; |
| 1415 | if (f->op.release) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1416 | fuse_do_release(f, req, path, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1417 | forget_node(f, e.ino, 1); |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | if (!err) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1424 | if (f->conf.direct_io) |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1425 | fi->direct_io = 1; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1426 | if (f->conf.kernel_cache) |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1427 | fi->keep_cache = 1; |
| 1428 | |
| 1429 | pthread_mutex_lock(&f->lock); |
| 1430 | if (fuse_reply_create(req, &e, fi) == -ENOENT) { |
| 1431 | /* The open syscall was interrupted, so it must be cancelled */ |
| 1432 | if(f->op.release) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1433 | fuse_do_release(f, req, path, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1434 | forget_node(f, e.ino, 1); |
| 1435 | } else { |
| 1436 | struct node *node = get_node(f, e.ino); |
| 1437 | node->open_count ++; |
| 1438 | } |
| 1439 | pthread_mutex_unlock(&f->lock); |
| 1440 | } else |
| 1441 | reply_err(req, err); |
| 1442 | |
| 1443 | if (path) |
| 1444 | free(path); |
| 1445 | pthread_rwlock_unlock(&f->tree_lock); |
| 1446 | } |
| 1447 | |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1448 | static double diff_timespec(const struct timespec *t1, |
| 1449 | const struct timespec *t2) |
| 1450 | { |
| 1451 | return (t1->tv_sec - t2->tv_sec) + |
| 1452 | ((double) t1->tv_nsec - (double) t2->tv_nsec) / 1000000000.0; |
| 1453 | } |
| 1454 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1455 | static void open_auto_cache(struct fuse *f, fuse_req_t req, fuse_ino_t ino, |
| 1456 | const char *path, struct fuse_file_info *fi) |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1457 | { |
| 1458 | struct node *node = get_node(f, ino); |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1459 | if (node->cache_valid) { |
| 1460 | struct timespec now; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1461 | |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1462 | curr_time(&now); |
Miklos Szeredi | 6e806e9 | 2006-02-16 16:59:39 +0000 | [diff] [blame] | 1463 | if (diff_timespec(&now, &node->stat_updated) > f->conf.ac_attr_timeout) { |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1464 | struct stat stbuf; |
| 1465 | int err; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1466 | |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1467 | if (f->op.fgetattr) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1468 | err = fuse_do_fgetattr(f, req, path, &stbuf, fi); |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1469 | else |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1470 | err = fuse_do_getattr(f, req, path, &stbuf); |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (!err) |
| 1473 | update_stat(node, &stbuf); |
| 1474 | else |
| 1475 | node->cache_valid = 0; |
| 1476 | } |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1477 | } |
| 1478 | if (node->cache_valid) |
| 1479 | fi->keep_cache = 1; |
Miklos Szeredi | 08dab16 | 2006-02-01 13:39:15 +0000 | [diff] [blame] | 1480 | |
| 1481 | node->cache_valid = 1; |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1484 | static void fuse_open(fuse_req_t req, fuse_ino_t ino, |
| 1485 | struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1486 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1487 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 31066bb | 2005-08-01 14:49:31 +0000 | [diff] [blame] | 1488 | char *path = NULL; |
| 1489 | int err = 0; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1490 | |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1491 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | 31066bb | 2005-08-01 14:49:31 +0000 | [diff] [blame] | 1492 | if (f->op.open) { |
| 1493 | err = -ENOENT; |
| 1494 | path = get_path(f, ino); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1495 | if (path != NULL) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1496 | err = fuse_compat_open(f, req, path, fi); |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 1497 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1498 | if (!err) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1499 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1500 | printf("OPEN[%llu] flags: 0x%x\n", (unsigned long long) fi->fh, |
| 1501 | fi->flags); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1502 | fflush(stdout); |
| 1503 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1504 | |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1505 | if (f->conf.direct_io) |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 1506 | fi->direct_io = 1; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1507 | if (f->conf.kernel_cache) |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 1508 | fi->keep_cache = 1; |
| 1509 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1510 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1511 | if (f->conf.auto_cache) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1512 | open_auto_cache(f, req, ino, path, fi); |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 1513 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1514 | if (fuse_reply_open(req, fi) == -ENOENT) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1515 | /* The open syscall was interrupted, so it must be cancelled */ |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1516 | if(f->op.release && path != NULL) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1517 | fuse_compat_release(f, req, path, fi); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1518 | } else { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1519 | struct node *node = get_node(f, ino); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1520 | node->open_count ++; |
| 1521 | } |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1522 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1523 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1524 | reply_err(req, err); |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1525 | |
Miklos Szeredi | 9a31cca | 2004-06-26 21:11:25 +0000 | [diff] [blame] | 1526 | if (path) |
| 1527 | free(path); |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1528 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1531 | static void fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, |
| 1532 | struct fuse_file_info *fi) |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1533 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1534 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1535 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1536 | char *buf; |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1537 | int res; |
| 1538 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1539 | buf = (char *) malloc(size); |
| 1540 | if (buf == NULL) { |
| 1541 | reply_err(req, -ENOMEM); |
| 1542 | return; |
| 1543 | } |
| 1544 | |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1545 | res = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1546 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1547 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1548 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1549 | if (f->conf.debug) { |
Miklos Szeredi | a039f8f | 2006-02-24 16:21:58 +0000 | [diff] [blame] | 1550 | printf("READ[%llu] %lu bytes from %llu\n", |
| 1551 | (unsigned long long) fi->fh, (unsigned long) size, |
| 1552 | (unsigned long long) off); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1553 | fflush(stdout); |
| 1554 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1555 | |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1556 | res = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1557 | if (f->op.read) { |
| 1558 | struct fuse_intr_data d; |
| 1559 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1560 | res = f->op.read(path, buf, size, off, fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1561 | fuse_finish_interrupt(f, req, &d); |
| 1562 | } |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1563 | free(path); |
| 1564 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1565 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1566 | |
| 1567 | if (res >= 0) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1568 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1569 | printf(" READ[%llu] %u bytes\n", (unsigned long long) fi->fh, |
| 1570 | res); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1571 | fflush(stdout); |
| 1572 | } |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1573 | if ((size_t) res > size) |
| 1574 | fprintf(stderr, "fuse: read too many bytes"); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1575 | fuse_reply_buf(req, buf, res); |
| 1576 | } else |
| 1577 | reply_err(req, res); |
| 1578 | |
| 1579 | free(buf); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1582 | static void fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf, |
| 1583 | size_t size, off_t off, struct fuse_file_info *fi) |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1584 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1585 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1586 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1587 | int res; |
| 1588 | |
| 1589 | res = -ENOENT; |
| 1590 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1591 | path = get_path(f, ino); |
| 1592 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1593 | if (f->conf.debug) { |
Miklos Szeredi | a039f8f | 2006-02-24 16:21:58 +0000 | [diff] [blame] | 1594 | printf("WRITE%s[%llu] %lu bytes to %llu\n", |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1595 | fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, |
Miklos Szeredi | a039f8f | 2006-02-24 16:21:58 +0000 | [diff] [blame] | 1596 | (unsigned long) size, (unsigned long long) off); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1597 | fflush(stdout); |
| 1598 | } |
| 1599 | |
| 1600 | res = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1601 | if (f->op.write) { |
| 1602 | struct fuse_intr_data d; |
| 1603 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1604 | res = f->op.write(path, buf, size, off, fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1605 | fuse_finish_interrupt(f, req, &d); |
| 1606 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1607 | free(path); |
| 1608 | } |
| 1609 | pthread_rwlock_unlock(&f->tree_lock); |
| 1610 | |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1611 | if (res >= 0) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1612 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1613 | printf(" WRITE%s[%llu] %u bytes\n", |
| 1614 | fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, |
| 1615 | res); |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1616 | fflush(stdout); |
| 1617 | } |
| 1618 | if ((size_t) res > size) |
| 1619 | fprintf(stderr, "fuse: wrote too many bytes"); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1620 | fuse_reply_write(req, res); |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1621 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1622 | reply_err(req, res); |
| 1623 | } |
| 1624 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1625 | static void fuse_release(fuse_req_t req, fuse_ino_t ino, |
| 1626 | struct fuse_file_info *fi) |
| 1627 | { |
| 1628 | struct fuse *f = req_fuse_prepare(req); |
| 1629 | char *path; |
| 1630 | struct node *node; |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1631 | int unlink_hidden = 0; |
Miklos Szeredi | fb28c5e | 2004-11-26 12:15:06 +0000 | [diff] [blame] | 1632 | |
Miklos Szeredi | aa8258e | 2006-02-25 14:42:03 +0000 | [diff] [blame] | 1633 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1634 | path = get_path(f, ino); |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1635 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1636 | printf("RELEASE[%llu] flags: 0x%x\n", (unsigned long long) fi->fh, |
| 1637 | fi->flags); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1638 | fflush(stdout); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1639 | } |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1640 | if (f->op.release) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1641 | fuse_compat_release(f, req, path, fi); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1642 | |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 1643 | pthread_mutex_lock(&f->lock); |
| 1644 | node = get_node(f, ino); |
| 1645 | assert(node->open_count > 0); |
| 1646 | --node->open_count; |
Miklos Szeredi | c3b7681 | 2006-09-16 08:52:09 +0000 | [diff] [blame] | 1647 | if (node->is_hidden && !node->open_count) { |
| 1648 | unlink_hidden = 1; |
| 1649 | node->is_hidden = 0; |
| 1650 | } |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 1651 | pthread_mutex_unlock(&f->lock); |
| 1652 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1653 | if(unlink_hidden && path) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1654 | fuse_do_unlink(f, req, path); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1655 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1656 | if (path) |
| 1657 | free(path); |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1658 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1659 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1660 | reply_err(req, 0); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1663 | static void fuse_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, |
| 1664 | struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1665 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1666 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1667 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1668 | int err; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1669 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1670 | err = -ENOENT; |
| 1671 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1672 | path = get_path(f, ino); |
| 1673 | if (path != NULL) { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1674 | if (f->conf.debug) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1675 | printf("FSYNC[%llu]\n", (unsigned long long) fi->fh); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1676 | fflush(stdout); |
| 1677 | } |
| 1678 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1679 | if (f->op.fsync) { |
| 1680 | struct fuse_intr_data d; |
| 1681 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1682 | err = f->op.fsync(path, datasync, fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1683 | fuse_finish_interrupt(f, req, &d); |
| 1684 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1685 | free(path); |
| 1686 | } |
| 1687 | pthread_rwlock_unlock(&f->tree_lock); |
| 1688 | reply_err(req, err); |
| 1689 | } |
| 1690 | |
| 1691 | static struct fuse_dirhandle *get_dirhandle(const struct fuse_file_info *llfi, |
| 1692 | struct fuse_file_info *fi) |
| 1693 | { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1694 | struct fuse_dirhandle *dh = (struct fuse_dirhandle *) (uintptr_t) llfi->fh; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1695 | memset(fi, 0, sizeof(struct fuse_file_info)); |
| 1696 | fi->fh = dh->fh; |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 1697 | fi->fh_old = dh->fh; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1698 | return dh; |
| 1699 | } |
| 1700 | |
| 1701 | static void fuse_opendir(fuse_req_t req, fuse_ino_t ino, |
| 1702 | struct fuse_file_info *llfi) |
| 1703 | { |
| 1704 | struct fuse *f = req_fuse_prepare(req); |
| 1705 | struct fuse_dirhandle *dh; |
| 1706 | |
| 1707 | dh = (struct fuse_dirhandle *) malloc(sizeof(struct fuse_dirhandle)); |
| 1708 | if (dh == NULL) { |
| 1709 | reply_err(req, -ENOMEM); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1710 | return; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1711 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1712 | memset(dh, 0, sizeof(struct fuse_dirhandle)); |
| 1713 | dh->fuse = f; |
| 1714 | dh->contents = NULL; |
| 1715 | dh->len = 0; |
| 1716 | dh->filled = 0; |
| 1717 | dh->nodeid = ino; |
Miklos Szeredi | 38f152c | 2006-09-03 18:28:52 +0000 | [diff] [blame] | 1718 | fuse_mutex_init(&dh->lock); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1719 | |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1720 | llfi->fh = (uintptr_t) dh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1721 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1722 | if (f->op.opendir) { |
| 1723 | struct fuse_file_info fi; |
| 1724 | char *path; |
| 1725 | int err; |
| 1726 | |
| 1727 | memset(&fi, 0, sizeof(fi)); |
| 1728 | fi.flags = llfi->flags; |
| 1729 | |
| 1730 | err = -ENOENT; |
| 1731 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1732 | path = get_path(f, ino); |
| 1733 | if (path != NULL) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1734 | err = fuse_compat_opendir(f, req, path, &fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1735 | dh->fh = fi.fh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1736 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1737 | if (!err) { |
| 1738 | pthread_mutex_lock(&f->lock); |
| 1739 | if (fuse_reply_open(req, llfi) == -ENOENT) { |
| 1740 | /* The opendir syscall was interrupted, so it must be |
| 1741 | cancelled */ |
| 1742 | if(f->op.releasedir) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1743 | fuse_do_releasedir(f, req, path, &fi); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1744 | pthread_mutex_destroy(&dh->lock); |
| 1745 | free(dh); |
| 1746 | } |
| 1747 | pthread_mutex_unlock(&f->lock); |
| 1748 | } else { |
| 1749 | reply_err(req, err); |
| 1750 | free(dh); |
| 1751 | } |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1752 | free(path); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1753 | pthread_rwlock_unlock(&f->tree_lock); |
| 1754 | } else |
| 1755 | fuse_reply_open(req, llfi); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1756 | } |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1757 | |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1758 | static int extend_contents(struct fuse_dirhandle *dh, unsigned minsize) |
| 1759 | { |
| 1760 | if (minsize > dh->size) { |
| 1761 | char *newptr; |
| 1762 | unsigned newsize = dh->size; |
| 1763 | if (!newsize) |
| 1764 | newsize = 1024; |
| 1765 | while (newsize < minsize) |
| 1766 | newsize *= 2; |
| 1767 | |
| 1768 | newptr = (char *) realloc(dh->contents, newsize); |
| 1769 | if (!newptr) { |
| 1770 | dh->error = -ENOMEM; |
| 1771 | return -1; |
| 1772 | } |
| 1773 | dh->contents = newptr; |
| 1774 | dh->size = newsize; |
| 1775 | } |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1779 | static int fill_dir_common(struct fuse_dirhandle *dh, const char *name, |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1780 | const struct stat *statp, off_t off) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1781 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1782 | struct stat stbuf; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1783 | size_t newlen; |
Miklos Szeredi | fb28c5e | 2004-11-26 12:15:06 +0000 | [diff] [blame] | 1784 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1785 | if (statp) |
| 1786 | stbuf = *statp; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1787 | else { |
| 1788 | memset(&stbuf, 0, sizeof(stbuf)); |
Miklos Szeredi | e248e4b | 2005-12-14 16:18:32 +0000 | [diff] [blame] | 1789 | stbuf.st_ino = FUSE_UNKNOWN_INO; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1790 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1791 | |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1792 | if (!dh->fuse->conf.use_ino) { |
Miklos Szeredi | e248e4b | 2005-12-14 16:18:32 +0000 | [diff] [blame] | 1793 | stbuf.st_ino = FUSE_UNKNOWN_INO; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 1794 | if (dh->fuse->conf.readdir_ino) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1795 | struct node *node; |
| 1796 | pthread_mutex_lock(&dh->fuse->lock); |
| 1797 | node = lookup_node(dh->fuse, dh->nodeid, name); |
| 1798 | if (node) |
| 1799 | stbuf.st_ino = (ino_t) node->nodeid; |
| 1800 | pthread_mutex_unlock(&dh->fuse->lock); |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1801 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1802 | } |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1803 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1804 | if (off) { |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1805 | if (extend_contents(dh, dh->needlen) == -1) |
| 1806 | return 1; |
| 1807 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1808 | dh->filled = 0; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1809 | newlen = dh->len + fuse_add_direntry(dh->req, dh->contents + dh->len, |
| 1810 | dh->needlen - dh->len, name, |
| 1811 | &stbuf, off); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1812 | if (newlen > dh->needlen) |
| 1813 | return 1; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1814 | } else { |
| 1815 | newlen = dh->len + fuse_add_direntry(dh->req, NULL, 0, name, NULL, 0); |
| 1816 | if (extend_contents(dh, newlen) == -1) |
Miklos Szeredi | c4c12ae | 2005-10-20 14:48:50 +0000 | [diff] [blame] | 1817 | return 1; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1818 | |
| 1819 | fuse_add_direntry(dh->req, dh->contents + dh->len, dh->size - dh->len, |
| 1820 | name, &stbuf, newlen); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1821 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1822 | dh->len = newlen; |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1826 | static int fill_dir(void *buf, const char *name, const struct stat *stbuf, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1827 | off_t off) |
| 1828 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1829 | return fill_dir_common((struct fuse_dirhandle *) buf, name, stbuf, off); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | static int fill_dir_old(struct fuse_dirhandle *dh, const char *name, int type, |
| 1833 | ino_t ino) |
| 1834 | { |
| 1835 | struct stat stbuf; |
| 1836 | |
| 1837 | memset(&stbuf, 0, sizeof(stbuf)); |
| 1838 | stbuf.st_mode = type << 12; |
| 1839 | stbuf.st_ino = ino; |
| 1840 | |
| 1841 | fill_dir_common(dh, name, &stbuf, 0); |
| 1842 | return dh->error; |
| 1843 | } |
| 1844 | |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1845 | static int readdir_fill(struct fuse *f, fuse_req_t req, fuse_ino_t ino, |
| 1846 | size_t size, off_t off, struct fuse_dirhandle *dh, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1847 | struct fuse_file_info *fi) |
| 1848 | { |
| 1849 | int err = -ENOENT; |
| 1850 | char *path; |
| 1851 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1852 | path = get_path(f, ino); |
| 1853 | if (path != NULL) { |
| 1854 | dh->len = 0; |
| 1855 | dh->error = 0; |
| 1856 | dh->needlen = size; |
| 1857 | dh->filled = 1; |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1858 | dh->req = req; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1859 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1860 | if (f->op.readdir) { |
| 1861 | struct fuse_intr_data d; |
| 1862 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1863 | err = f->op.readdir(path, dh, fill_dir, off, fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1864 | fuse_finish_interrupt(f, req, &d); |
| 1865 | } else if (f->op.getdir) { |
| 1866 | struct fuse_intr_data d; |
| 1867 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1868 | err = f->op.getdir(path, dh, fill_dir_old); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1869 | fuse_finish_interrupt(f, req, &d); |
| 1870 | } |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1871 | dh->req = NULL; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1872 | if (!err) |
| 1873 | err = dh->error; |
| 1874 | if (err) |
| 1875 | dh->filled = 0; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1876 | free(path); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1877 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1878 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1879 | return err; |
| 1880 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1881 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1882 | static void fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, |
| 1883 | off_t off, struct fuse_file_info *llfi) |
| 1884 | { |
| 1885 | struct fuse *f = req_fuse_prepare(req); |
| 1886 | struct fuse_file_info fi; |
| 1887 | struct fuse_dirhandle *dh = get_dirhandle(llfi, &fi); |
| 1888 | |
| 1889 | pthread_mutex_lock(&dh->lock); |
Miklos Szeredi | 77ccf65 | 2005-08-19 14:40:27 +0000 | [diff] [blame] | 1890 | /* According to SUS, directory contents need to be refreshed on |
| 1891 | rewinddir() */ |
| 1892 | if (!off) |
| 1893 | dh->filled = 0; |
| 1894 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1895 | if (!dh->filled) { |
Miklos Szeredi | 1bf64f4 | 2006-02-17 15:49:25 +0000 | [diff] [blame] | 1896 | int err = readdir_fill(f, req, ino, size, off, dh, &fi); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1897 | if (err) { |
| 1898 | reply_err(req, err); |
| 1899 | goto out; |
| 1900 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1901 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1902 | if (dh->filled) { |
| 1903 | if (off < dh->len) { |
| 1904 | if (off + size > dh->len) |
| 1905 | size = dh->len - off; |
| 1906 | } else |
| 1907 | size = 0; |
| 1908 | } else { |
| 1909 | size = dh->len; |
| 1910 | off = 0; |
| 1911 | } |
| 1912 | fuse_reply_buf(req, dh->contents + off, size); |
| 1913 | out: |
| 1914 | pthread_mutex_unlock(&dh->lock); |
| 1915 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1916 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1917 | static void fuse_releasedir(fuse_req_t req, fuse_ino_t ino, |
| 1918 | struct fuse_file_info *llfi) |
| 1919 | { |
| 1920 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 1921 | struct fuse_file_info fi; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1922 | struct fuse_dirhandle *dh = get_dirhandle(llfi, &fi); |
| 1923 | if (f->op.releasedir) { |
| 1924 | char *path; |
| 1925 | |
| 1926 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1927 | path = get_path(f, ino); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1928 | fuse_do_releasedir(f, req, path ? path : "-", &fi); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1929 | free(path); |
| 1930 | pthread_rwlock_unlock(&f->tree_lock); |
| 1931 | } |
| 1932 | pthread_mutex_lock(&dh->lock); |
| 1933 | pthread_mutex_unlock(&dh->lock); |
| 1934 | pthread_mutex_destroy(&dh->lock); |
| 1935 | free(dh->contents); |
| 1936 | free(dh); |
| 1937 | reply_err(req, 0); |
| 1938 | } |
| 1939 | |
| 1940 | static void fuse_fsyncdir(fuse_req_t req, fuse_ino_t ino, int datasync, |
| 1941 | struct fuse_file_info *llfi) |
| 1942 | { |
| 1943 | struct fuse *f = req_fuse_prepare(req); |
| 1944 | struct fuse_file_info fi; |
| 1945 | char *path; |
| 1946 | int err; |
| 1947 | |
| 1948 | get_dirhandle(llfi, &fi); |
| 1949 | |
| 1950 | err = -ENOENT; |
| 1951 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1952 | path = get_path(f, ino); |
| 1953 | if (path != NULL) { |
| 1954 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1955 | if (f->op.fsyncdir) { |
| 1956 | struct fuse_intr_data d; |
| 1957 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1958 | err = f->op.fsyncdir(path, datasync, &fi); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1959 | fuse_finish_interrupt(f, req, &d); |
| 1960 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1961 | free(path); |
| 1962 | } |
| 1963 | pthread_rwlock_unlock(&f->tree_lock); |
| 1964 | reply_err(req, err); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1967 | static int default_statfs(struct statvfs *buf) |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1968 | { |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1969 | buf->f_namemax = 255; |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1970 | buf->f_bsize = 512; |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
Miklos Szeredi | 3ded1a3 | 2006-08-18 18:43:50 +0000 | [diff] [blame] | 1974 | static void fuse_statfs(fuse_req_t req, fuse_ino_t ino) |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 1975 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1976 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1977 | struct statvfs buf; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1978 | int err; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1979 | |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1980 | memset(&buf, 0, sizeof(buf)); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1981 | if (f->op.statfs) { |
Miklos Szeredi | 3ded1a3 | 2006-08-18 18:43:50 +0000 | [diff] [blame] | 1982 | if (ino && (!f->compat || f->compat >= 26)) { |
| 1983 | char *path; |
| 1984 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1985 | err = -ENOENT; |
| 1986 | path = get_path(f, ino); |
| 1987 | if (path) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1988 | err = fuse_do_statfs(f, req, path, &buf); |
Miklos Szeredi | 3ded1a3 | 2006-08-18 18:43:50 +0000 | [diff] [blame] | 1989 | free(path); |
| 1990 | } |
| 1991 | pthread_rwlock_unlock(&f->tree_lock); |
| 1992 | } else |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 1993 | err = fuse_compat_statfs(f, req, &buf); |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1994 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1995 | err = default_statfs(&buf); |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1996 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1997 | if (!err) |
| 1998 | fuse_reply_statfs(req, &buf); |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1999 | else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2000 | reply_err(req, err); |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2003 | static void fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, |
| 2004 | const char *value, size_t size, int flags) |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 2005 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2006 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 2007 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2008 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 2009 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2010 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 2011 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2012 | path = get_path(f, ino); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 2013 | if (path != NULL) { |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 2014 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2015 | if (f->op.setxattr) { |
| 2016 | struct fuse_intr_data d; |
| 2017 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2018 | err = f->op.setxattr(path, name, value, size, flags); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2019 | fuse_finish_interrupt(f, req, &d); |
| 2020 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2021 | free(path); |
| 2022 | } |
| 2023 | pthread_rwlock_unlock(&f->tree_lock); |
| 2024 | reply_err(req, err); |
| 2025 | } |
| 2026 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2027 | static int common_getxattr(struct fuse *f, fuse_req_t req, fuse_ino_t ino, |
| 2028 | const char *name, char *value, size_t size) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2029 | { |
| 2030 | int err; |
| 2031 | char *path; |
| 2032 | |
| 2033 | err = -ENOENT; |
| 2034 | pthread_rwlock_rdlock(&f->tree_lock); |
| 2035 | path = get_path(f, ino); |
| 2036 | if (path != NULL) { |
| 2037 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2038 | if (f->op.getxattr) { |
| 2039 | struct fuse_intr_data d; |
| 2040 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2041 | err = f->op.getxattr(path, name, value, size); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2042 | fuse_finish_interrupt(f, req, &d); |
| 2043 | } |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 2044 | free(path); |
| 2045 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 2046 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 2047 | return err; |
| 2048 | } |
| 2049 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2050 | static void fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, |
| 2051 | size_t size) |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 2052 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2053 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2054 | int res; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2055 | |
| 2056 | if (size) { |
| 2057 | char *value = (char *) malloc(size); |
| 2058 | if (value == NULL) { |
| 2059 | reply_err(req, -ENOMEM); |
| 2060 | return; |
| 2061 | } |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2062 | res = common_getxattr(f, req, ino, name, value, size); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2063 | if (res > 0) |
| 2064 | fuse_reply_buf(req, value, res); |
| 2065 | else |
| 2066 | reply_err(req, res); |
| 2067 | free(value); |
| 2068 | } else { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2069 | res = common_getxattr(f, req, ino, name, NULL, 0); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2070 | if (res >= 0) |
| 2071 | fuse_reply_xattr(req, res); |
| 2072 | else |
| 2073 | reply_err(req, res); |
| 2074 | } |
| 2075 | } |
| 2076 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2077 | static int common_listxattr(struct fuse *f, fuse_req_t req, fuse_ino_t ino, |
| 2078 | char *list, size_t size) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2079 | { |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2080 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2081 | int err; |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2082 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2083 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 2084 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2085 | path = get_path(f, ino); |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2086 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2087 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2088 | if (f->op.listxattr) { |
| 2089 | struct fuse_intr_data d; |
| 2090 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2091 | err = f->op.listxattr(path, list, size); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2092 | fuse_finish_interrupt(f, req, &d); |
| 2093 | } |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2094 | free(path); |
| 2095 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 2096 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2097 | return err; |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 2098 | } |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 2099 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2100 | static void fuse_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 2101 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2102 | struct fuse *f = req_fuse_prepare(req); |
| 2103 | int res; |
| 2104 | |
| 2105 | if (size) { |
| 2106 | char *list = (char *) malloc(size); |
| 2107 | if (list == NULL) { |
| 2108 | reply_err(req, -ENOMEM); |
| 2109 | return; |
| 2110 | } |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2111 | res = common_listxattr(f, req, ino, list, size); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2112 | if (res > 0) |
| 2113 | fuse_reply_buf(req, list, res); |
| 2114 | else |
| 2115 | reply_err(req, res); |
| 2116 | free(list); |
| 2117 | } else { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2118 | res = common_listxattr(f, req, ino, NULL, 0); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2119 | if (res >= 0) |
| 2120 | fuse_reply_xattr(req, res); |
| 2121 | else |
| 2122 | reply_err(req, res); |
| 2123 | } |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2126 | static void fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *name) |
| 2127 | { |
| 2128 | struct fuse *f = req_fuse_prepare(req); |
| 2129 | char *path; |
| 2130 | int err; |
| 2131 | |
| 2132 | err = -ENOENT; |
| 2133 | pthread_rwlock_rdlock(&f->tree_lock); |
| 2134 | path = get_path(f, ino); |
| 2135 | if (path != NULL) { |
| 2136 | err = -ENOSYS; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2137 | if (f->op.removexattr) { |
| 2138 | struct fuse_intr_data d; |
| 2139 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2140 | err = f->op.removexattr(path, name); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2141 | fuse_finish_interrupt(f, req, &d); |
| 2142 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2143 | free(path); |
| 2144 | } |
| 2145 | pthread_rwlock_unlock(&f->tree_lock); |
| 2146 | reply_err(req, err); |
| 2147 | } |
| 2148 | |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 2149 | static struct lock *locks_conflict(struct node *node, const struct lock *lock) |
| 2150 | { |
| 2151 | struct lock *l; |
| 2152 | |
| 2153 | for (l = node->locks; l; l = l->next) |
| 2154 | if (l->owner != lock->owner && |
| 2155 | lock->start <= l->end && l->start <= lock->end && |
| 2156 | (l->type == F_WRLCK || lock->type == F_WRLCK)) |
| 2157 | break; |
| 2158 | |
| 2159 | return l; |
| 2160 | } |
| 2161 | |
| 2162 | static void delete_lock(struct lock **lockp) |
| 2163 | { |
| 2164 | struct lock *l = *lockp; |
| 2165 | *lockp = l->next; |
| 2166 | free(l); |
| 2167 | } |
| 2168 | |
| 2169 | static void insert_lock(struct lock **pos, struct lock *lock) |
| 2170 | { |
| 2171 | lock->next = *pos; |
| 2172 | *pos = lock; |
| 2173 | } |
| 2174 | |
| 2175 | static int locks_insert(struct node *node, struct lock *lock) |
| 2176 | { |
| 2177 | struct lock **lp; |
| 2178 | struct lock *newl1 = NULL; |
| 2179 | struct lock *newl2 = NULL; |
| 2180 | |
| 2181 | if (lock->type != F_UNLCK || lock->start != 0 || lock->end != OFFSET_MAX) { |
| 2182 | newl1 = malloc(sizeof(struct lock)); |
| 2183 | newl2 = malloc(sizeof(struct lock)); |
| 2184 | |
| 2185 | if (!newl1 || !newl2) { |
| 2186 | free(newl1); |
| 2187 | free(newl2); |
| 2188 | return -ENOLCK; |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | for (lp = &node->locks; *lp;) { |
| 2193 | struct lock *l = *lp; |
| 2194 | if (l->owner != lock->owner) |
| 2195 | goto skip; |
| 2196 | |
| 2197 | if (lock->type == l->type) { |
| 2198 | if (l->end < lock->start - 1) |
| 2199 | goto skip; |
| 2200 | if (lock->end < l->start - 1) |
| 2201 | break; |
| 2202 | if (l->start <= lock->start && lock->end <= l->end) |
| 2203 | goto out; |
| 2204 | if (l->start < lock->start) |
| 2205 | lock->start = l->start; |
| 2206 | if (lock->end < l->end) |
| 2207 | lock->end = l->end; |
| 2208 | goto delete; |
| 2209 | } else { |
| 2210 | if (l->end < lock->start) |
| 2211 | goto skip; |
| 2212 | if (lock->end < l->start) |
| 2213 | break; |
| 2214 | if (lock->start <= l->start && l->end <= lock->end) |
| 2215 | goto delete; |
| 2216 | if (l->end <= lock->end) { |
| 2217 | l->end = lock->start - 1; |
| 2218 | goto skip; |
| 2219 | } |
| 2220 | if (lock->start <= l->start) { |
| 2221 | l->start = lock->end + 1; |
| 2222 | break; |
| 2223 | } |
| 2224 | *newl2 = *l; |
| 2225 | newl2->start = lock->end + 1; |
| 2226 | l->end = lock->start - 1; |
| 2227 | insert_lock(&l->next, newl2); |
| 2228 | newl2 = NULL; |
| 2229 | } |
| 2230 | skip: |
| 2231 | lp = &l->next; |
| 2232 | continue; |
| 2233 | |
| 2234 | delete: |
| 2235 | delete_lock(lp); |
| 2236 | } |
| 2237 | if (lock->type != F_UNLCK) { |
| 2238 | *newl1 = *lock; |
| 2239 | insert_lock(lp, newl1); |
| 2240 | newl1 = NULL; |
| 2241 | } |
| 2242 | out: |
| 2243 | free(newl1); |
| 2244 | free(newl2); |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
| 2248 | static void flock_to_lock(struct flock *flock, struct lock *lock) |
| 2249 | { |
| 2250 | memset(lock, 0, sizeof(struct lock)); |
| 2251 | lock->type = flock->l_type; |
| 2252 | lock->start = flock->l_start; |
| 2253 | lock->end = flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX; |
| 2254 | lock->pid = flock->l_pid; |
| 2255 | } |
| 2256 | |
| 2257 | static void lock_to_flock(struct lock *lock, struct flock *flock) |
| 2258 | { |
| 2259 | flock->l_type = lock->type; |
| 2260 | flock->l_start = lock->start; |
| 2261 | flock->l_len = (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1; |
| 2262 | flock->l_pid = lock->pid; |
| 2263 | } |
| 2264 | |
| 2265 | static void fuse_flush(fuse_req_t req, fuse_ino_t ino, |
| 2266 | struct fuse_file_info *fi, uint64_t owner) |
| 2267 | { |
| 2268 | struct fuse *f = req_fuse_prepare(req); |
| 2269 | char *path; |
| 2270 | int err; |
| 2271 | |
| 2272 | err = -ENOENT; |
| 2273 | pthread_rwlock_rdlock(&f->tree_lock); |
| 2274 | path = get_path(f, ino); |
| 2275 | if (path != NULL) { |
| 2276 | if (f->conf.debug) { |
| 2277 | printf("FLUSH[%llu]\n", (unsigned long long) fi->fh); |
| 2278 | fflush(stdout); |
| 2279 | } |
| 2280 | err = -ENOSYS; |
| 2281 | if (f->op.flush) { |
| 2282 | struct fuse_intr_data d; |
| 2283 | fuse_prepare_interrupt(f, req, &d); |
| 2284 | err = f->op.flush(path, fi); |
| 2285 | fuse_finish_interrupt(f, req, &d); |
| 2286 | } |
| 2287 | free(path); |
| 2288 | } |
| 2289 | if (f->op.lock) { |
| 2290 | struct flock lock; |
| 2291 | struct lock l; |
| 2292 | memset(&lock, 0, sizeof(lock)); |
| 2293 | lock.l_type = F_UNLCK; |
| 2294 | lock.l_whence = SEEK_SET; |
| 2295 | fuse_do_lock(f, req, path, fi, F_SETLK, &lock, owner); |
| 2296 | flock_to_lock(&lock, &l); |
| 2297 | l.owner = owner; |
| 2298 | pthread_mutex_lock(&f->lock); |
| 2299 | locks_insert(get_node(f, ino), &l); |
| 2300 | pthread_mutex_unlock(&f->lock); |
| 2301 | |
| 2302 | /* if op.lock() is defined FLUSH is needed regardless of op.flush() */ |
| 2303 | if (err == -ENOSYS) |
| 2304 | err = 0; |
| 2305 | } |
| 2306 | pthread_rwlock_unlock(&f->tree_lock); |
| 2307 | reply_err(req, err); |
| 2308 | } |
| 2309 | |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2310 | static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino, |
| 2311 | struct fuse_file_info *fi, struct flock *lock, |
| 2312 | uint64_t owner, int cmd) |
| 2313 | { |
| 2314 | struct fuse *f = req_fuse_prepare(req); |
| 2315 | char *path; |
| 2316 | int err; |
| 2317 | |
| 2318 | err = -ENOENT; |
| 2319 | pthread_rwlock_rdlock(&f->tree_lock); |
| 2320 | path = get_path(f, ino); |
| 2321 | if (path != NULL) { |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 2322 | err = fuse_do_lock(f, req, path, fi, cmd, lock, owner); |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2323 | free(path); |
| 2324 | } |
| 2325 | pthread_rwlock_unlock(&f->tree_lock); |
| 2326 | return err; |
| 2327 | } |
| 2328 | |
| 2329 | static void fuse_getlk(fuse_req_t req, fuse_ino_t ino, |
| 2330 | struct fuse_file_info *fi, struct flock *lock, |
| 2331 | uint64_t owner) |
| 2332 | { |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 2333 | int err; |
| 2334 | struct lock l; |
| 2335 | struct lock *conflict; |
| 2336 | struct fuse *f = req_fuse(req); |
| 2337 | |
| 2338 | flock_to_lock(lock, &l); |
| 2339 | l.owner = owner; |
| 2340 | pthread_mutex_lock(&f->lock); |
| 2341 | conflict = locks_conflict(get_node(f, ino), &l); |
| 2342 | if (conflict) |
| 2343 | lock_to_flock(conflict, lock); |
| 2344 | pthread_mutex_unlock(&f->lock); |
| 2345 | if (!conflict) |
| 2346 | err = fuse_lock_common(req, ino, fi, lock, owner, F_GETLK); |
| 2347 | else |
| 2348 | err = 0; |
| 2349 | |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2350 | if (!err) |
| 2351 | fuse_reply_lock(req, lock); |
| 2352 | else |
| 2353 | reply_err(req, err); |
| 2354 | } |
| 2355 | |
| 2356 | static void fuse_setlk(fuse_req_t req, fuse_ino_t ino, |
| 2357 | struct fuse_file_info *fi, struct flock *lock, |
| 2358 | uint64_t owner, int sleep) |
| 2359 | { |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 2360 | int err = fuse_lock_common(req, ino, fi, lock, owner, |
| 2361 | sleep ? F_SETLKW : F_SETLK); |
| 2362 | if (!err) { |
| 2363 | struct fuse *f = req_fuse(req); |
| 2364 | struct lock l; |
| 2365 | flock_to_lock(lock, &l); |
| 2366 | l.owner = owner; |
| 2367 | pthread_mutex_lock(&f->lock); |
| 2368 | locks_insert(get_node(f, ino), &l); |
| 2369 | pthread_mutex_unlock(&f->lock); |
| 2370 | } |
| 2371 | reply_err(req, err); |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2372 | } |
| 2373 | |
Miklos Szeredi | 708b481 | 2006-09-30 16:02:25 +0000 | [diff] [blame] | 2374 | static void fuse_bmap(fuse_req_t req, fuse_ino_t ino, size_t blocksize, |
| 2375 | uint64_t idx) |
| 2376 | { |
| 2377 | struct fuse *f = req_fuse_prepare(req); |
| 2378 | char *path; |
| 2379 | int err; |
| 2380 | |
| 2381 | err = -ENOENT; |
| 2382 | pthread_rwlock_rdlock(&f->tree_lock); |
| 2383 | path = get_path(f, ino); |
| 2384 | if (path != NULL) { |
| 2385 | err = -ENOSYS; |
| 2386 | if (f->op.bmap) |
| 2387 | err = f->op.bmap(path, blocksize, &idx); |
| 2388 | free(path); |
| 2389 | } |
| 2390 | pthread_rwlock_unlock(&f->tree_lock); |
| 2391 | if (!err) |
| 2392 | fuse_reply_bmap(req, idx); |
| 2393 | else |
| 2394 | reply_err(req, err); |
| 2395 | } |
| 2396 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2397 | static struct fuse_lowlevel_ops fuse_path_ops = { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2398 | .init = fuse_data_init, |
| 2399 | .destroy = fuse_data_destroy, |
| 2400 | .lookup = fuse_lookup, |
| 2401 | .forget = fuse_forget, |
| 2402 | .getattr = fuse_getattr, |
| 2403 | .setattr = fuse_setattr, |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 2404 | .access = fuse_access, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2405 | .readlink = fuse_readlink, |
| 2406 | .mknod = fuse_mknod, |
| 2407 | .mkdir = fuse_mkdir, |
| 2408 | .unlink = fuse_unlink, |
| 2409 | .rmdir = fuse_rmdir, |
| 2410 | .symlink = fuse_symlink, |
| 2411 | .rename = fuse_rename, |
| 2412 | .link = fuse_link, |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 2413 | .create = fuse_create, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2414 | .open = fuse_open, |
| 2415 | .read = fuse_read, |
| 2416 | .write = fuse_write, |
| 2417 | .flush = fuse_flush, |
| 2418 | .release = fuse_release, |
| 2419 | .fsync = fuse_fsync, |
| 2420 | .opendir = fuse_opendir, |
| 2421 | .readdir = fuse_readdir, |
| 2422 | .releasedir = fuse_releasedir, |
| 2423 | .fsyncdir = fuse_fsyncdir, |
| 2424 | .statfs = fuse_statfs, |
| 2425 | .setxattr = fuse_setxattr, |
| 2426 | .getxattr = fuse_getxattr, |
| 2427 | .listxattr = fuse_listxattr, |
| 2428 | .removexattr = fuse_removexattr, |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2429 | .getlk = fuse_getlk, |
| 2430 | .setlk = fuse_setlk, |
Miklos Szeredi | 708b481 | 2006-09-30 16:02:25 +0000 | [diff] [blame] | 2431 | .bmap = fuse_bmap, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2432 | }; |
| 2433 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2434 | static void free_cmd(struct fuse_cmd *cmd) |
| 2435 | { |
| 2436 | free(cmd->buf); |
| 2437 | free(cmd); |
| 2438 | } |
| 2439 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 2440 | void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 2441 | { |
Miklos Szeredi | 178451d | 2005-08-15 13:19:07 +0000 | [diff] [blame] | 2442 | fuse_session_process(f->se, cmd->buf, cmd->buflen, cmd->ch); |
Miklos Szeredi | fa829b5 | 2005-12-02 11:05:41 +0000 | [diff] [blame] | 2443 | free_cmd(cmd); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2446 | int fuse_exited(struct fuse *f) |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 2447 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2448 | return fuse_session_exited(f->se); |
| 2449 | } |
| 2450 | |
| 2451 | struct fuse_session *fuse_get_session(struct fuse *f) |
| 2452 | { |
| 2453 | return f->se; |
| 2454 | } |
| 2455 | |
| 2456 | static struct fuse_cmd *fuse_alloc_cmd(size_t bufsize) |
| 2457 | { |
| 2458 | struct fuse_cmd *cmd = (struct fuse_cmd *) malloc(sizeof(*cmd)); |
| 2459 | if (cmd == NULL) { |
| 2460 | fprintf(stderr, "fuse: failed to allocate cmd\n"); |
| 2461 | return NULL; |
| 2462 | } |
| 2463 | cmd->buf = (char *) malloc(bufsize); |
| 2464 | if (cmd->buf == NULL) { |
| 2465 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 2466 | free(cmd); |
| 2467 | return NULL; |
| 2468 | } |
| 2469 | return cmd; |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 2472 | struct fuse_cmd *fuse_read_cmd(struct fuse *f) |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 2473 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2474 | struct fuse_chan *ch = fuse_session_next_chan(f->se, NULL); |
| 2475 | size_t bufsize = fuse_chan_bufsize(ch); |
| 2476 | struct fuse_cmd *cmd = fuse_alloc_cmd(bufsize); |
| 2477 | if (cmd != NULL) { |
Miklos Szeredi | 8d975f6 | 2006-03-17 15:56:05 +0000 | [diff] [blame] | 2478 | int res = fuse_chan_recv(&ch, cmd->buf, bufsize); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2479 | if (res <= 0) { |
| 2480 | free_cmd(cmd); |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 2481 | if (res < 0 && res != -EINTR && res != -EAGAIN) |
Miklos Szeredi | fa829b5 | 2005-12-02 11:05:41 +0000 | [diff] [blame] | 2482 | fuse_exit(f); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2483 | return NULL; |
| 2484 | } |
| 2485 | cmd->buflen = res; |
Miklos Szeredi | 178451d | 2005-08-15 13:19:07 +0000 | [diff] [blame] | 2486 | cmd->ch = ch; |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2487 | } |
| 2488 | return cmd; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2491 | int fuse_loop(struct fuse *f) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2492 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2493 | if (f) |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2494 | return fuse_session_loop(f->se); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2495 | else |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2496 | return -1; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 2499 | int fuse_invalidate(struct fuse *f, const char *path) |
| 2500 | { |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2501 | (void) f; |
| 2502 | (void) path; |
| 2503 | return -EINVAL; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 2506 | void fuse_exit(struct fuse *f) |
| 2507 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2508 | fuse_session_exit(f->se); |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2511 | struct fuse_context *fuse_get_context(void) |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 2512 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2513 | return &fuse_get_context_internal()->ctx; |
| 2514 | } |
| 2515 | |
| 2516 | int fuse_interrupted(void) |
| 2517 | { |
| 2518 | return fuse_req_interrupted(fuse_get_context_internal()->req); |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 2521 | void fuse_set_getcontext_func(struct fuse_context *(*func)(void)) |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 2522 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2523 | (void) func; |
| 2524 | /* no-op */ |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2527 | enum { |
| 2528 | KEY_HELP, |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2529 | }; |
| 2530 | |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2531 | #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } |
| 2532 | |
| 2533 | static const struct fuse_opt fuse_lib_opts[] = { |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2534 | FUSE_OPT_KEY("-h", KEY_HELP), |
| 2535 | FUSE_OPT_KEY("--help", KEY_HELP), |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2536 | FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), |
| 2537 | FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP), |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2538 | FUSE_LIB_OPT("debug", debug, 1), |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2539 | FUSE_LIB_OPT("-d", debug, 1), |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2540 | FUSE_LIB_OPT("hard_remove", hard_remove, 1), |
| 2541 | FUSE_LIB_OPT("use_ino", use_ino, 1), |
| 2542 | FUSE_LIB_OPT("readdir_ino", readdir_ino, 1), |
| 2543 | FUSE_LIB_OPT("direct_io", direct_io, 1), |
| 2544 | FUSE_LIB_OPT("kernel_cache", kernel_cache, 1), |
Miklos Szeredi | 320abe4 | 2006-01-30 18:14:51 +0000 | [diff] [blame] | 2545 | FUSE_LIB_OPT("auto_cache", auto_cache, 1), |
| 2546 | FUSE_LIB_OPT("noauto_cache", auto_cache, 0), |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2547 | FUSE_LIB_OPT("umask=", set_mode, 1), |
| 2548 | FUSE_LIB_OPT("umask=%o", umask, 0), |
| 2549 | FUSE_LIB_OPT("uid=", set_uid, 1), |
| 2550 | FUSE_LIB_OPT("uid=%d", uid, 0), |
| 2551 | FUSE_LIB_OPT("gid=", set_gid, 1), |
| 2552 | FUSE_LIB_OPT("gid=%d", gid, 0), |
| 2553 | FUSE_LIB_OPT("entry_timeout=%lf", entry_timeout, 0), |
| 2554 | FUSE_LIB_OPT("attr_timeout=%lf", attr_timeout, 0), |
Miklos Szeredi | 6e806e9 | 2006-02-16 16:59:39 +0000 | [diff] [blame] | 2555 | FUSE_LIB_OPT("ac_attr_timeout=%lf", ac_attr_timeout, 0), |
| 2556 | FUSE_LIB_OPT("ac_attr_timeout=", ac_attr_timeout_set, 1), |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2557 | FUSE_LIB_OPT("negative_timeout=%lf", negative_timeout, 0), |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2558 | FUSE_LIB_OPT("intr", intr, 1), |
| 2559 | FUSE_LIB_OPT("intr_signal=%d", intr_signal, 0), |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2560 | FUSE_OPT_END |
| 2561 | }; |
| 2562 | |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2563 | static void fuse_lib_help(void) |
| 2564 | { |
| 2565 | fprintf(stderr, |
Miklos Szeredi | 0609146 | 2006-02-16 16:38:34 +0000 | [diff] [blame] | 2566 | " -o hard_remove immediate removal (don't hide files)\n" |
| 2567 | " -o use_ino let filesystem set inode numbers\n" |
| 2568 | " -o readdir_ino try to fill in d_ino in readdir\n" |
| 2569 | " -o direct_io use direct I/O\n" |
| 2570 | " -o kernel_cache cache files in kernel\n" |
| 2571 | " -o [no]auto_cache enable caching based on modification times\n" |
| 2572 | " -o umask=M set file permissions (octal)\n" |
| 2573 | " -o uid=N set file owner\n" |
| 2574 | " -o gid=N set file group\n" |
| 2575 | " -o entry_timeout=T cache timeout for names (1.0s)\n" |
| 2576 | " -o negative_timeout=T cache timeout for deleted names (0.0s)\n" |
Miklos Szeredi | 6e806e9 | 2006-02-16 16:59:39 +0000 | [diff] [blame] | 2577 | " -o attr_timeout=T cache timeout for attributes (1.0s)\n" |
| 2578 | " -o ac_attr_timeout=T auto cache timeout for attributes (attr_timeout)\n" |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2579 | " -o intr allow requests to be interrupted\n" |
| 2580 | " -o intr_signal=NUM signal to send on interrupt (%i)\n" |
| 2581 | "\n", FUSE_DEFAULT_INTR_SIGNAL); |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | static int fuse_lib_opt_proc(void *data, const char *arg, int key, |
| 2585 | struct fuse_args *outargs) |
| 2586 | { |
| 2587 | (void) data; (void) arg; (void) outargs; |
| 2588 | |
| 2589 | if (key == KEY_HELP) |
| 2590 | fuse_lib_help(); |
| 2591 | |
| 2592 | return 1; |
| 2593 | } |
| 2594 | |
| 2595 | |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 2596 | int fuse_is_lib_option(const char *opt) |
| 2597 | { |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2598 | return fuse_lowlevel_is_lib_option(opt) || |
| 2599 | fuse_opt_match(fuse_lib_opts, opt); |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2602 | static int fuse_init_intr_signal(int signum, int *installed) |
| 2603 | { |
| 2604 | struct sigaction old_sa; |
| 2605 | |
| 2606 | if (sigaction(signum, NULL, &old_sa) == -1) { |
| 2607 | perror("fuse: cannot get old signal handler"); |
| 2608 | return -1; |
| 2609 | } |
| 2610 | |
| 2611 | if (old_sa.sa_handler == SIG_DFL) { |
| 2612 | struct sigaction sa; |
| 2613 | |
| 2614 | memset(&sa, 0, sizeof(struct sigaction)); |
| 2615 | sa.sa_handler = fuse_intr_sighandler; |
Miklos Szeredi | 0c59ebf | 2006-09-10 20:53:36 +0000 | [diff] [blame] | 2616 | sigemptyset(&sa.sa_mask); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2617 | |
| 2618 | if (sigaction(signum, &sa, NULL) == -1) { |
| 2619 | perror("fuse: cannot set interrupt signal handler"); |
| 2620 | return -1; |
| 2621 | } |
| 2622 | *installed = 1; |
| 2623 | } |
| 2624 | return 0; |
| 2625 | } |
| 2626 | |
Miklos Szeredi | 349bdda | 2006-09-07 11:48:16 +0000 | [diff] [blame] | 2627 | static void fuse_restore_intr_signal(int signum) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2628 | { |
Miklos Szeredi | 349bdda | 2006-09-07 11:48:16 +0000 | [diff] [blame] | 2629 | struct sigaction sa; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2630 | |
Miklos Szeredi | 349bdda | 2006-09-07 11:48:16 +0000 | [diff] [blame] | 2631 | memset(&sa, 0, sizeof(struct sigaction)); |
| 2632 | sa.sa_handler = SIG_DFL; |
| 2633 | sigaction(signum, &sa, NULL); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2636 | struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2637 | const struct fuse_operations *op, |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2638 | size_t op_size, void *user_data, int compat) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2639 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2640 | struct fuse *f; |
| 2641 | struct node *root; |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2642 | struct fuse_lowlevel_ops llop = fuse_path_ops; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2643 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 2644 | if (sizeof(struct fuse_operations) < op_size) { |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2645 | fprintf(stderr, "fuse: warning: library too old, some operations may not not work\n"); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 2646 | op_size = sizeof(struct fuse_operations); |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2649 | if (fuse_create_context_key() == -1) |
| 2650 | goto out; |
| 2651 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2652 | f = (struct fuse *) calloc(1, sizeof(struct fuse)); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2653 | if (f == NULL) { |
| 2654 | fprintf(stderr, "fuse: failed to allocate fuse object\n"); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2655 | goto out_delete_context_key; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2656 | } |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 2657 | |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2658 | f->user_data = user_data; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2659 | f->conf.entry_timeout = 1.0; |
| 2660 | f->conf.attr_timeout = 1.0; |
| 2661 | f->conf.negative_timeout = 0.0; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2662 | f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 2663 | |
Miklos Szeredi | ad00597 | 2006-01-07 10:14:34 +0000 | [diff] [blame] | 2664 | if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, fuse_lib_opt_proc) == -1) |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2665 | goto out_free; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2666 | |
Miklos Szeredi | 6e806e9 | 2006-02-16 16:59:39 +0000 | [diff] [blame] | 2667 | if (!f->conf.ac_attr_timeout_set) |
| 2668 | f->conf.ac_attr_timeout = f->conf.attr_timeout; |
| 2669 | |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2670 | #ifdef __FreeBSD__ |
| 2671 | /* |
| 2672 | * In FreeBSD, we always use these settings as inode numbers are needed to |
| 2673 | * make getcwd(3) work. |
| 2674 | */ |
Miklos Szeredi | 76fc3de | 2005-12-12 09:34:45 +0000 | [diff] [blame] | 2675 | f->conf.readdir_ino = 1; |
Miklos Szeredi | 659743b | 2005-12-09 17:41:42 +0000 | [diff] [blame] | 2676 | #endif |
| 2677 | |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2678 | if (compat && compat <= 25) { |
| 2679 | if (fuse_sync_compat_args(args) == -1) |
| 2680 | goto out_free; |
| 2681 | } |
| 2682 | |
Miklos Szeredi | 9a5c11d | 2006-07-30 17:33:40 +0000 | [diff] [blame] | 2683 | memcpy(&f->op, op, op_size); |
| 2684 | if (!f->op.lock) { |
| 2685 | llop.getlk = NULL; |
| 2686 | llop.setlk = NULL; |
| 2687 | } |
| 2688 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2689 | f->se = fuse_lowlevel_new_common(args, &llop, sizeof(llop), f); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2690 | if (f->se == NULL) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2691 | goto out_free; |
Miklos Szeredi | 2bb750e | 2005-10-03 14:54:24 +0000 | [diff] [blame] | 2692 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2693 | fuse_session_add_chan(f->se, ch); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 2694 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2695 | f->ctr = 0; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 2696 | f->generation = 0; |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 2697 | /* FIXME: Dynamic hash table */ |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2698 | f->name_table_size = 14057; |
| 2699 | f->name_table = (struct node **) |
| 2700 | calloc(1, sizeof(struct node *) * f->name_table_size); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2701 | if (f->name_table == NULL) { |
| 2702 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2703 | goto out_free_session; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2704 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2705 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2706 | f->id_table_size = 14057; |
| 2707 | f->id_table = (struct node **) |
| 2708 | calloc(1, sizeof(struct node *) * f->id_table_size); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2709 | if (f->id_table == NULL) { |
| 2710 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2711 | goto out_free_name_table; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2712 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2713 | |
Miklos Szeredi | 38f152c | 2006-09-03 18:28:52 +0000 | [diff] [blame] | 2714 | fuse_mutex_init(&f->lock); |
Miklos Szeredi | d0a777a | 2006-04-05 07:18:00 +0000 | [diff] [blame] | 2715 | pthread_rwlock_init(&f->tree_lock, NULL); |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2716 | f->compat = compat; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2717 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2718 | root = (struct node *) calloc(1, sizeof(struct node)); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2719 | if (root == NULL) { |
| 2720 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2721 | goto out_free_id_table; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2722 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2723 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2724 | root->name = strdup("/"); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2725 | if (root->name == NULL) { |
| 2726 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2727 | goto out_free_root; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2728 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2729 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2730 | if (f->conf.intr && |
| 2731 | fuse_init_intr_signal(f->conf.intr_signal, &f->intr_installed) == -1) |
| 2732 | goto out_free_root_name; |
| 2733 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2734 | root->parent = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2735 | root->nodeid = FUSE_ROOT_ID; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 2736 | root->generation = 0; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 2737 | root->refctr = 1; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 2738 | root->nlookup = 1; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2739 | hash_id(f, root); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2740 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2741 | return f; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2742 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2743 | out_free_root_name: |
| 2744 | free(root->name); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2745 | out_free_root: |
| 2746 | free(root); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2747 | out_free_id_table: |
| 2748 | free(f->id_table); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2749 | out_free_name_table: |
| 2750 | free(f->name_table); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2751 | out_free_session: |
| 2752 | fuse_session_destroy(f->se); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2753 | out_free: |
| 2754 | free(f); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2755 | out_delete_context_key: |
| 2756 | fuse_delete_context_key(); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2757 | out: |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2758 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2761 | struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, |
| 2762 | const struct fuse_operations *op, size_t op_size, |
| 2763 | void *user_data) |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2764 | { |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2765 | return fuse_new_common(ch, args, op, op_size, user_data, 0); |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2768 | void fuse_destroy(struct fuse *f) |
| 2769 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2770 | size_t i; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2771 | struct fuse_context_i *c = fuse_get_context_internal(); |
| 2772 | |
| 2773 | if (f->conf.intr && f->intr_installed) |
| 2774 | fuse_restore_intr_signal(f->conf.intr_signal); |
Miklos Szeredi | ad51956 | 2006-07-31 11:07:40 +0000 | [diff] [blame] | 2775 | |
| 2776 | memset(c, 0, sizeof(*c)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2777 | c->ctx.fuse = f; |
| 2778 | c->ctx.private_data = f->user_data; |
Miklos Szeredi | ad51956 | 2006-07-31 11:07:40 +0000 | [diff] [blame] | 2779 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2780 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2781 | struct node *node; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2782 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2783 | for (node = f->id_table[i]; node != NULL; node = node->id_next) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2784 | if (node->is_hidden) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2785 | char *path = get_path(f, node->nodeid); |
Miklos Szeredi | 21019c9 | 2005-05-09 11:22:41 +0000 | [diff] [blame] | 2786 | if (path) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2787 | f->op.unlink(path); |
Miklos Szeredi | 21019c9 | 2005-05-09 11:22:41 +0000 | [diff] [blame] | 2788 | free(path); |
| 2789 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2790 | } |
| 2791 | } |
| 2792 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2793 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2794 | struct node *node; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2795 | struct node *next; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2796 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2797 | for (node = f->id_table[i]; node != NULL; node = next) { |
| 2798 | next = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2799 | free_node(node); |
| 2800 | } |
| 2801 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2802 | free(f->id_table); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2803 | free(f->name_table); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 2804 | pthread_mutex_destroy(&f->lock); |
Miklos Szeredi | 55a8410 | 2006-06-06 10:16:38 +0000 | [diff] [blame] | 2805 | pthread_rwlock_destroy(&f->tree_lock); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2806 | fuse_session_destroy(f->se); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2807 | free(f); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2808 | fuse_delete_context_key(); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2809 | } |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2810 | |
Miklos Szeredi | eafdf42 | 2006-09-22 19:30:17 +0000 | [diff] [blame] | 2811 | #include "fuse_common_compat.h" |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2812 | #include "fuse_compat.h" |
| 2813 | |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2814 | static struct fuse *fuse_new_common_compat25(int fd, struct fuse_args *args, |
| 2815 | const struct fuse_operations *op, |
| 2816 | size_t op_size, int compat) |
| 2817 | { |
| 2818 | struct fuse *f = NULL; |
| 2819 | struct fuse_chan *ch = fuse_kern_chan_new(fd); |
| 2820 | |
| 2821 | if (ch) |
| 2822 | f = fuse_new_common(ch, args, op, op_size, NULL, compat); |
| 2823 | |
| 2824 | return f; |
| 2825 | } |
| 2826 | |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2827 | #ifndef __FreeBSD__ |
| 2828 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2829 | static int fuse_compat_open(struct fuse *f, fuse_req_t req, char *path, |
| 2830 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2831 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2832 | int err; |
| 2833 | struct fuse_intr_data d; |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2834 | if (!f->compat || f->compat >= 25) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2835 | err = fuse_do_open(f, req, path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2836 | else if (f->compat == 22) { |
Miklos Szeredi | eafdf42 | 2006-09-22 19:30:17 +0000 | [diff] [blame] | 2837 | struct fuse_file_info_compat tmp; |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2838 | memcpy(&tmp, fi, sizeof(tmp)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2839 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2840 | err = ((struct fuse_operations_compat22 *) &f->op)->open(path, &tmp); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2841 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2842 | memcpy(fi, &tmp, sizeof(tmp)); |
| 2843 | fi->fh = tmp.fh; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2844 | } else { |
| 2845 | fuse_prepare_interrupt(f, req, &d); |
| 2846 | err = |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2847 | ((struct fuse_operations_compat2 *) &f->op)->open(path, fi->flags); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2848 | fuse_finish_interrupt(f, req, &d); |
| 2849 | } |
| 2850 | return err; |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2853 | static void fuse_compat_release(struct fuse *f, fuse_req_t req, char *path, |
| 2854 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2855 | { |
| 2856 | if (!f->compat || f->compat >= 22) |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2857 | fuse_do_release(f, req, path ? path : "-", fi); |
| 2858 | else if (path) { |
| 2859 | struct fuse_intr_data d; |
| 2860 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2861 | ((struct fuse_operations_compat2 *) &f->op)->release(path, fi->flags); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2862 | fuse_finish_interrupt(f, req, &d); |
| 2863 | } |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2866 | static int fuse_compat_opendir(struct fuse *f, fuse_req_t req, char *path, |
| 2867 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2868 | { |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2869 | if (!f->compat || f->compat >= 25) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2870 | return fuse_do_opendir(f, req, path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2871 | } else { |
| 2872 | int err; |
Miklos Szeredi | eafdf42 | 2006-09-22 19:30:17 +0000 | [diff] [blame] | 2873 | struct fuse_file_info_compat tmp; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2874 | struct fuse_intr_data d; |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2875 | memcpy(&tmp, fi, sizeof(tmp)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2876 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2877 | err = ((struct fuse_operations_compat22 *) &f->op)->opendir(path, &tmp); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2878 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2879 | memcpy(fi, &tmp, sizeof(tmp)); |
| 2880 | fi->fh = tmp.fh; |
| 2881 | return err; |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | static void convert_statfs_compat(struct fuse_statfs_compat1 *compatbuf, |
| 2886 | struct statvfs *stbuf) |
| 2887 | { |
| 2888 | stbuf->f_bsize = compatbuf->block_size; |
| 2889 | stbuf->f_blocks = compatbuf->blocks; |
| 2890 | stbuf->f_bfree = compatbuf->blocks_free; |
| 2891 | stbuf->f_bavail = compatbuf->blocks_free; |
| 2892 | stbuf->f_files = compatbuf->files; |
| 2893 | stbuf->f_ffree = compatbuf->files_free; |
| 2894 | stbuf->f_namemax = compatbuf->namelen; |
| 2895 | } |
| 2896 | |
| 2897 | static void convert_statfs_old(struct statfs *oldbuf, struct statvfs *stbuf) |
| 2898 | { |
| 2899 | stbuf->f_bsize = oldbuf->f_bsize; |
| 2900 | stbuf->f_blocks = oldbuf->f_blocks; |
| 2901 | stbuf->f_bfree = oldbuf->f_bfree; |
| 2902 | stbuf->f_bavail = oldbuf->f_bavail; |
| 2903 | stbuf->f_files = oldbuf->f_files; |
| 2904 | stbuf->f_ffree = oldbuf->f_ffree; |
| 2905 | stbuf->f_namemax = oldbuf->f_namelen; |
| 2906 | } |
| 2907 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2908 | static int fuse_compat_statfs(struct fuse *f, fuse_req_t req, |
| 2909 | struct statvfs *buf) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2910 | { |
| 2911 | int err; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2912 | struct fuse_intr_data d; |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2913 | |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 2914 | if (!f->compat || f->compat >= 25) { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2915 | err = fuse_do_statfs(f, req, "/", buf); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2916 | } else if (f->compat > 11) { |
| 2917 | struct statfs oldbuf; |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2918 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2919 | err = ((struct fuse_operations_compat22 *) &f->op)->statfs("/", &oldbuf); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2920 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2921 | if (!err) |
| 2922 | convert_statfs_old(&oldbuf, buf); |
| 2923 | } else { |
| 2924 | struct fuse_statfs_compat1 compatbuf; |
| 2925 | memset(&compatbuf, 0, sizeof(struct fuse_statfs_compat1)); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2926 | fuse_prepare_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2927 | err = ((struct fuse_operations_compat1 *) &f->op)->statfs(&compatbuf); |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2928 | fuse_finish_interrupt(f, req, &d); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2929 | if (!err) |
| 2930 | convert_statfs_compat(&compatbuf, buf); |
| 2931 | } |
| 2932 | return err; |
| 2933 | } |
| 2934 | |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2935 | static struct fuse *fuse_new_common_compat(int fd, const char *opts, |
| 2936 | const struct fuse_operations *op, |
| 2937 | size_t op_size, int compat) |
| 2938 | { |
| 2939 | struct fuse *f; |
| 2940 | struct fuse_args args = FUSE_ARGS_INIT(0, NULL); |
| 2941 | |
| 2942 | if (opts && |
| 2943 | (fuse_opt_add_arg(&args, "") == -1 || |
| 2944 | fuse_opt_add_arg(&args, "-o") == -1 || |
| 2945 | fuse_opt_add_arg(&args, opts) == -1)) { |
| 2946 | fuse_opt_free_args(&args); |
| 2947 | return NULL; |
| 2948 | } |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 2949 | f = fuse_new_common_compat25(fd, &args, op, op_size, compat); |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2950 | fuse_opt_free_args(&args); |
| 2951 | |
| 2952 | return f; |
| 2953 | } |
| 2954 | |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2955 | struct fuse *fuse_new_compat22(int fd, const char *opts, |
| 2956 | const struct fuse_operations_compat22 *op, |
| 2957 | size_t op_size) |
| 2958 | { |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2959 | return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op, |
| 2960 | op_size, 22); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | struct fuse *fuse_new_compat2(int fd, const char *opts, |
| 2964 | const struct fuse_operations_compat2 *op) |
| 2965 | { |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2966 | return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op, |
| 2967 | sizeof(struct fuse_operations_compat2), 21); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | struct fuse *fuse_new_compat1(int fd, int flags, |
| 2971 | const struct fuse_operations_compat1 *op) |
| 2972 | { |
| 2973 | const char *opts = NULL; |
| 2974 | if (flags & FUSE_DEBUG_COMPAT1) |
| 2975 | opts = "debug"; |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 2976 | return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op, |
| 2977 | sizeof(struct fuse_operations_compat1), 11); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 2980 | __asm__(".symver fuse_exited,__fuse_exited@"); |
| 2981 | __asm__(".symver fuse_process_cmd,__fuse_process_cmd@"); |
| 2982 | __asm__(".symver fuse_read_cmd,__fuse_read_cmd@"); |
| 2983 | __asm__(".symver fuse_set_getcontext_func,__fuse_set_getcontext_func@"); |
| 2984 | __asm__(".symver fuse_new_compat2,fuse_new@"); |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 2985 | __asm__(".symver fuse_new_compat22,fuse_new@FUSE_2.2"); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2986 | |
| 2987 | #else /* __FreeBSD__ */ |
| 2988 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2989 | static int fuse_compat_open(struct fuse *f, fuse_req_t req, char *path, |
| 2990 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2991 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2992 | return fuse_do_open(f, req, path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2995 | static void fuse_compat_release(struct fuse *f, fuse_req_t req, char *path, |
| 2996 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2997 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 2998 | fuse_do_release(f, req, path ? path : "-", fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 3001 | static int fuse_compat_opendir(struct fuse *f, fuse_req_t req, char *path, |
| 3002 | struct fuse_file_info *fi) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 3003 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 3004 | return fuse_do_opendir(f, req, path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
Csaba Henk | 3e3a125 | 2006-09-24 14:53:29 +0000 | [diff] [blame] | 3007 | static int fuse_compat_statfs(struct fuse *f, fuse_req_t req, struct statvfs *buf) |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 3008 | { |
Miklos Szeredi | 288ed4e | 2006-09-07 06:02:44 +0000 | [diff] [blame] | 3009 | return fuse_do_statfs(f, req, "/", buf); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | #endif /* __FreeBSD__ */ |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 3013 | |
| 3014 | struct fuse *fuse_new_compat25(int fd, struct fuse_args *args, |
| 3015 | const struct fuse_operations_compat25 *op, |
| 3016 | size_t op_size) |
| 3017 | { |
Miklos Szeredi | 6f38541 | 2006-03-17 15:05:40 +0000 | [diff] [blame] | 3018 | return fuse_new_common_compat25(fd, args, (struct fuse_operations *) op, |
| 3019 | op_size, 25); |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | __asm__(".symver fuse_new_compat25,fuse_new@FUSE_2.5"); |