Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 149f607 | 2005-01-10 12:29:28 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2005 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 | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 15 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 16 | #include <stdio.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 17 | #include <string.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 20 | #include <fcntl.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 21 | #include <limits.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 22 | #include <errno.h> |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 23 | #include <assert.h> |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 24 | #include <pthread.h> |
Miklos Szeredi | 019b4e9 | 2001-12-26 18:08:09 +0000 | [diff] [blame] | 25 | #include <sys/param.h> |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 26 | #include <sys/uio.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 27 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 28 | /* FUSE flags: */ |
| 29 | |
Miklos Szeredi | b75d4b9 | 2005-10-11 10:12:08 +0000 | [diff] [blame] | 30 | /** Enable debugging output */ |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 31 | #define FUSE_DEBUG (1 << 1) |
| 32 | |
| 33 | /** If a file is removed but it's still open, don't hide the file but |
| 34 | remove it immediately */ |
| 35 | #define FUSE_HARD_REMOVE (1 << 2) |
| 36 | |
| 37 | /** Use st_ino field in getattr instead of generating inode numbers */ |
| 38 | #define FUSE_USE_INO (1 << 3) |
| 39 | |
Miklos Szeredi | 33be22d | 2005-05-27 09:12:43 +0000 | [diff] [blame] | 40 | /** Make a best effort to fill in inode number in a readdir **/ |
| 41 | #define FUSE_READDIR_INO (1 << 5) |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 42 | |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 43 | /** Ignore file mode supplied by the filesystem, and create one based |
| 44 | on the 'umask' option */ |
| 45 | #define FUSE_SET_MODE (1 << 6) |
| 46 | |
| 47 | /** Ignore st_uid supplied by the filesystem and set it based on the |
| 48 | 'uid' option*/ |
| 49 | #define FUSE_SET_UID (1 << 7) |
| 50 | |
| 51 | /** Ignore st_gid supplied by the filesystem and set it based on the |
| 52 | 'gid' option*/ |
| 53 | #define FUSE_SET_GID (1 << 8) |
| 54 | |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 55 | /** Bypass the page cache for read and write operations */ |
| 56 | #define FUSE_DIRECT_IO (1 << 9) |
| 57 | |
| 58 | /** If the FUSE_KERNEL_CACHE flag is given, then cached data will not |
| 59 | be flushed on open */ |
| 60 | #define FUSE_KERNEL_CACHE (1 << 10) |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 61 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 62 | #define FUSE_MAX_PATH 4096 |
Miklos Szeredi | 30e093a | 2005-04-03 17:44:54 +0000 | [diff] [blame] | 63 | |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 64 | struct fuse { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 65 | struct fuse_session *se; |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 66 | int flags; |
| 67 | struct fuse_operations op; |
| 68 | int compat; |
| 69 | struct node **name_table; |
| 70 | size_t name_table_size; |
| 71 | struct node **id_table; |
| 72 | size_t id_table_size; |
| 73 | fuse_ino_t ctr; |
| 74 | unsigned int generation; |
| 75 | unsigned int hidectr; |
| 76 | pthread_mutex_t lock; |
| 77 | pthread_rwlock_t tree_lock; |
| 78 | void *user_data; |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 79 | unsigned int uid; |
| 80 | unsigned int gid; |
| 81 | unsigned int umask; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 82 | double entry_timeout; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 83 | double negative_timeout; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 84 | double attr_timeout; |
Miklos Szeredi | e2aa2e2 | 2005-07-15 13:31:36 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 87 | struct node { |
| 88 | struct node *name_next; |
| 89 | struct node *id_next; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 90 | fuse_ino_t nodeid; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 91 | unsigned int generation; |
| 92 | int refctr; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 93 | fuse_ino_t parent; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 94 | char *name; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 95 | uint64_t nlookup; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 96 | int open_count; |
| 97 | int is_hidden; |
| 98 | }; |
| 99 | |
| 100 | struct fuse_dirhandle { |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 101 | pthread_mutex_t lock; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 102 | struct fuse *fuse; |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 103 | char *contents; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 104 | int allocated; |
Miklos Szeredi | b92d978 | 2005-02-07 16:10:49 +0000 | [diff] [blame] | 105 | unsigned len; |
Miklos Szeredi | c4c12ae | 2005-10-20 14:48:50 +0000 | [diff] [blame] | 106 | unsigned size; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 107 | unsigned needlen; |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 108 | int filled; |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 109 | uint64_t fh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 110 | int error; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 111 | fuse_ino_t nodeid; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 114 | static struct fuse_context *(*fuse_getcontext)(void) = NULL; |
| 115 | |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 116 | static int fuse_do_open(struct fuse *, char *, struct fuse_file_info *); |
| 117 | static void fuse_do_release(struct fuse *, char *, struct fuse_file_info *); |
| 118 | static int fuse_do_opendir(struct fuse *, char *, struct fuse_file_info *); |
| 119 | static int fuse_do_statfs(struct fuse *, char *, struct statvfs *); |
| 120 | |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 121 | #ifndef USE_UCLIBC |
| 122 | #define mutex_init(mut) pthread_mutex_init(mut, NULL) |
| 123 | #else |
Miklos Szeredi | 129ef8f | 2005-06-20 13:48:42 +0000 | [diff] [blame] | 124 | static void mutex_init(pthread_mutex_t *mut) |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 125 | { |
| 126 | pthread_mutexattr_t attr; |
| 127 | pthread_mutexattr_init(&attr); |
| 128 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); |
| 129 | pthread_mutex_init(mut, &attr); |
| 130 | pthread_mutexattr_destroy(&attr); |
| 131 | } |
| 132 | #endif |
| 133 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 134 | 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] | 135 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 136 | size_t hash = nodeid % f->id_table_size; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 137 | struct node *node; |
| 138 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 139 | for (node = f->id_table[hash]; node != NULL; node = node->id_next) |
| 140 | if (node->nodeid == nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 141 | return node; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 142 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 143 | return NULL; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 146 | static struct node *get_node(struct fuse *f, fuse_ino_t nodeid) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 147 | { |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 148 | struct node *node = get_node_nocheck(f, nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 149 | if (!node) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 150 | fprintf(stderr, "fuse internal error: node %llu not found\n", |
| 151 | (unsigned long long) nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 152 | abort(); |
| 153 | } |
| 154 | return node; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 157 | static void free_node(struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 158 | { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 159 | free(node->name); |
| 160 | free(node); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 163 | static void unhash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 164 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 165 | size_t hash = node->nodeid % f->id_table_size; |
| 166 | struct node **nodep = &f->id_table[hash]; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 167 | |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 168 | for (; *nodep != NULL; nodep = &(*nodep)->id_next) |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 169 | if (*nodep == node) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 170 | *nodep = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 171 | return; |
| 172 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 175 | static void hash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 176 | { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 177 | size_t hash = node->nodeid % f->id_table_size; |
| 178 | node->id_next = f->id_table[hash]; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 179 | f->id_table[hash] = node; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 182 | 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] | 183 | { |
| 184 | unsigned int hash = *name; |
| 185 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 186 | if (hash) |
| 187 | for (name += 1; *name != '\0'; name++) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 188 | hash = (hash << 5) - hash + *name; |
| 189 | |
| 190 | return (hash + parent) % f->name_table_size; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 193 | static void unref_node(struct fuse *f, struct node *node); |
| 194 | |
| 195 | static void unhash_name(struct fuse *f, struct node *node) |
| 196 | { |
| 197 | if (node->name) { |
| 198 | size_t hash = name_hash(f, node->parent, node->name); |
| 199 | struct node **nodep = &f->name_table[hash]; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 200 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 201 | for (; *nodep != NULL; nodep = &(*nodep)->name_next) |
| 202 | if (*nodep == node) { |
| 203 | *nodep = node->name_next; |
| 204 | node->name_next = NULL; |
| 205 | unref_node(f, get_node(f, node->parent)); |
| 206 | free(node->name); |
| 207 | node->name = NULL; |
| 208 | node->parent = 0; |
| 209 | return; |
| 210 | } |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 211 | fprintf(stderr, "fuse internal error: unable to unhash node: %llu\n", |
| 212 | (unsigned long long) node->nodeid); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 213 | abort(); |
| 214 | } |
| 215 | } |
| 216 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 217 | 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] | 218 | const char *name) |
| 219 | { |
| 220 | size_t hash = name_hash(f, parent, name); |
| 221 | node->name = strdup(name); |
| 222 | if (node->name == NULL) |
| 223 | return -1; |
| 224 | |
| 225 | get_node(f, parent)->refctr ++; |
| 226 | node->parent = parent; |
| 227 | node->name_next = f->name_table[hash]; |
| 228 | f->name_table[hash] = node; |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static void delete_node(struct fuse *f, struct node *node) |
| 233 | { |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 234 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 235 | printf("delete: %llu\n", (unsigned long long) node->nodeid); |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 236 | fflush(stdout); |
| 237 | } |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 238 | assert(!node->name); |
| 239 | unhash_id(f, node); |
| 240 | free_node(node); |
| 241 | } |
| 242 | |
| 243 | static void unref_node(struct fuse *f, struct node *node) |
| 244 | { |
| 245 | assert(node->refctr > 0); |
| 246 | node->refctr --; |
| 247 | if (!node->refctr) |
| 248 | delete_node(f, node); |
| 249 | } |
| 250 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 251 | static fuse_ino_t next_id(struct fuse *f) |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 252 | { |
| 253 | do { |
| 254 | f->ctr++; |
| 255 | if (!f->ctr) |
| 256 | f->generation ++; |
| 257 | } while (f->ctr == 0 || get_node_nocheck(f, f->ctr) != NULL); |
| 258 | return f->ctr; |
| 259 | } |
| 260 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 261 | static struct node *lookup_node(struct fuse *f, fuse_ino_t parent, |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 262 | const char *name) |
| 263 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 264 | size_t hash = name_hash(f, parent, name); |
| 265 | struct node *node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 266 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 267 | for (node = f->name_table[hash]; node != NULL; node = node->name_next) |
| 268 | if (node->parent == parent && strcmp(node->name, name) == 0) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 269 | return node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 270 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 271 | return NULL; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 274 | static struct node *find_node(struct fuse *f, fuse_ino_t parent, |
| 275 | const char *name) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 276 | { |
| 277 | struct node *node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 278 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 279 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 280 | node = lookup_node(f, parent, name); |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 281 | if (node == NULL) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 282 | node = (struct node *) calloc(1, sizeof(struct node)); |
| 283 | if (node == NULL) |
| 284 | goto out_err; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 285 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 286 | node->refctr = 1; |
| 287 | node->nodeid = next_id(f); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 288 | node->open_count = 0; |
| 289 | node->is_hidden = 0; |
| 290 | node->generation = f->generation; |
| 291 | if (hash_name(f, node, parent, name) == -1) { |
| 292 | free(node); |
| 293 | node = NULL; |
| 294 | goto out_err; |
| 295 | } |
| 296 | hash_id(f, node); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 297 | } |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 298 | node->nlookup ++; |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 299 | out_err: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 300 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 301 | return node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 304 | static char *add_name(char *buf, char *s, const char *name) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 305 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 306 | size_t len = strlen(name); |
| 307 | s -= len; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 308 | if (s <= buf) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 309 | fprintf(stderr, "fuse: path too long: ...%s\n", s + len); |
| 310 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 311 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 312 | strncpy(s, name, len); |
| 313 | s--; |
| 314 | *s = '/'; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 315 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 316 | return s; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 319 | 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] | 320 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 321 | char buf[FUSE_MAX_PATH]; |
| 322 | char *s = buf + FUSE_MAX_PATH - 1; |
| 323 | struct node *node; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 324 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 325 | *s = '\0'; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 326 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 327 | if (name != NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 328 | s = add_name(buf, s, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 329 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 334 | for (node = get_node(f, nodeid); node && node->nodeid != FUSE_ROOT_ID; |
| 335 | node = get_node(f, node->parent)) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 336 | if (node->name == NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 337 | s = NULL; |
| 338 | break; |
| 339 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 340 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 341 | s = add_name(buf, s, node->name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 342 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | pthread_mutex_unlock(&f->lock); |
| 346 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 347 | if (node == NULL || s == NULL) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 348 | return NULL; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 349 | else if (*s == '\0') |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 350 | return strdup("/"); |
| 351 | else |
| 352 | return strdup(s); |
| 353 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 354 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 355 | static char *get_path(struct fuse *f, fuse_ino_t nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 356 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 357 | return get_path_name(f, nodeid, NULL); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 360 | 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] | 361 | { |
| 362 | struct node *node; |
| 363 | if (nodeid == FUSE_ROOT_ID) |
| 364 | return; |
| 365 | pthread_mutex_lock(&f->lock); |
| 366 | node = get_node(f, nodeid); |
| 367 | assert(node->nlookup >= nlookup); |
| 368 | node->nlookup -= nlookup; |
| 369 | if (!node->nlookup) { |
| 370 | unhash_name(f, node); |
| 371 | unref_node(f, node); |
| 372 | } |
| 373 | pthread_mutex_unlock(&f->lock); |
| 374 | } |
| 375 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 376 | 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] | 377 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 378 | struct node *node; |
| 379 | |
| 380 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 381 | node = lookup_node(f, dir, name); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 382 | if (node != NULL) |
| 383 | unhash_name(f, node); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 384 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 387 | static int rename_node(struct fuse *f, fuse_ino_t olddir, const char *oldname, |
| 388 | fuse_ino_t newdir, const char *newname, int hide) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 389 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 390 | struct node *node; |
| 391 | struct node *newnode; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 392 | int err = 0; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 393 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 394 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 395 | node = lookup_node(f, olddir, oldname); |
| 396 | newnode = lookup_node(f, newdir, newname); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 397 | if (node == NULL) |
| 398 | goto out; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 399 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 400 | if (newnode != NULL) { |
| 401 | if (hide) { |
| 402 | fprintf(stderr, "fuse: hidden file got created during hiding\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 403 | err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 404 | goto out; |
| 405 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 406 | unhash_name(f, newnode); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 407 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 408 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 409 | unhash_name(f, node); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 410 | if (hash_name(f, node, newdir, newname) == -1) { |
| 411 | err = -ENOMEM; |
| 412 | goto out; |
| 413 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 414 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 415 | if (hide) |
| 416 | node->is_hidden = 1; |
| 417 | |
| 418 | out: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 419 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 420 | return err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 423 | 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] | 424 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 425 | if (!(f->flags & FUSE_USE_INO)) |
| 426 | stbuf->st_ino = nodeid; |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 427 | if (f->flags & FUSE_SET_MODE) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 428 | stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f->umask); |
| 429 | if (f->flags & FUSE_SET_UID) |
| 430 | stbuf->st_uid = f->uid; |
| 431 | if (f->flags & FUSE_SET_GID) |
| 432 | stbuf->st_gid = f->gid; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 435 | 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] | 436 | { |
| 437 | struct node *node; |
| 438 | int isopen = 0; |
| 439 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 440 | node = lookup_node(f, dir, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 441 | if (node && node->open_count > 0) |
| 442 | isopen = 1; |
| 443 | pthread_mutex_unlock(&f->lock); |
| 444 | return isopen; |
| 445 | } |
| 446 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 447 | static char *hidden_name(struct fuse *f, fuse_ino_t dir, const char *oldname, |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 448 | char *newname, size_t bufsize) |
| 449 | { |
| 450 | struct stat buf; |
| 451 | struct node *node; |
| 452 | struct node *newnode; |
| 453 | char *newpath; |
| 454 | int res; |
| 455 | int failctr = 10; |
| 456 | |
| 457 | if (!f->op.getattr) |
| 458 | return NULL; |
| 459 | |
| 460 | do { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 461 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 462 | node = lookup_node(f, dir, oldname); |
| 463 | if (node == NULL) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 464 | pthread_mutex_unlock(&f->lock); |
| 465 | return NULL; |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 466 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 467 | do { |
| 468 | f->hidectr ++; |
| 469 | snprintf(newname, bufsize, ".fuse_hidden%08x%08x", |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 470 | (unsigned int) node->nodeid, f->hidectr); |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 471 | newnode = lookup_node(f, dir, newname); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 472 | } while(newnode); |
| 473 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 474 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 475 | newpath = get_path_name(f, dir, newname); |
| 476 | if (!newpath) |
| 477 | break; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 478 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 479 | res = f->op.getattr(newpath, &buf); |
| 480 | if (res != 0) |
| 481 | break; |
| 482 | free(newpath); |
| 483 | newpath = NULL; |
| 484 | } while(--failctr); |
| 485 | |
| 486 | return newpath; |
| 487 | } |
| 488 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 489 | static int hide_node(struct fuse *f, const char *oldpath, fuse_ino_t dir, |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 490 | const char *oldname) |
| 491 | { |
| 492 | char newname[64]; |
| 493 | char *newpath; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 494 | int err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 495 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 496 | if (f->op.rename && f->op.unlink) { |
| 497 | newpath = hidden_name(f, dir, oldname, newname, sizeof(newname)); |
| 498 | if (newpath) { |
| 499 | int res = f->op.rename(oldpath, newpath); |
| 500 | if (res == 0) |
| 501 | err = rename_node(f, dir, oldname, dir, newname, 1); |
| 502 | free(newpath); |
| 503 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 504 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 505 | return err; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 508 | static int lookup_path(struct fuse *f, fuse_ino_t nodeid, const char *name, |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 509 | const char *path, struct fuse_entry_param *e, |
| 510 | struct fuse_file_info *fi) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 511 | { |
| 512 | int res; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 513 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 514 | memset(e, 0, sizeof(struct fuse_entry_param)); |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 515 | if (fi && f->op.fgetattr) |
| 516 | res = f->op.fgetattr(path, &e->attr, fi); |
| 517 | else |
| 518 | res = f->op.getattr(path, &e->attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 519 | if (res == 0) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 520 | struct node *node; |
| 521 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 522 | node = find_node(f, nodeid, name); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 523 | if (node == NULL) |
| 524 | res = -ENOMEM; |
| 525 | else { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 526 | e->ino = node->nodeid; |
| 527 | e->generation = node->generation; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 528 | e->entry_timeout = f->entry_timeout; |
| 529 | e->attr_timeout = f->attr_timeout; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 530 | set_stat(f, e->ino, &e->attr); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 531 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 532 | printf(" NODEID: %lu\n", (unsigned long) e->ino); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 533 | fflush(stdout); |
| 534 | } |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | return res; |
| 538 | } |
| 539 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 540 | static struct fuse *req_fuse(fuse_req_t req) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 541 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 542 | return (struct fuse *) fuse_req_userdata(req); |
| 543 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 544 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 545 | static struct fuse *req_fuse_prepare(fuse_req_t req) |
| 546 | { |
| 547 | struct fuse_context *c = fuse_get_context(); |
| 548 | const struct fuse_ctx *ctx = fuse_req_ctx(req); |
| 549 | c->fuse = req_fuse(req); |
| 550 | c->uid = ctx->uid; |
| 551 | c->gid = ctx->gid; |
| 552 | c->pid = ctx->pid; |
| 553 | c->private_data = c->fuse->user_data; |
| 554 | |
| 555 | return c->fuse; |
| 556 | } |
| 557 | |
| 558 | static inline void reply_err(fuse_req_t req, int err) |
| 559 | { |
| 560 | /* fuse_reply_err() uses non-negated errno values */ |
| 561 | fuse_reply_err(req, -err); |
| 562 | } |
| 563 | |
| 564 | static void reply_entry(fuse_req_t req, const struct fuse_entry_param *e, |
| 565 | int err) |
| 566 | { |
| 567 | if (!err) { |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 568 | if (fuse_reply_entry(req, e) == -ENOENT) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 569 | forget_node(req_fuse(req), e->ino, 1); |
| 570 | } else |
| 571 | reply_err(req, err); |
| 572 | } |
| 573 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 574 | static void fuse_data_init(void *data) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 575 | { |
| 576 | struct fuse *f = (struct fuse *) data; |
Miklos Szeredi | 4f5df5e | 2005-10-07 12:39:58 +0000 | [diff] [blame] | 577 | struct fuse_context *c = fuse_get_context(); |
| 578 | |
| 579 | memset(c, 0, sizeof(*c)); |
| 580 | c->fuse = f; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 581 | |
| 582 | if (f->op.init) |
| 583 | f->user_data = f->op.init(); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void fuse_data_destroy(void *data) |
| 587 | { |
| 588 | struct fuse *f = (struct fuse *) data; |
Miklos Szeredi | 4f5df5e | 2005-10-07 12:39:58 +0000 | [diff] [blame] | 589 | struct fuse_context *c = fuse_get_context(); |
| 590 | |
| 591 | memset(c, 0, sizeof(*c)); |
| 592 | c->fuse = f; |
| 593 | c->private_data = f->user_data; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 594 | |
| 595 | if (f->op.destroy) |
| 596 | f->op.destroy(f->user_data); |
| 597 | } |
| 598 | |
| 599 | static void fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) |
| 600 | { |
| 601 | struct fuse *f = req_fuse_prepare(req); |
| 602 | struct fuse_entry_param e; |
| 603 | char *path; |
| 604 | int err; |
| 605 | |
| 606 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 607 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 608 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 609 | if (path != NULL) { |
| 610 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 611 | printf("LOOKUP %s\n", path); |
| 612 | fflush(stdout); |
| 613 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 614 | err = -ENOSYS; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 615 | if (f->op.getattr) { |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 616 | err = lookup_path(f, parent, name, path, &e, NULL); |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 617 | if (err == -ENOENT && f->negative_timeout != 0.0) { |
| 618 | e.ino = 0; |
| 619 | e.entry_timeout = f->negative_timeout; |
| 620 | err = 0; |
| 621 | } |
| 622 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 623 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 624 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 625 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 626 | reply_entry(req, &e, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 629 | 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] | 630 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 631 | struct fuse *f = req_fuse(req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 632 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 633 | printf("FORGET %llu/%lu\n", (unsigned long long) ino, nlookup); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 634 | fflush(stdout); |
| 635 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 636 | forget_node(f, ino, nlookup); |
| 637 | fuse_reply_none(req); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 640 | static void fuse_getattr(fuse_req_t req, fuse_ino_t ino, |
| 641 | struct fuse_file_info *fi) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 642 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 643 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 644 | struct stat buf; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 645 | char *path; |
| 646 | int err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 647 | |
Miklos Szeredi | ecce1bf | 2005-08-25 15:19:06 +0000 | [diff] [blame] | 648 | (void) fi; |
| 649 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 650 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 651 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 652 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 653 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 654 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 655 | if (f->op.getattr) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 656 | err = f->op.getattr(path, &buf); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 657 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 658 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 659 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 660 | if (!err) { |
| 661 | set_stat(f, ino, &buf); |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 662 | fuse_reply_attr(req, &buf, f->attr_timeout); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 663 | } else |
| 664 | reply_err(req, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 667 | static int do_chmod(struct fuse *f, const char *path, struct stat *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 668 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 669 | int err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 670 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 671 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 672 | if (f->op.chmod) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 673 | err = f->op.chmod(path, attr->st_mode); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 674 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 675 | return err; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 676 | } |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 677 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 678 | static int do_chown(struct fuse *f, const char *path, struct stat *attr, |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 679 | int valid) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 680 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 681 | int err; |
| 682 | uid_t uid = (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : (uid_t) -1; |
| 683 | 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] | 684 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 685 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 686 | if (f->op.chown) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 687 | err = f->op.chown(path, uid, gid); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 688 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 689 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Miklos Szeredi | 11509ce | 2005-10-26 16:04:04 +0000 | [diff] [blame] | 692 | static int do_truncate(struct fuse *f, const char *path, struct stat *attr, |
| 693 | struct fuse_file_info *fi) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 694 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 695 | int err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 696 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 697 | err = -ENOSYS; |
Miklos Szeredi | 11509ce | 2005-10-26 16:04:04 +0000 | [diff] [blame] | 698 | if (fi && f->op.ftruncate) |
| 699 | err = f->op.ftruncate(path, attr->st_size, fi); |
| 700 | else if (f->op.truncate) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 701 | err = f->op.truncate(path, attr->st_size); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 702 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 703 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 706 | static int do_utime(struct fuse *f, const char *path, struct stat *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 707 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 708 | int err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 709 | struct utimbuf buf; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 710 | buf.actime = attr->st_atime; |
| 711 | buf.modtime = attr->st_mtime; |
| 712 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 713 | if (f->op.utime) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 714 | err = f->op.utime(path, &buf); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 715 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 716 | return err; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 719 | 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] | 720 | int valid, struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 721 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 722 | struct fuse *f = req_fuse_prepare(req); |
| 723 | struct stat buf; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 724 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 725 | int err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 726 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 727 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 728 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 729 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 730 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 731 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 732 | if (f->op.getattr) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 733 | err = 0; |
| 734 | if (!err && (valid & FUSE_SET_ATTR_MODE)) |
| 735 | err = do_chmod(f, path, attr); |
| 736 | if (!err && (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))) |
| 737 | err = do_chown(f, path, attr, valid); |
| 738 | if (!err && (valid & FUSE_SET_ATTR_SIZE)) |
Miklos Szeredi | 11509ce | 2005-10-26 16:04:04 +0000 | [diff] [blame] | 739 | err = do_truncate(f, path, attr, fi); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 740 | if (!err && (valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) == (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) |
| 741 | err = do_utime(f, path, attr); |
| 742 | if (!err) |
| 743 | err = f->op.getattr(path, &buf); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 744 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 745 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 746 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 747 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 748 | if (!err) { |
| 749 | set_stat(f, ino, &buf); |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 750 | fuse_reply_attr(req, &buf, f->attr_timeout); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 751 | } else |
| 752 | reply_err(req, err); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 755 | static void fuse_access(fuse_req_t req, fuse_ino_t ino, int mask) |
| 756 | { |
| 757 | struct fuse *f = req_fuse_prepare(req); |
| 758 | char *path; |
| 759 | int err; |
| 760 | |
| 761 | err = -ENOENT; |
| 762 | pthread_rwlock_rdlock(&f->tree_lock); |
| 763 | path = get_path(f, ino); |
| 764 | if (path != NULL) { |
| 765 | if (f->flags & FUSE_DEBUG) { |
| 766 | printf("ACCESS %s 0%o\n", path, mask); |
| 767 | fflush(stdout); |
| 768 | } |
| 769 | err = -ENOSYS; |
| 770 | if (f->op.access) |
| 771 | err = f->op.access(path, mask); |
| 772 | free(path); |
| 773 | } |
| 774 | pthread_rwlock_unlock(&f->tree_lock); |
| 775 | reply_err(req, err); |
| 776 | } |
| 777 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 778 | static void fuse_readlink(fuse_req_t req, fuse_ino_t ino) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 779 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 780 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 781 | char linkname[PATH_MAX + 1]; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 782 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 783 | int err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 784 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 785 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 786 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 787 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 788 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 789 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 790 | if (f->op.readlink) |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 791 | err = f->op.readlink(path, linkname, sizeof(linkname)); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 792 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 793 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 794 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 795 | if (!err) { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 796 | linkname[PATH_MAX] = '\0'; |
| 797 | fuse_reply_readlink(req, linkname); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 798 | } else |
| 799 | reply_err(req, err); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 802 | static void fuse_mknod(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 803 | mode_t mode, dev_t rdev) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 804 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 805 | struct fuse *f = req_fuse_prepare(req); |
| 806 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 807 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 808 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 809 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 810 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 811 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 812 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 813 | if (path != NULL) { |
| 814 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 815 | printf("MKNOD %s\n", path); |
| 816 | fflush(stdout); |
| 817 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 818 | err = -ENOSYS; |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 819 | if (S_ISREG(mode) && f->op.create && f->op.getattr) { |
| 820 | struct fuse_file_info fi; |
| 821 | |
| 822 | memset(&fi, 0, sizeof(fi)); |
| 823 | fi.flags = O_CREAT | O_EXCL | O_WRONLY; |
| 824 | err = f->op.create(path, mode, &fi); |
| 825 | if (!err) { |
| 826 | err = lookup_path(f, parent, name, path, &e, &fi); |
| 827 | if (f->op.release) |
| 828 | f->op.release(path, &fi); |
| 829 | } |
| 830 | } else if (f->op.mknod && f->op.getattr) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 831 | err = f->op.mknod(path, mode, rdev); |
| 832 | if (!err) |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 833 | err = lookup_path(f, parent, name, path, &e, NULL); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 834 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 835 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 836 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 837 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 838 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 841 | static void fuse_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 842 | mode_t mode) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 843 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 844 | struct fuse *f = req_fuse_prepare(req); |
| 845 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 846 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 847 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 848 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 849 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 850 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 851 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 852 | if (path != NULL) { |
| 853 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 854 | printf("MKDIR %s\n", path); |
| 855 | fflush(stdout); |
| 856 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 857 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 858 | if (f->op.mkdir && f->op.getattr) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 859 | err = f->op.mkdir(path, mode); |
| 860 | if (!err) |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 861 | err = lookup_path(f, parent, name, path, &e, NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 862 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 863 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 864 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 865 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 866 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 869 | 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] | 870 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 871 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 872 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 873 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 874 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 875 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 876 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 877 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 878 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 879 | if (f->flags & FUSE_DEBUG) { |
| 880 | printf("UNLINK %s\n", path); |
| 881 | fflush(stdout); |
| 882 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 883 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 884 | if (f->op.unlink) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 885 | if (!(f->flags & FUSE_HARD_REMOVE) && is_open(f, parent, name)) |
| 886 | err = hide_node(f, path, parent, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 887 | else { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 888 | err = f->op.unlink(path); |
| 889 | if (!err) |
| 890 | remove_node(f, parent, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 891 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 892 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 893 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 894 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 895 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 896 | reply_err(req, err); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 899 | 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] | 900 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 901 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 902 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 903 | int err; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 904 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 905 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 906 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 907 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 908 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 909 | if (f->flags & FUSE_DEBUG) { |
| 910 | printf("RMDIR %s\n", path); |
| 911 | fflush(stdout); |
| 912 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 913 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 914 | if (f->op.rmdir) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 915 | err = f->op.rmdir(path); |
| 916 | if (!err) |
| 917 | remove_node(f, parent, name); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 918 | } |
| 919 | free(path); |
| 920 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 921 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 922 | reply_err(req, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 925 | static void fuse_symlink(fuse_req_t req, const char *linkname, |
| 926 | fuse_ino_t parent, const char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 927 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 928 | struct fuse *f = req_fuse_prepare(req); |
| 929 | struct fuse_entry_param e; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 930 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 931 | int err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 932 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 933 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 934 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 935 | path = get_path_name(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 936 | if (path != NULL) { |
| 937 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 938 | printf("SYMLINK %s\n", path); |
| 939 | fflush(stdout); |
| 940 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 941 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 942 | if (f->op.symlink && f->op.getattr) { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 943 | err = f->op.symlink(linkname, path); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 944 | if (!err) |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 945 | err = lookup_path(f, parent, name, path, &e, NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 946 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 947 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 948 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 949 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 950 | reply_entry(req, &e, err); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 953 | static void fuse_rename(fuse_req_t req, fuse_ino_t olddir, const char *oldname, |
| 954 | fuse_ino_t newdir, const char *newname) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 955 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 956 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 957 | char *oldpath; |
| 958 | char *newpath; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 959 | int err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 960 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 961 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 962 | pthread_rwlock_wrlock(&f->tree_lock); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 963 | oldpath = get_path_name(f, olddir, oldname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 964 | if (oldpath != NULL) { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 965 | newpath = get_path_name(f, newdir, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 966 | if (newpath != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 967 | if (f->flags & FUSE_DEBUG) { |
| 968 | printf("RENAME %s -> %s\n", oldpath, newpath); |
| 969 | fflush(stdout); |
| 970 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 971 | err = -ENOSYS; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 972 | if (f->op.rename) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 973 | err = 0; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 974 | if (!(f->flags & FUSE_HARD_REMOVE) && |
Miklos Szeredi | 2529ca2 | 2004-07-13 15:36:52 +0000 | [diff] [blame] | 975 | is_open(f, newdir, newname)) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 976 | err = hide_node(f, newpath, newdir, newname); |
| 977 | if (!err) { |
| 978 | err = f->op.rename(oldpath, newpath); |
| 979 | if (!err) |
| 980 | err = rename_node(f, olddir, oldname, newdir, newname, 0); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 981 | } |
| 982 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 983 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 984 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 985 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 986 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 987 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 988 | reply_err(req, err); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 991 | static void fuse_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, |
| 992 | const char *newname) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 993 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 994 | struct fuse *f = req_fuse_prepare(req); |
| 995 | struct fuse_entry_param e; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 996 | char *oldpath; |
| 997 | char *newpath; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 998 | int err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 999 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1000 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1001 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1002 | oldpath = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1003 | if (oldpath != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1004 | newpath = get_path_name(f, newparent, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1005 | if (newpath != NULL) { |
| 1006 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1007 | printf("LINK %s\n", newpath); |
| 1008 | fflush(stdout); |
| 1009 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1010 | err = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1011 | if (f->op.link && f->op.getattr) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1012 | err = f->op.link(oldpath, newpath); |
| 1013 | if (!err) |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 1014 | err = lookup_path(f, newparent, newname, newpath, &e, NULL); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1015 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1016 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1017 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1018 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1019 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1020 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1021 | reply_entry(req, &e, err); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1024 | static void fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name, |
| 1025 | mode_t mode, struct fuse_file_info *fi) |
| 1026 | { |
| 1027 | struct fuse *f = req_fuse_prepare(req); |
| 1028 | struct fuse_entry_param e; |
| 1029 | char *path; |
| 1030 | int err; |
| 1031 | |
| 1032 | err = -ENOENT; |
| 1033 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1034 | path = get_path_name(f, parent, name); |
| 1035 | if (path != NULL) { |
| 1036 | err = -ENOSYS; |
| 1037 | if (f->op.create && f->op.getattr) { |
| 1038 | err = f->op.create(path, mode, fi); |
| 1039 | if (!err) { |
| 1040 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1041 | printf("CREATE[%llu] flags: 0x%x %s\n", |
| 1042 | (unsigned long long) fi->fh, fi->flags, path); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1043 | fflush(stdout); |
| 1044 | } |
Miklos Szeredi | f7eec03 | 2005-10-28 13:09:50 +0000 | [diff] [blame] | 1045 | err = lookup_path(f, parent, name, path, &e, fi); |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1046 | if (err) { |
| 1047 | if (f->op.release) |
| 1048 | f->op.release(path, fi); |
| 1049 | } else if (!S_ISREG(e.attr.st_mode)) { |
| 1050 | err = -EIO; |
| 1051 | if (f->op.release) |
| 1052 | f->op.release(path, fi); |
| 1053 | forget_node(f, e.ino, 1); |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | if (!err) { |
| 1060 | if (f->flags & FUSE_DIRECT_IO) |
| 1061 | fi->direct_io = 1; |
| 1062 | if (f->flags & FUSE_KERNEL_CACHE) |
| 1063 | fi->keep_cache = 1; |
| 1064 | |
| 1065 | pthread_mutex_lock(&f->lock); |
| 1066 | if (fuse_reply_create(req, &e, fi) == -ENOENT) { |
| 1067 | /* The open syscall was interrupted, so it must be cancelled */ |
| 1068 | if(f->op.release) |
| 1069 | f->op.release(path, fi); |
| 1070 | forget_node(f, e.ino, 1); |
| 1071 | } else { |
| 1072 | struct node *node = get_node(f, e.ino); |
| 1073 | node->open_count ++; |
| 1074 | } |
| 1075 | pthread_mutex_unlock(&f->lock); |
| 1076 | } else |
| 1077 | reply_err(req, err); |
| 1078 | |
| 1079 | if (path) |
| 1080 | free(path); |
| 1081 | pthread_rwlock_unlock(&f->tree_lock); |
| 1082 | } |
| 1083 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1084 | static void fuse_open(fuse_req_t req, fuse_ino_t ino, |
| 1085 | struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1086 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1087 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 31066bb | 2005-08-01 14:49:31 +0000 | [diff] [blame] | 1088 | char *path = NULL; |
| 1089 | int err = 0; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1090 | |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1091 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | 31066bb | 2005-08-01 14:49:31 +0000 | [diff] [blame] | 1092 | if (f->op.open) { |
| 1093 | err = -ENOENT; |
| 1094 | path = get_path(f, ino); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1095 | if (path != NULL) |
| 1096 | err = fuse_do_open(f, path, fi); |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 1097 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1098 | if (!err) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1099 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1100 | printf("OPEN[%llu] flags: 0x%x\n", (unsigned long long) fi->fh, |
| 1101 | fi->flags); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1102 | fflush(stdout); |
| 1103 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1104 | |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 1105 | if (f->flags & FUSE_DIRECT_IO) |
| 1106 | fi->direct_io = 1; |
| 1107 | if (f->flags & FUSE_KERNEL_CACHE) |
| 1108 | fi->keep_cache = 1; |
| 1109 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1110 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1111 | if (fuse_reply_open(req, fi) == -ENOENT) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1112 | /* The open syscall was interrupted, so it must be cancelled */ |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1113 | if(f->op.release && path != NULL) |
| 1114 | fuse_do_release(f, path, fi); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1115 | } else { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1116 | struct node *node = get_node(f, ino); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1117 | node->open_count ++; |
| 1118 | } |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1119 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1120 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1121 | reply_err(req, err); |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1122 | |
Miklos Szeredi | 9a31cca | 2004-06-26 21:11:25 +0000 | [diff] [blame] | 1123 | if (path) |
| 1124 | free(path); |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1125 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1128 | static void fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, |
| 1129 | struct fuse_file_info *fi) |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1130 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1131 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1132 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1133 | char *buf; |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1134 | int res; |
| 1135 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1136 | buf = (char *) malloc(size); |
| 1137 | if (buf == NULL) { |
| 1138 | reply_err(req, -ENOMEM); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1142 | res = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1143 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1144 | path = get_path(f, ino); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1145 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1146 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1147 | printf("READ[%llu] %u bytes from %llu\n", |
| 1148 | (unsigned long long) fi->fh, size, off); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1149 | fflush(stdout); |
| 1150 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1151 | |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1152 | res = -ENOSYS; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1153 | if (f->op.read) |
| 1154 | res = f->op.read(path, buf, size, off, fi); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1155 | free(path); |
| 1156 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1157 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1158 | |
| 1159 | if (res >= 0) { |
| 1160 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1161 | printf(" READ[%llu] %u bytes\n", (unsigned long long) fi->fh, |
| 1162 | res); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1163 | fflush(stdout); |
| 1164 | } |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1165 | if ((size_t) res > size) |
| 1166 | fprintf(stderr, "fuse: read too many bytes"); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1167 | fuse_reply_buf(req, buf, res); |
| 1168 | } else |
| 1169 | reply_err(req, res); |
| 1170 | |
| 1171 | free(buf); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1174 | static void fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf, |
| 1175 | size_t size, off_t off, struct fuse_file_info *fi) |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1176 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1177 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1178 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1179 | int res; |
| 1180 | |
| 1181 | res = -ENOENT; |
| 1182 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1183 | path = get_path(f, ino); |
| 1184 | if (path != NULL) { |
| 1185 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1186 | printf("WRITE%s[%llu] %u bytes to %llu\n", |
| 1187 | fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, |
| 1188 | size, off); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1189 | fflush(stdout); |
| 1190 | } |
| 1191 | |
| 1192 | res = -ENOSYS; |
| 1193 | if (f->op.write) |
| 1194 | res = f->op.write(path, buf, size, off, fi); |
| 1195 | free(path); |
| 1196 | } |
| 1197 | pthread_rwlock_unlock(&f->tree_lock); |
| 1198 | |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1199 | if (res >= 0) { |
| 1200 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1201 | printf(" WRITE%s[%llu] %u bytes\n", |
| 1202 | fi->writepage ? "PAGE" : "", (unsigned long long) fi->fh, |
| 1203 | res); |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1204 | fflush(stdout); |
| 1205 | } |
| 1206 | if ((size_t) res > size) |
| 1207 | fprintf(stderr, "fuse: wrote too many bytes"); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1208 | fuse_reply_write(req, res); |
Miklos Szeredi | f412d07 | 2005-10-14 21:24:32 +0000 | [diff] [blame] | 1209 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1210 | reply_err(req, res); |
| 1211 | } |
| 1212 | |
| 1213 | static void fuse_flush(fuse_req_t req, fuse_ino_t ino, |
| 1214 | struct fuse_file_info *fi) |
| 1215 | { |
| 1216 | struct fuse *f = req_fuse_prepare(req); |
| 1217 | char *path; |
| 1218 | int err; |
| 1219 | |
| 1220 | err = -ENOENT; |
| 1221 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1222 | path = get_path(f, ino); |
| 1223 | if (path != NULL) { |
| 1224 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1225 | printf("FLUSH[%llu]\n", (unsigned long long) fi->fh); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1226 | fflush(stdout); |
| 1227 | } |
| 1228 | err = -ENOSYS; |
| 1229 | if (f->op.flush) |
| 1230 | err = f->op.flush(path, fi); |
| 1231 | free(path); |
| 1232 | } |
| 1233 | pthread_rwlock_unlock(&f->tree_lock); |
| 1234 | reply_err(req, err); |
| 1235 | } |
| 1236 | |
| 1237 | static void fuse_release(fuse_req_t req, fuse_ino_t ino, |
| 1238 | struct fuse_file_info *fi) |
| 1239 | { |
| 1240 | struct fuse *f = req_fuse_prepare(req); |
| 1241 | char *path; |
| 1242 | struct node *node; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1243 | int unlink_hidden; |
Miklos Szeredi | fb28c5e | 2004-11-26 12:15:06 +0000 | [diff] [blame] | 1244 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1245 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1246 | node = get_node(f, ino); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1247 | assert(node->open_count > 0); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1248 | --node->open_count; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1249 | unlink_hidden = (node->is_hidden && !node->open_count); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1250 | pthread_mutex_unlock(&f->lock); |
| 1251 | |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1252 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1253 | path = get_path(f, ino); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1254 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1255 | printf("RELEASE[%llu] flags: 0x%x\n", (unsigned long long) fi->fh, |
| 1256 | fi->flags); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1257 | fflush(stdout); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1258 | } |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1259 | if (f->op.release) |
| 1260 | fuse_do_release(f, path, fi); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1261 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1262 | if(unlink_hidden && path) |
| 1263 | f->op.unlink(path); |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1264 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1265 | if (path) |
| 1266 | free(path); |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1267 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1268 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1269 | reply_err(req, 0); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1272 | static void fuse_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, |
| 1273 | struct fuse_file_info *fi) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1274 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1275 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1276 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1277 | int err; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1278 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1279 | err = -ENOENT; |
| 1280 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1281 | path = get_path(f, ino); |
| 1282 | if (path != NULL) { |
| 1283 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1284 | printf("FSYNC[%llu]\n", (unsigned long long) fi->fh); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1285 | fflush(stdout); |
| 1286 | } |
| 1287 | err = -ENOSYS; |
| 1288 | if (f->op.fsync) |
| 1289 | err = f->op.fsync(path, datasync, fi); |
| 1290 | free(path); |
| 1291 | } |
| 1292 | pthread_rwlock_unlock(&f->tree_lock); |
| 1293 | reply_err(req, err); |
| 1294 | } |
| 1295 | |
| 1296 | static struct fuse_dirhandle *get_dirhandle(const struct fuse_file_info *llfi, |
| 1297 | struct fuse_file_info *fi) |
| 1298 | { |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1299 | struct fuse_dirhandle *dh = (struct fuse_dirhandle *) (uintptr_t) llfi->fh; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1300 | memset(fi, 0, sizeof(struct fuse_file_info)); |
| 1301 | fi->fh = dh->fh; |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 1302 | fi->fh_old = dh->fh; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1303 | return dh; |
| 1304 | } |
| 1305 | |
| 1306 | static void fuse_opendir(fuse_req_t req, fuse_ino_t ino, |
| 1307 | struct fuse_file_info *llfi) |
| 1308 | { |
| 1309 | struct fuse *f = req_fuse_prepare(req); |
| 1310 | struct fuse_dirhandle *dh; |
| 1311 | |
| 1312 | dh = (struct fuse_dirhandle *) malloc(sizeof(struct fuse_dirhandle)); |
| 1313 | if (dh == NULL) { |
| 1314 | reply_err(req, -ENOMEM); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1315 | return; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1316 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1317 | memset(dh, 0, sizeof(struct fuse_dirhandle)); |
| 1318 | dh->fuse = f; |
| 1319 | dh->contents = NULL; |
| 1320 | dh->len = 0; |
| 1321 | dh->filled = 0; |
| 1322 | dh->nodeid = ino; |
| 1323 | mutex_init(&dh->lock); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1324 | |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 1325 | llfi->fh = (uintptr_t) dh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1326 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1327 | if (f->op.opendir) { |
| 1328 | struct fuse_file_info fi; |
| 1329 | char *path; |
| 1330 | int err; |
| 1331 | |
| 1332 | memset(&fi, 0, sizeof(fi)); |
| 1333 | fi.flags = llfi->flags; |
| 1334 | |
| 1335 | err = -ENOENT; |
| 1336 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1337 | path = get_path(f, ino); |
| 1338 | if (path != NULL) { |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1339 | err = fuse_do_opendir(f, path, &fi); |
| 1340 | dh->fh = fi.fh; |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1341 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1342 | if (!err) { |
| 1343 | pthread_mutex_lock(&f->lock); |
| 1344 | if (fuse_reply_open(req, llfi) == -ENOENT) { |
| 1345 | /* The opendir syscall was interrupted, so it must be |
| 1346 | cancelled */ |
| 1347 | if(f->op.releasedir) |
| 1348 | f->op.releasedir(path, &fi); |
| 1349 | pthread_mutex_destroy(&dh->lock); |
| 1350 | free(dh); |
| 1351 | } |
| 1352 | pthread_mutex_unlock(&f->lock); |
| 1353 | } else { |
| 1354 | reply_err(req, err); |
| 1355 | free(dh); |
| 1356 | } |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1357 | free(path); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1358 | pthread_rwlock_unlock(&f->tree_lock); |
| 1359 | } else |
| 1360 | fuse_reply_open(req, llfi); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1361 | } |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1362 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1363 | static int fill_dir_common(struct fuse_dirhandle *dh, const char *name, |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1364 | const struct stat *statp, off_t off) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1365 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1366 | struct stat stbuf; |
| 1367 | unsigned namelen = strlen(name); |
| 1368 | unsigned entsize; |
| 1369 | unsigned newlen; |
Miklos Szeredi | fb28c5e | 2004-11-26 12:15:06 +0000 | [diff] [blame] | 1370 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1371 | if (statp) |
| 1372 | stbuf = *statp; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1373 | else { |
| 1374 | memset(&stbuf, 0, sizeof(stbuf)); |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1375 | stbuf.st_ino = (ino_t) -1; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1376 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1377 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1378 | if (!(dh->fuse->flags & FUSE_USE_INO)) { |
| 1379 | stbuf.st_ino = (ino_t) -1; |
| 1380 | if (dh->fuse->flags & FUSE_READDIR_INO) { |
| 1381 | struct node *node; |
| 1382 | pthread_mutex_lock(&dh->fuse->lock); |
| 1383 | node = lookup_node(dh->fuse, dh->nodeid, name); |
| 1384 | if (node) |
| 1385 | stbuf.st_ino = (ino_t) node->nodeid; |
| 1386 | pthread_mutex_unlock(&dh->fuse->lock); |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1387 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1388 | } |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1389 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1390 | entsize = fuse_dirent_size(namelen); |
| 1391 | newlen = dh->len + entsize; |
| 1392 | |
| 1393 | if (off) { |
| 1394 | dh->filled = 0; |
| 1395 | if (newlen > dh->needlen) |
| 1396 | return 1; |
| 1397 | } |
| 1398 | |
Miklos Szeredi | c4c12ae | 2005-10-20 14:48:50 +0000 | [diff] [blame] | 1399 | if (newlen > dh->size) { |
| 1400 | char *newptr; |
| 1401 | |
| 1402 | if (!dh->size) |
| 1403 | dh->size = 1024; |
| 1404 | while (newlen > dh->size) |
| 1405 | dh->size *= 2; |
| 1406 | |
| 1407 | newptr = (char *) realloc(dh->contents, dh->size); |
| 1408 | if (!newptr) { |
| 1409 | dh->error = -ENOMEM; |
| 1410 | return 1; |
| 1411 | } |
| 1412 | dh->contents = newptr; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1413 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1414 | fuse_add_dirent(dh->contents + dh->len, name, &stbuf, off ? off : newlen); |
| 1415 | dh->len = newlen; |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1419 | 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] | 1420 | off_t off) |
| 1421 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 1422 | return fill_dir_common((struct fuse_dirhandle *) buf, name, stbuf, off); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | static int fill_dir_old(struct fuse_dirhandle *dh, const char *name, int type, |
| 1426 | ino_t ino) |
| 1427 | { |
| 1428 | struct stat stbuf; |
| 1429 | |
| 1430 | memset(&stbuf, 0, sizeof(stbuf)); |
| 1431 | stbuf.st_mode = type << 12; |
| 1432 | stbuf.st_ino = ino; |
| 1433 | |
| 1434 | fill_dir_common(dh, name, &stbuf, 0); |
| 1435 | return dh->error; |
| 1436 | } |
| 1437 | |
| 1438 | static int readdir_fill(struct fuse *f, fuse_ino_t ino, size_t size, |
| 1439 | off_t off, struct fuse_dirhandle *dh, |
| 1440 | struct fuse_file_info *fi) |
| 1441 | { |
| 1442 | int err = -ENOENT; |
| 1443 | char *path; |
| 1444 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1445 | path = get_path(f, ino); |
| 1446 | if (path != NULL) { |
| 1447 | dh->len = 0; |
| 1448 | dh->error = 0; |
| 1449 | dh->needlen = size; |
| 1450 | dh->filled = 1; |
| 1451 | err = -ENOSYS; |
| 1452 | if (f->op.readdir) |
| 1453 | err = f->op.readdir(path, dh, fill_dir, off, fi); |
| 1454 | else if (f->op.getdir) |
| 1455 | err = f->op.getdir(path, dh, fill_dir_old); |
| 1456 | if (!err) |
| 1457 | err = dh->error; |
| 1458 | if (err) |
| 1459 | dh->filled = 0; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1460 | free(path); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1461 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1462 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1463 | return err; |
| 1464 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1465 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1466 | static void fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, |
| 1467 | off_t off, struct fuse_file_info *llfi) |
| 1468 | { |
| 1469 | struct fuse *f = req_fuse_prepare(req); |
| 1470 | struct fuse_file_info fi; |
| 1471 | struct fuse_dirhandle *dh = get_dirhandle(llfi, &fi); |
| 1472 | |
| 1473 | pthread_mutex_lock(&dh->lock); |
Miklos Szeredi | 77ccf65 | 2005-08-19 14:40:27 +0000 | [diff] [blame] | 1474 | /* According to SUS, directory contents need to be refreshed on |
| 1475 | rewinddir() */ |
| 1476 | if (!off) |
| 1477 | dh->filled = 0; |
| 1478 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1479 | if (!dh->filled) { |
| 1480 | int err = readdir_fill(f, ino, size, off, dh, &fi); |
| 1481 | if (err) { |
| 1482 | reply_err(req, err); |
| 1483 | goto out; |
| 1484 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1485 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1486 | if (dh->filled) { |
| 1487 | if (off < dh->len) { |
| 1488 | if (off + size > dh->len) |
| 1489 | size = dh->len - off; |
| 1490 | } else |
| 1491 | size = 0; |
| 1492 | } else { |
| 1493 | size = dh->len; |
| 1494 | off = 0; |
| 1495 | } |
| 1496 | fuse_reply_buf(req, dh->contents + off, size); |
| 1497 | out: |
| 1498 | pthread_mutex_unlock(&dh->lock); |
| 1499 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1500 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1501 | static void fuse_releasedir(fuse_req_t req, fuse_ino_t ino, |
| 1502 | struct fuse_file_info *llfi) |
| 1503 | { |
| 1504 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 1505 | struct fuse_file_info fi; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1506 | struct fuse_dirhandle *dh = get_dirhandle(llfi, &fi); |
| 1507 | if (f->op.releasedir) { |
| 1508 | char *path; |
| 1509 | |
| 1510 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1511 | path = get_path(f, ino); |
| 1512 | f->op.releasedir(path ? path : "-", &fi); |
| 1513 | free(path); |
| 1514 | pthread_rwlock_unlock(&f->tree_lock); |
| 1515 | } |
| 1516 | pthread_mutex_lock(&dh->lock); |
| 1517 | pthread_mutex_unlock(&dh->lock); |
| 1518 | pthread_mutex_destroy(&dh->lock); |
| 1519 | free(dh->contents); |
| 1520 | free(dh); |
| 1521 | reply_err(req, 0); |
| 1522 | } |
| 1523 | |
| 1524 | static void fuse_fsyncdir(fuse_req_t req, fuse_ino_t ino, int datasync, |
| 1525 | struct fuse_file_info *llfi) |
| 1526 | { |
| 1527 | struct fuse *f = req_fuse_prepare(req); |
| 1528 | struct fuse_file_info fi; |
| 1529 | char *path; |
| 1530 | int err; |
| 1531 | |
| 1532 | get_dirhandle(llfi, &fi); |
| 1533 | |
| 1534 | err = -ENOENT; |
| 1535 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1536 | path = get_path(f, ino); |
| 1537 | if (path != NULL) { |
| 1538 | err = -ENOSYS; |
| 1539 | if (f->op.fsyncdir) |
| 1540 | err = f->op.fsyncdir(path, datasync, &fi); |
| 1541 | free(path); |
| 1542 | } |
| 1543 | pthread_rwlock_unlock(&f->tree_lock); |
| 1544 | reply_err(req, err); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1547 | static int default_statfs(struct statvfs *buf) |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1548 | { |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1549 | buf->f_namemax = 255; |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1550 | buf->f_bsize = 512; |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1554 | static void fuse_statfs(fuse_req_t req) |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 1555 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1556 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1557 | struct statvfs buf; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1558 | int err; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1559 | |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1560 | memset(&buf, 0, sizeof(buf)); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1561 | if (f->op.statfs) { |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 1562 | err = fuse_do_statfs(f, "/", &buf); |
Miklos Szeredi | 52cb09d | 2005-11-07 11:59:00 +0000 | [diff] [blame] | 1563 | } else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1564 | err = default_statfs(&buf); |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1565 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1566 | if (!err) |
| 1567 | fuse_reply_statfs(req, &buf); |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1568 | else |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1569 | reply_err(req, err); |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1572 | static void fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, |
| 1573 | const char *value, size_t size, int flags) |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1574 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1575 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1576 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1577 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1578 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1579 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1580 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1581 | path = get_path(f, ino); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1582 | if (path != NULL) { |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1583 | err = -ENOSYS; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1584 | if (f->op.setxattr) |
| 1585 | err = f->op.setxattr(path, name, value, size, flags); |
| 1586 | free(path); |
| 1587 | } |
| 1588 | pthread_rwlock_unlock(&f->tree_lock); |
| 1589 | reply_err(req, err); |
| 1590 | } |
| 1591 | |
| 1592 | static int common_getxattr(struct fuse *f, fuse_ino_t ino, const char *name, |
| 1593 | char *value, size_t size) |
| 1594 | { |
| 1595 | int err; |
| 1596 | char *path; |
| 1597 | |
| 1598 | err = -ENOENT; |
| 1599 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1600 | path = get_path(f, ino); |
| 1601 | if (path != NULL) { |
| 1602 | err = -ENOSYS; |
| 1603 | if (f->op.getxattr) |
| 1604 | err = f->op.getxattr(path, name, value, size); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1605 | free(path); |
| 1606 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1607 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1608 | return err; |
| 1609 | } |
| 1610 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1611 | static void fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, |
| 1612 | size_t size) |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 1613 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1614 | struct fuse *f = req_fuse_prepare(req); |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1615 | int res; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1616 | |
| 1617 | if (size) { |
| 1618 | char *value = (char *) malloc(size); |
| 1619 | if (value == NULL) { |
| 1620 | reply_err(req, -ENOMEM); |
| 1621 | return; |
| 1622 | } |
| 1623 | res = common_getxattr(f, ino, name, value, size); |
| 1624 | if (res > 0) |
| 1625 | fuse_reply_buf(req, value, res); |
| 1626 | else |
| 1627 | reply_err(req, res); |
| 1628 | free(value); |
| 1629 | } else { |
| 1630 | res = common_getxattr(f, ino, name, NULL, 0); |
| 1631 | if (res >= 0) |
| 1632 | fuse_reply_xattr(req, res); |
| 1633 | else |
| 1634 | reply_err(req, res); |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | static int common_listxattr(struct fuse *f, fuse_ino_t ino, char *list, |
| 1639 | size_t size) |
| 1640 | { |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1641 | char *path; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1642 | int err; |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1643 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1644 | err = -ENOENT; |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1645 | pthread_rwlock_rdlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1646 | path = get_path(f, ino); |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1647 | if (path != NULL) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1648 | err = -ENOSYS; |
| 1649 | if (f->op.listxattr) |
| 1650 | err = f->op.listxattr(path, list, size); |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1651 | free(path); |
| 1652 | } |
Miklos Szeredi | c2a33ee | 2005-05-09 13:29:17 +0000 | [diff] [blame] | 1653 | pthread_rwlock_unlock(&f->tree_lock); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1654 | return err; |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1655 | } |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 1656 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1657 | 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] | 1658 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1659 | struct fuse *f = req_fuse_prepare(req); |
| 1660 | int res; |
| 1661 | |
| 1662 | if (size) { |
| 1663 | char *list = (char *) malloc(size); |
| 1664 | if (list == NULL) { |
| 1665 | reply_err(req, -ENOMEM); |
| 1666 | return; |
| 1667 | } |
| 1668 | res = common_listxattr(f, ino, list, size); |
| 1669 | if (res > 0) |
| 1670 | fuse_reply_buf(req, list, res); |
| 1671 | else |
| 1672 | reply_err(req, res); |
| 1673 | free(list); |
| 1674 | } else { |
| 1675 | res = common_listxattr(f, ino, NULL, 0); |
| 1676 | if (res >= 0) |
| 1677 | fuse_reply_xattr(req, res); |
| 1678 | else |
| 1679 | reply_err(req, res); |
| 1680 | } |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1683 | static void fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *name) |
| 1684 | { |
| 1685 | struct fuse *f = req_fuse_prepare(req); |
| 1686 | char *path; |
| 1687 | int err; |
| 1688 | |
| 1689 | err = -ENOENT; |
| 1690 | pthread_rwlock_rdlock(&f->tree_lock); |
| 1691 | path = get_path(f, ino); |
| 1692 | if (path != NULL) { |
| 1693 | err = -ENOSYS; |
| 1694 | if (f->op.removexattr) |
| 1695 | err = f->op.removexattr(path, name); |
| 1696 | free(path); |
| 1697 | } |
| 1698 | pthread_rwlock_unlock(&f->tree_lock); |
| 1699 | reply_err(req, err); |
| 1700 | } |
| 1701 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1702 | static struct fuse_lowlevel_ops fuse_path_ops = { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1703 | .init = fuse_data_init, |
| 1704 | .destroy = fuse_data_destroy, |
| 1705 | .lookup = fuse_lookup, |
| 1706 | .forget = fuse_forget, |
| 1707 | .getattr = fuse_getattr, |
| 1708 | .setattr = fuse_setattr, |
Miklos Szeredi | b0b13d1 | 2005-10-26 12:53:25 +0000 | [diff] [blame] | 1709 | .access = fuse_access, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1710 | .readlink = fuse_readlink, |
| 1711 | .mknod = fuse_mknod, |
| 1712 | .mkdir = fuse_mkdir, |
| 1713 | .unlink = fuse_unlink, |
| 1714 | .rmdir = fuse_rmdir, |
| 1715 | .symlink = fuse_symlink, |
| 1716 | .rename = fuse_rename, |
| 1717 | .link = fuse_link, |
Miklos Szeredi | d9079a7 | 2005-10-26 15:29:06 +0000 | [diff] [blame] | 1718 | .create = fuse_create, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1719 | .open = fuse_open, |
| 1720 | .read = fuse_read, |
| 1721 | .write = fuse_write, |
| 1722 | .flush = fuse_flush, |
| 1723 | .release = fuse_release, |
| 1724 | .fsync = fuse_fsync, |
| 1725 | .opendir = fuse_opendir, |
| 1726 | .readdir = fuse_readdir, |
| 1727 | .releasedir = fuse_releasedir, |
| 1728 | .fsyncdir = fuse_fsyncdir, |
| 1729 | .statfs = fuse_statfs, |
| 1730 | .setxattr = fuse_setxattr, |
| 1731 | .getxattr = fuse_getxattr, |
| 1732 | .listxattr = fuse_listxattr, |
| 1733 | .removexattr = fuse_removexattr, |
| 1734 | }; |
| 1735 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1736 | static void free_cmd(struct fuse_cmd *cmd) |
| 1737 | { |
| 1738 | free(cmd->buf); |
| 1739 | free(cmd); |
| 1740 | } |
| 1741 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 1742 | void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1743 | { |
Miklos Szeredi | 178451d | 2005-08-15 13:19:07 +0000 | [diff] [blame] | 1744 | fuse_session_process(f->se, cmd->buf, cmd->buflen, cmd->ch); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1747 | int fuse_exited(struct fuse *f) |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1748 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1749 | return fuse_session_exited(f->se); |
| 1750 | } |
| 1751 | |
| 1752 | struct fuse_session *fuse_get_session(struct fuse *f) |
| 1753 | { |
| 1754 | return f->se; |
| 1755 | } |
| 1756 | |
| 1757 | static struct fuse_cmd *fuse_alloc_cmd(size_t bufsize) |
| 1758 | { |
| 1759 | struct fuse_cmd *cmd = (struct fuse_cmd *) malloc(sizeof(*cmd)); |
| 1760 | if (cmd == NULL) { |
| 1761 | fprintf(stderr, "fuse: failed to allocate cmd\n"); |
| 1762 | return NULL; |
| 1763 | } |
| 1764 | cmd->buf = (char *) malloc(bufsize); |
| 1765 | if (cmd->buf == NULL) { |
| 1766 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 1767 | free(cmd); |
| 1768 | return NULL; |
| 1769 | } |
| 1770 | return cmd; |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 1773 | struct fuse_cmd *fuse_read_cmd(struct fuse *f) |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1774 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1775 | struct fuse_chan *ch = fuse_session_next_chan(f->se, NULL); |
| 1776 | size_t bufsize = fuse_chan_bufsize(ch); |
| 1777 | struct fuse_cmd *cmd = fuse_alloc_cmd(bufsize); |
| 1778 | if (cmd != NULL) { |
| 1779 | int res = fuse_chan_receive(ch, cmd->buf, bufsize); |
| 1780 | if (res <= 0) { |
| 1781 | free_cmd(cmd); |
| 1782 | return NULL; |
| 1783 | } |
| 1784 | cmd->buflen = res; |
Miklos Szeredi | 178451d | 2005-08-15 13:19:07 +0000 | [diff] [blame] | 1785 | cmd->ch = ch; |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1786 | } |
| 1787 | return cmd; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1790 | int fuse_loop(struct fuse *f) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1791 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1792 | if (f) |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1793 | return fuse_session_loop(f->se); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1794 | else |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1795 | return -1; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1798 | int fuse_invalidate(struct fuse *f, const char *path) |
| 1799 | { |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1800 | (void) f; |
| 1801 | (void) path; |
| 1802 | return -EINVAL; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1805 | void fuse_exit(struct fuse *f) |
| 1806 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1807 | fuse_session_exit(f->se); |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1810 | struct fuse_context *fuse_get_context() |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1811 | { |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1812 | static struct fuse_context context; |
| 1813 | if (fuse_getcontext) |
| 1814 | return fuse_getcontext(); |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1815 | else |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1816 | return &context; |
| 1817 | } |
| 1818 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 1819 | void fuse_set_getcontext_func(struct fuse_context *(*func)(void)) |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1820 | { |
| 1821 | fuse_getcontext = func; |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 1824 | static int begins_with(const char *s, const char *beg) |
| 1825 | { |
| 1826 | if (strncmp(s, beg, strlen(beg)) == 0) |
| 1827 | return 1; |
| 1828 | else |
| 1829 | return 0; |
| 1830 | } |
| 1831 | |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1832 | int fuse_is_lib_option(const char *opt) |
| 1833 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1834 | if (fuse_lowlevel_is_lib_option(opt) || |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1835 | strcmp(opt, "debug") == 0 || |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1836 | strcmp(opt, "hard_remove") == 0 || |
Miklos Szeredi | 0111f9d | 2005-04-22 12:04:55 +0000 | [diff] [blame] | 1837 | strcmp(opt, "use_ino") == 0 || |
Miklos Szeredi | 33be22d | 2005-05-27 09:12:43 +0000 | [diff] [blame] | 1838 | strcmp(opt, "allow_root") == 0 || |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 1839 | strcmp(opt, "readdir_ino") == 0 || |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 1840 | strcmp(opt, "direct_io") == 0 || |
| 1841 | strcmp(opt, "kernel_cache") == 0 || |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 1842 | begins_with(opt, "umask=") || |
| 1843 | begins_with(opt, "uid=") || |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 1844 | begins_with(opt, "gid=") || |
| 1845 | begins_with(opt, "entry_timeout=") || |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 1846 | begins_with(opt, "attr_timeout=") || |
| 1847 | begins_with(opt, "negative_timeout=")) |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1848 | return 1; |
| 1849 | else |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1853 | static int parse_lib_opts(struct fuse *f, const char *opts, char **llopts) |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1854 | { |
| 1855 | if (opts) { |
| 1856 | char *xopts = strdup(opts); |
| 1857 | char *s = xopts; |
| 1858 | char *opt; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1859 | char *d = xopts; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1860 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1861 | if (xopts == NULL) { |
| 1862 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1863 | return -1; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1864 | } |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1865 | |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1866 | while((opt = strsep(&s, ","))) { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1867 | if (fuse_lowlevel_is_lib_option(opt)) { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1868 | size_t optlen = strlen(opt); |
| 1869 | if (strcmp(opt, "debug") == 0) |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 1870 | f->flags |= FUSE_DEBUG; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1871 | memmove(d, opt, optlen); |
| 1872 | d += optlen; |
| 1873 | *d++ = ','; |
| 1874 | } else if (strcmp(opt, "hard_remove") == 0) |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1875 | f->flags |= FUSE_HARD_REMOVE; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1876 | else if (strcmp(opt, "use_ino") == 0) |
| 1877 | f->flags |= FUSE_USE_INO; |
Miklos Szeredi | 33be22d | 2005-05-27 09:12:43 +0000 | [diff] [blame] | 1878 | else if (strcmp(opt, "readdir_ino") == 0) |
| 1879 | f->flags |= FUSE_READDIR_INO; |
Miklos Szeredi | e77cc07 | 2005-08-01 11:58:51 +0000 | [diff] [blame] | 1880 | else if (strcmp(opt, "direct_io") == 0) |
| 1881 | f->flags |= FUSE_DIRECT_IO; |
| 1882 | else if (strcmp(opt, "kernel_cache") == 0) |
| 1883 | f->flags |= FUSE_KERNEL_CACHE; |
Miklos Szeredi | e331c4b | 2005-07-06 13:34:02 +0000 | [diff] [blame] | 1884 | else if (sscanf(opt, "umask=%o", &f->umask) == 1) |
| 1885 | f->flags |= FUSE_SET_MODE; |
| 1886 | else if (sscanf(opt, "uid=%u", &f->uid) == 1) |
| 1887 | f->flags |= FUSE_SET_UID; |
| 1888 | else if(sscanf(opt, "gid=%u", &f->gid) == 1) |
| 1889 | f->flags |= FUSE_SET_GID; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 1890 | else if (sscanf(opt, "entry_timeout=%lf", &f->entry_timeout) == 1) |
| 1891 | /* nop */; |
| 1892 | else if (sscanf(opt, "attr_timeout=%lf", &f->attr_timeout) == 1) |
| 1893 | /* nop */; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 1894 | else if (sscanf(opt, "negative_timeout=%lf", |
| 1895 | &f->negative_timeout) == 1) |
| 1896 | /* nop */; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 1897 | else |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1898 | fprintf(stderr, "fuse: warning: unknown option `%s'\n", opt); |
| 1899 | } |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1900 | if (d != xopts) { |
| 1901 | d[-1] = '\0'; |
| 1902 | *llopts = xopts; |
| 1903 | } |
| 1904 | else |
| 1905 | free(xopts); |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1906 | } |
Miklos Szeredi | b3f9972 | 2005-11-16 13:00:24 +0000 | [diff] [blame] | 1907 | #ifdef __FreeBSD__ |
| 1908 | /* |
| 1909 | * In FreeBSD, we always use these settings as inode numbers are needed to |
| 1910 | * make getcwd(3) work. |
| 1911 | */ |
| 1912 | f->flags |= FUSE_READDIR_INO; |
| 1913 | #endif |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1914 | return 0; |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 1917 | struct fuse *fuse_new_common(int fd, const char *opts, |
| 1918 | const struct fuse_operations *op, |
| 1919 | size_t op_size, int compat) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1920 | { |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1921 | struct fuse_chan *ch; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1922 | struct fuse *f; |
| 1923 | struct node *root; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1924 | char *llopts = NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1925 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1926 | if (sizeof(struct fuse_operations) < op_size) { |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 1927 | 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] | 1928 | op_size = sizeof(struct fuse_operations); |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1931 | f = (struct fuse *) calloc(1, sizeof(struct fuse)); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1932 | if (f == NULL) { |
| 1933 | fprintf(stderr, "fuse: failed to allocate fuse object\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1934 | goto out; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1935 | } |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1936 | |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 1937 | f->entry_timeout = 1.0; |
| 1938 | f->attr_timeout = 1.0; |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 1939 | f->negative_timeout = 0.0; |
Miklos Szeredi | 6c0209a | 2005-08-02 13:31:28 +0000 | [diff] [blame] | 1940 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1941 | if (parse_lib_opts(f, opts, &llopts) == -1) |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1942 | goto out_free; |
| 1943 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1944 | f->se = fuse_lowlevel_new(llopts, &fuse_path_ops, sizeof(fuse_path_ops), f); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1945 | free(llopts); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1946 | if (f->se == NULL) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1947 | goto out_free; |
Miklos Szeredi | 2bb750e | 2005-10-03 14:54:24 +0000 | [diff] [blame] | 1948 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1949 | ch = fuse_kern_chan_new(fd); |
| 1950 | if (ch == NULL) |
| 1951 | goto out_free_session; |
Miklos Szeredi | 2bb750e | 2005-10-03 14:54:24 +0000 | [diff] [blame] | 1952 | |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1953 | fuse_session_add_chan(f->se, ch); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1954 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1955 | f->ctr = 0; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1956 | f->generation = 0; |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1957 | /* FIXME: Dynamic hash table */ |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1958 | f->name_table_size = 14057; |
| 1959 | f->name_table = (struct node **) |
| 1960 | calloc(1, sizeof(struct node *) * f->name_table_size); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1961 | if (f->name_table == NULL) { |
| 1962 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1963 | goto out_free_session; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1964 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1965 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1966 | f->id_table_size = 14057; |
| 1967 | f->id_table = (struct node **) |
| 1968 | calloc(1, sizeof(struct node *) * f->id_table_size); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1969 | if (f->id_table == NULL) { |
| 1970 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1971 | goto out_free_name_table; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1972 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1973 | |
Miklos Szeredi | ab97456 | 2005-04-07 15:40:21 +0000 | [diff] [blame] | 1974 | mutex_init(&f->lock); |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 1975 | memcpy(&f->op, op, op_size); |
| 1976 | f->compat = compat; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1977 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1978 | root = (struct node *) calloc(1, sizeof(struct node)); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1979 | if (root == NULL) { |
| 1980 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1981 | goto out_free_id_table; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1982 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1983 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1984 | root->name = strdup("/"); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1985 | if (root->name == NULL) { |
| 1986 | fprintf(stderr, "fuse: memory allocation failed\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1987 | goto out_free_root; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1988 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1989 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1990 | root->parent = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1991 | root->nodeid = FUSE_ROOT_ID; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1992 | root->generation = 0; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1993 | root->refctr = 1; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 1994 | root->nlookup = 1; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1995 | hash_id(f, root); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1996 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1997 | return f; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1998 | |
| 1999 | out_free_root: |
| 2000 | free(root); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2001 | out_free_id_table: |
| 2002 | free(f->id_table); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2003 | out_free_name_table: |
| 2004 | free(f->name_table); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2005 | out_free_session: |
| 2006 | fuse_session_destroy(f->se); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2007 | out_free: |
| 2008 | free(f); |
| 2009 | out: |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 2010 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2013 | struct fuse *fuse_new(int fd, const char *opts, |
| 2014 | const struct fuse_operations *op, size_t op_size) |
| 2015 | { |
| 2016 | return fuse_new_common(fd, opts, op, op_size, 0); |
| 2017 | } |
| 2018 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2019 | void fuse_destroy(struct fuse *f) |
| 2020 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2021 | size_t i; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2022 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2023 | struct node *node; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2024 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2025 | for (node = f->id_table[i]; node != NULL; node = node->id_next) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2026 | if (node->is_hidden) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2027 | char *path = get_path(f, node->nodeid); |
Miklos Szeredi | 21019c9 | 2005-05-09 11:22:41 +0000 | [diff] [blame] | 2028 | if (path) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2029 | f->op.unlink(path); |
Miklos Szeredi | 21019c9 | 2005-05-09 11:22:41 +0000 | [diff] [blame] | 2030 | free(path); |
| 2031 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2035 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2036 | struct node *node; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2037 | struct node *next; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 2038 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2039 | for (node = f->id_table[i]; node != NULL; node = next) { |
| 2040 | next = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2041 | free_node(node); |
| 2042 | } |
| 2043 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 2044 | free(f->id_table); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2045 | free(f->name_table); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 2046 | pthread_mutex_destroy(&f->lock); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 2047 | fuse_session_destroy(f->se); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 2048 | free(f); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 2049 | } |
Miklos Szeredi | 0b6a0ad | 2004-12-04 00:40:50 +0000 | [diff] [blame] | 2050 | |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2051 | #ifndef __FreeBSD__ |
| 2052 | |
| 2053 | #include "fuse_compat.h" |
| 2054 | |
| 2055 | static int fuse_do_open(struct fuse *f, char *path, struct fuse_file_info *fi) |
| 2056 | { |
| 2057 | if (!f->compat) |
| 2058 | return f->op.open(path, fi); |
| 2059 | else if (f->compat == 22) { |
| 2060 | int err; |
| 2061 | struct fuse_file_info_compat22 tmp; |
| 2062 | memcpy(&tmp, fi, sizeof(tmp)); |
| 2063 | err = ((struct fuse_operations_compat22 *) &f->op)->open(path, &tmp); |
| 2064 | memcpy(fi, &tmp, sizeof(tmp)); |
| 2065 | fi->fh = tmp.fh; |
| 2066 | return err; |
| 2067 | } else |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 2068 | return |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2069 | ((struct fuse_operations_compat2 *) &f->op)->open(path, fi->flags); |
| 2070 | } |
| 2071 | |
| 2072 | static void fuse_do_release(struct fuse *f, char *path, |
| 2073 | struct fuse_file_info *fi) |
| 2074 | { |
| 2075 | if (!f->compat || f->compat >= 22) |
| 2076 | f->op.release(path ? path : "-", fi); |
| 2077 | else if (path) |
| 2078 | ((struct fuse_operations_compat2 *) &f->op)->release(path, fi->flags); |
| 2079 | } |
| 2080 | |
| 2081 | static int fuse_do_opendir(struct fuse *f, char *path, |
| 2082 | struct fuse_file_info *fi) |
| 2083 | { |
| 2084 | if (!f->compat) { |
| 2085 | return f->op.opendir(path, fi); |
| 2086 | } else { |
| 2087 | int err; |
| 2088 | struct fuse_file_info_compat22 tmp; |
| 2089 | memcpy(&tmp, fi, sizeof(tmp)); |
| 2090 | err = ((struct fuse_operations_compat22 *) &f->op)->opendir(path, &tmp); |
| 2091 | memcpy(fi, &tmp, sizeof(tmp)); |
| 2092 | fi->fh = tmp.fh; |
| 2093 | return err; |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | static void convert_statfs_compat(struct fuse_statfs_compat1 *compatbuf, |
| 2098 | struct statvfs *stbuf) |
| 2099 | { |
| 2100 | stbuf->f_bsize = compatbuf->block_size; |
| 2101 | stbuf->f_blocks = compatbuf->blocks; |
| 2102 | stbuf->f_bfree = compatbuf->blocks_free; |
| 2103 | stbuf->f_bavail = compatbuf->blocks_free; |
| 2104 | stbuf->f_files = compatbuf->files; |
| 2105 | stbuf->f_ffree = compatbuf->files_free; |
| 2106 | stbuf->f_namemax = compatbuf->namelen; |
| 2107 | } |
| 2108 | |
| 2109 | static void convert_statfs_old(struct statfs *oldbuf, struct statvfs *stbuf) |
| 2110 | { |
| 2111 | stbuf->f_bsize = oldbuf->f_bsize; |
| 2112 | stbuf->f_blocks = oldbuf->f_blocks; |
| 2113 | stbuf->f_bfree = oldbuf->f_bfree; |
| 2114 | stbuf->f_bavail = oldbuf->f_bavail; |
| 2115 | stbuf->f_files = oldbuf->f_files; |
| 2116 | stbuf->f_ffree = oldbuf->f_ffree; |
| 2117 | stbuf->f_namemax = oldbuf->f_namelen; |
| 2118 | } |
| 2119 | |
| 2120 | static int fuse_do_statfs(struct fuse *f, char *path, struct statvfs *buf) |
| 2121 | { |
| 2122 | int err; |
| 2123 | |
| 2124 | if (!f->compat) { |
| 2125 | err = f->op.statfs(path, buf); |
| 2126 | } else if (f->compat > 11) { |
| 2127 | struct statfs oldbuf; |
| 2128 | err = ((struct fuse_operations_compat22 *) &f->op)->statfs("/", &oldbuf); |
| 2129 | if (!err) |
| 2130 | convert_statfs_old(&oldbuf, buf); |
| 2131 | } else { |
| 2132 | struct fuse_statfs_compat1 compatbuf; |
| 2133 | memset(&compatbuf, 0, sizeof(struct fuse_statfs_compat1)); |
| 2134 | err = ((struct fuse_operations_compat1 *) &f->op)->statfs(&compatbuf); |
| 2135 | if (!err) |
| 2136 | convert_statfs_compat(&compatbuf, buf); |
| 2137 | } |
| 2138 | return err; |
| 2139 | } |
| 2140 | |
| 2141 | struct fuse *fuse_new_compat22(int fd, const char *opts, |
| 2142 | const struct fuse_operations_compat22 *op, |
| 2143 | size_t op_size) |
| 2144 | { |
| 2145 | return fuse_new_common(fd, opts, (struct fuse_operations *) op, |
| 2146 | op_size, 22); |
| 2147 | } |
| 2148 | |
| 2149 | struct fuse *fuse_new_compat2(int fd, const char *opts, |
| 2150 | const struct fuse_operations_compat2 *op) |
| 2151 | { |
| 2152 | return fuse_new_common(fd, opts, (struct fuse_operations *) op, |
| 2153 | sizeof(struct fuse_operations_compat2), 21); |
| 2154 | } |
| 2155 | |
| 2156 | struct fuse *fuse_new_compat1(int fd, int flags, |
| 2157 | const struct fuse_operations_compat1 *op) |
| 2158 | { |
| 2159 | const char *opts = NULL; |
| 2160 | if (flags & FUSE_DEBUG_COMPAT1) |
| 2161 | opts = "debug"; |
| 2162 | return fuse_new_common(fd, opts, (struct fuse_operations *) op, |
| 2163 | sizeof(struct fuse_operations_compat1), 11); |
| 2164 | } |
| 2165 | |
Miklos Szeredi | f458b8c | 2004-12-07 16:46:42 +0000 | [diff] [blame] | 2166 | __asm__(".symver fuse_exited,__fuse_exited@"); |
| 2167 | __asm__(".symver fuse_process_cmd,__fuse_process_cmd@"); |
| 2168 | __asm__(".symver fuse_read_cmd,__fuse_read_cmd@"); |
| 2169 | __asm__(".symver fuse_set_getcontext_func,__fuse_set_getcontext_func@"); |
| 2170 | __asm__(".symver fuse_new_compat2,fuse_new@"); |
Miklos Szeredi | 3a77047 | 2005-11-11 21:32:42 +0000 | [diff] [blame] | 2171 | __asm__(".symver fuse_new_compat22,fuse_new@FUSE_2.2"); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2172 | |
| 2173 | #else /* __FreeBSD__ */ |
| 2174 | |
| 2175 | static int fuse_do_open(struct fuse *f, char *path, struct fuse_file_info *fi) |
| 2176 | { |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 2177 | return f->op.open(path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | static void fuse_do_release(struct fuse *f, char *path, |
| 2181 | struct fuse_file_info *fi) |
| 2182 | { |
| 2183 | f->op.release(path ? path : "-", fi); |
| 2184 | } |
| 2185 | |
| 2186 | static int fuse_do_opendir(struct fuse *f, char *path, |
| 2187 | struct fuse_file_info *fi) |
| 2188 | { |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 2189 | return f->op.opendir(path, fi); |
Miklos Szeredi | 9c2ccb4 | 2005-11-17 17:11:48 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static int fuse_do_statfs(struct fuse *f, char *path, struct statvfs *buf) |
| 2193 | { |
| 2194 | return f->op.statfs(path, buf); |
| 2195 | } |
| 2196 | |
| 2197 | #endif /* __FreeBSD__ */ |