Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 2e6b6f2 | 2004-07-07 19:19:53 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2004 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 | cb26451 | 2004-06-23 18:52:50 +0000 | [diff] [blame] | 9 | #include <config.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 10 | #include "fuse_i.h" |
| 11 | #include <linux/fuse.h> |
| 12 | |
| 13 | #include <string.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 15 | #include <unistd.h> |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 16 | #include <limits.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 17 | #include <errno.h> |
Miklos Szeredi | 019b4e9 | 2001-12-26 18:08:09 +0000 | [diff] [blame] | 18 | #include <sys/param.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 19 | |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame^] | 20 | #define FUSE_VERSION_FILE_OLD "/proc/fs/fuse/version" |
| 21 | #define FUSE_DEV_OLD "/proc/fs/fuse/dev" |
| 22 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 23 | #define FUSE_MAX_PATH 4096 |
Miklos Szeredi | 6bf8b68 | 2002-10-28 08:49:39 +0000 | [diff] [blame] | 24 | #define PARAM(inarg) (((char *)(inarg)) + sizeof(*inarg)) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 25 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 26 | #define ENTRY_REVALIDATE_TIME 1 /* sec */ |
| 27 | #define ATTR_REVALIDATE_TIME 1 /* sec */ |
| 28 | |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 29 | static struct fuse_context *(*fuse_getcontext)(void) = NULL; |
| 30 | |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 31 | static const char *opname(enum fuse_opcode opcode) |
| 32 | { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 33 | switch (opcode) { |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 34 | case FUSE_LOOKUP: return "LOOKUP"; |
| 35 | case FUSE_FORGET: return "FORGET"; |
| 36 | case FUSE_GETATTR: return "GETATTR"; |
| 37 | case FUSE_SETATTR: return "SETATTR"; |
| 38 | case FUSE_READLINK: return "READLINK"; |
| 39 | case FUSE_SYMLINK: return "SYMLINK"; |
| 40 | case FUSE_GETDIR: return "GETDIR"; |
| 41 | case FUSE_MKNOD: return "MKNOD"; |
| 42 | case FUSE_MKDIR: return "MKDIR"; |
| 43 | case FUSE_UNLINK: return "UNLINK"; |
| 44 | case FUSE_RMDIR: return "RMDIR"; |
| 45 | case FUSE_RENAME: return "RENAME"; |
| 46 | case FUSE_LINK: return "LINK"; |
| 47 | case FUSE_OPEN: return "OPEN"; |
| 48 | case FUSE_READ: return "READ"; |
| 49 | case FUSE_WRITE: return "WRITE"; |
| 50 | case FUSE_STATFS: return "STATFS"; |
Miklos Szeredi | 99f2074 | 2004-05-19 08:01:10 +0000 | [diff] [blame] | 51 | case FUSE_FLUSH: return "FLUSH"; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 52 | case FUSE_RELEASE: return "RELEASE"; |
| 53 | case FUSE_FSYNC: return "FSYNC"; |
| 54 | case FUSE_SETXATTR: return "SETXATTR"; |
| 55 | case FUSE_GETXATTR: return "GETXATTR"; |
| 56 | case FUSE_LISTXATTR: return "LISTXATTR"; |
| 57 | case FUSE_REMOVEXATTR: return "REMOVEXATTR"; |
Miklos Szeredi | 99f2074 | 2004-05-19 08:01:10 +0000 | [diff] [blame] | 58 | default: return "???"; |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 62 | |
| 63 | static inline void dec_avail(struct fuse *f) |
| 64 | { |
| 65 | pthread_mutex_lock(&f->lock); |
| 66 | f->numavail --; |
| 67 | pthread_mutex_unlock(&f->lock); |
| 68 | } |
| 69 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 70 | static struct node *__get_node(struct fuse *f, nodeid_t nodeid) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 71 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 72 | size_t hash = nodeid % f->id_table_size; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 73 | struct node *node; |
| 74 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 75 | for (node = f->id_table[hash]; node != NULL; node = node->id_next) |
| 76 | if (node->nodeid == nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 77 | return node; |
| 78 | |
| 79 | return NULL; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 82 | static struct node *get_node(struct fuse *f, nodeid_t nodeid) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 83 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 84 | struct node *node = __get_node(f, nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 85 | if (node != NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 86 | return node; |
| 87 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 88 | fprintf(stderr, "fuse internal error: inode %lu not found\n", nodeid); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 89 | abort(); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 92 | static void hash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 93 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 94 | size_t hash = node->nodeid % f->id_table_size; |
| 95 | node->id_next = f->id_table[hash]; |
| 96 | f->id_table[hash] = node; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 99 | static void unhash_id(struct fuse *f, struct node *node) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 100 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 101 | size_t hash = node->nodeid % f->id_table_size; |
| 102 | struct node **nodep = &f->id_table[hash]; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 103 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 104 | for (; *nodep != NULL; nodep = &(*nodep)->id_next) |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 105 | if (*nodep == node) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 106 | *nodep = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 107 | return; |
| 108 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 111 | static nodeid_t next_id(struct fuse *f) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 112 | { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 113 | do { |
| 114 | f->ctr++; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 115 | if (!f->ctr) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 116 | f->generation ++; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 117 | } while (f->ctr == 0 || __get_node(f, f->ctr) != NULL); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 118 | return f->ctr; |
| 119 | } |
| 120 | |
| 121 | static void free_node(struct node *node) |
| 122 | { |
| 123 | free(node->name); |
| 124 | free(node); |
| 125 | } |
| 126 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 127 | static unsigned int name_hash(struct fuse *f, nodeid_t parent, const char *name) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 128 | { |
| 129 | unsigned int hash = *name; |
| 130 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 131 | if (hash) |
| 132 | for (name += 1; *name != '\0'; name++) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 133 | hash = (hash << 5) - hash + *name; |
| 134 | |
| 135 | return (hash + parent) % f->name_table_size; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 138 | static struct node *__lookup_node(struct fuse *f, nodeid_t parent, |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 139 | const char *name) |
| 140 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 141 | size_t hash = name_hash(f, parent, name); |
| 142 | struct node *node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 143 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 144 | for (node = f->name_table[hash]; node != NULL; node = node->name_next) |
| 145 | if (node->parent == parent && strcmp(node->name, name) == 0) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 146 | return node; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 147 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 148 | return NULL; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 151 | static struct node *lookup_node(struct fuse *f, nodeid_t parent, |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 152 | const char *name) |
| 153 | { |
| 154 | struct node *node; |
| 155 | |
| 156 | pthread_mutex_lock(&f->lock); |
| 157 | node = __lookup_node(f, parent, name); |
| 158 | pthread_mutex_unlock(&f->lock); |
| 159 | if (node != NULL) |
| 160 | return node; |
| 161 | |
| 162 | fprintf(stderr, "fuse internal error: node %lu/%s not found\n", parent, |
| 163 | name); |
| 164 | abort(); |
| 165 | } |
| 166 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 167 | static int hash_name(struct fuse *f, struct node *node, nodeid_t parent, |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 168 | const char *name) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 169 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 170 | size_t hash = name_hash(f, parent, name); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 171 | node->parent = parent; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 172 | node->name = strdup(name); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 173 | if (node->name == NULL) |
| 174 | return -1; |
| 175 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 176 | node->name_next = f->name_table[hash]; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 177 | f->name_table[hash] = node; |
| 178 | return 0; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 181 | static void unhash_name(struct fuse *f, struct node *node) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 182 | { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 183 | if (node->name != NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 184 | size_t hash = name_hash(f, node->parent, node->name); |
| 185 | struct node **nodep = &f->name_table[hash]; |
| 186 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 187 | for (; *nodep != NULL; nodep = &(*nodep)->name_next) |
| 188 | if (*nodep == node) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 189 | *nodep = node->name_next; |
| 190 | node->name_next = NULL; |
| 191 | free(node->name); |
| 192 | node->name = NULL; |
| 193 | node->parent = 0; |
| 194 | return; |
| 195 | } |
| 196 | fprintf(stderr, "fuse internal error: unable to unhash node: %lu\n", |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 197 | node->nodeid); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 198 | abort(); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 202 | static struct node *find_node(struct fuse *f, nodeid_t parent, char *name, |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 203 | struct fuse_attr *attr, int version) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 204 | { |
| 205 | struct node *node; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 206 | int mode = attr->mode & S_IFMT; |
| 207 | int rdev = 0; |
| 208 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 209 | if (S_ISCHR(mode) || S_ISBLK(mode)) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 210 | rdev = attr->rdev; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 211 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 212 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 213 | node = __lookup_node(f, parent, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 214 | if (node != NULL) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 215 | if (node->mode == mode && node->rdev == rdev && |
| 216 | (!(f->flags & FUSE_USE_INO) || node->ino == attr->ino)) { |
| 217 | if (!(f->flags & FUSE_USE_INO)) |
| 218 | attr->ino = node->nodeid; |
| 219 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 220 | goto out; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 221 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 222 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 223 | unhash_name(f, node); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 226 | node = (struct node *) calloc(1, sizeof(struct node)); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 227 | if (node == NULL) |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 228 | goto out_err; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 229 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 230 | node->nodeid = next_id(f); |
| 231 | if (!(f->flags & FUSE_USE_INO)) |
| 232 | attr->ino = node->nodeid; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 233 | node->mode = mode; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 234 | node->rdev = rdev; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 235 | node->ino = attr->ino; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 236 | node->open_count = 0; |
| 237 | node->is_hidden = 0; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 238 | node->generation = f->generation; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 239 | if (hash_name(f, node, parent, name) == -1) { |
| 240 | free(node); |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 241 | node = NULL; |
| 242 | goto out_err; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 243 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 244 | hash_id(f, node); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 245 | |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 246 | out: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 247 | node->version = version; |
Miklos Szeredi | c230991 | 2004-09-21 13:40:38 +0000 | [diff] [blame] | 248 | out_err: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 249 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 250 | return node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 253 | static int path_lookup(struct fuse *f, const char *path, nodeid_t *nodeidp, |
| 254 | unsigned long *inop) |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 255 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 256 | nodeid_t nodeid; |
| 257 | unsigned long ino; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 258 | int err; |
| 259 | char *s; |
| 260 | char *name; |
| 261 | char *tmp = strdup(path); |
| 262 | if (!tmp) |
| 263 | return -ENOMEM; |
| 264 | |
| 265 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 266 | nodeid = FUSE_ROOT_ID; |
| 267 | ino = nodeid; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 268 | err = 0; |
| 269 | for (s = tmp; (name = strsep(&s, "/")) != NULL; ) { |
| 270 | if (name[0]) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 271 | struct node *node = __lookup_node(f, nodeid, name); |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 272 | if (node == NULL) { |
| 273 | err = -ENOENT; |
| 274 | break; |
| 275 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 276 | nodeid = node->nodeid; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 277 | ino = node->ino; |
| 278 | } |
| 279 | } |
| 280 | pthread_mutex_unlock(&f->lock); |
| 281 | free(tmp); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 282 | if (!err) { |
| 283 | *nodeidp = nodeid; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 284 | *inop = ino; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 285 | } |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 286 | |
| 287 | return err; |
| 288 | } |
| 289 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 290 | static char *add_name(char *buf, char *s, const char *name) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 291 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 292 | size_t len = strlen(name); |
| 293 | s -= len; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 294 | if (s <= buf) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 295 | fprintf(stderr, "fuse: path too long: ...%s\n", s + len); |
| 296 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 297 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 298 | strncpy(s, name, len); |
| 299 | s--; |
| 300 | *s = '/'; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 301 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 302 | return s; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 305 | static char *get_path_name(struct fuse *f, nodeid_t nodeid, const char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 306 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 307 | char buf[FUSE_MAX_PATH]; |
| 308 | char *s = buf + FUSE_MAX_PATH - 1; |
| 309 | struct node *node; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 310 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 311 | *s = '\0'; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 312 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 313 | if (name != NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 314 | s = add_name(buf, s, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 315 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 320 | for (node = get_node(f, nodeid); node->nodeid != FUSE_ROOT_ID; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 321 | node = get_node(f, node->parent)) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 322 | if (node->name == NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 323 | s = NULL; |
| 324 | break; |
| 325 | } |
| 326 | |
| 327 | s = add_name(buf, s, node->name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 328 | if (s == NULL) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | pthread_mutex_unlock(&f->lock); |
| 332 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 333 | if (s == NULL) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 334 | return NULL; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 335 | else if (*s == '\0') |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 336 | return strdup("/"); |
| 337 | else |
| 338 | return strdup(s); |
| 339 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 340 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 341 | static char *get_path(struct fuse *f, nodeid_t nodeid) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 342 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 343 | return get_path_name(f, nodeid, NULL); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 346 | static void destroy_node(struct fuse *f, nodeid_t nodeid, int version) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 347 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 348 | struct node *node; |
| 349 | |
| 350 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 351 | node = __get_node(f, nodeid); |
| 352 | if (node && node->version == version && nodeid != FUSE_ROOT_ID) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 353 | unhash_name(f, node); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 354 | unhash_id(f, node); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 355 | free_node(node); |
| 356 | } |
| 357 | pthread_mutex_unlock(&f->lock); |
| 358 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 361 | static void remove_node(struct fuse *f, nodeid_t dir, const char *name) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 362 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 363 | struct node *node; |
| 364 | |
| 365 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 366 | node = __lookup_node(f, dir, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 367 | if (node == NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 368 | fprintf(stderr, "fuse internal error: unable to remove node %lu/%s\n", |
| 369 | dir, name); |
| 370 | abort(); |
| 371 | } |
| 372 | unhash_name(f, node); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 373 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 376 | static int rename_node(struct fuse *f, nodeid_t olddir, const char *oldname, |
| 377 | nodeid_t newdir, const char *newname, int hide) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 378 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 379 | struct node *node; |
| 380 | struct node *newnode; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 381 | int err = 0; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 382 | |
| 383 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 384 | node = __lookup_node(f, olddir, oldname); |
| 385 | newnode = __lookup_node(f, newdir, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 386 | if (node == NULL) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 387 | fprintf(stderr, "fuse internal error: unable to rename node %lu/%s\n", |
| 388 | olddir, oldname); |
| 389 | abort(); |
| 390 | } |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 391 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 392 | if (newnode != NULL) { |
| 393 | if (hide) { |
| 394 | fprintf(stderr, "fuse: hidden file got created during hiding\n"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 395 | err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 396 | goto out; |
| 397 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 398 | unhash_name(f, newnode); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 399 | } |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 400 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 401 | unhash_name(f, node); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 402 | if (hash_name(f, node, newdir, newname) == -1) { |
| 403 | err = -ENOMEM; |
| 404 | goto out; |
| 405 | } |
| 406 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 407 | if (hide) |
| 408 | node->is_hidden = 1; |
| 409 | |
| 410 | out: |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 411 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 412 | return err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 415 | static void convert_stat(struct stat *stbuf, struct fuse_attr *attr) |
| 416 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 417 | attr->ino = stbuf->st_ino; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 418 | attr->mode = stbuf->st_mode; |
| 419 | attr->nlink = stbuf->st_nlink; |
| 420 | attr->uid = stbuf->st_uid; |
| 421 | attr->gid = stbuf->st_gid; |
| 422 | attr->rdev = stbuf->st_rdev; |
| 423 | attr->size = stbuf->st_size; |
| 424 | attr->blocks = stbuf->st_blocks; |
| 425 | attr->atime = stbuf->st_atime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 426 | attr->mtime = stbuf->st_mtime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 427 | attr->ctime = stbuf->st_ctime; |
Miklos Szeredi | cb26451 | 2004-06-23 18:52:50 +0000 | [diff] [blame] | 428 | #ifdef HAVE_STRUCT_STAT_ST_ATIM |
| 429 | attr->atimensec = stbuf->st_atim.tv_nsec; |
| 430 | attr->mtimensec = stbuf->st_mtim.tv_nsec; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 431 | attr->ctimensec = stbuf->st_ctim.tv_nsec; |
Miklos Szeredi | cb26451 | 2004-06-23 18:52:50 +0000 | [diff] [blame] | 432 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Miklos Szeredi | 8fb48fe | 2004-11-08 14:48:52 +0000 | [diff] [blame] | 435 | static int fill_dir(struct fuse_dirhandle *dh, const char *name, int type, |
| 436 | ino_t ino) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 437 | { |
| 438 | struct fuse_dirent dirent; |
| 439 | size_t reclen; |
| 440 | size_t res; |
| 441 | |
Miklos Szeredi | 8fb48fe | 2004-11-08 14:48:52 +0000 | [diff] [blame] | 442 | if ((dh->fuse->flags & FUSE_USE_INO)) |
| 443 | dirent.ino = ino; |
| 444 | else |
| 445 | dirent.ino = (unsigned long) -1; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 446 | dirent.namelen = strlen(name); |
| 447 | strncpy(dirent.name, name, sizeof(dirent.name)); |
| 448 | dirent.type = type; |
| 449 | reclen = FUSE_DIRENT_SIZE(&dirent); |
| 450 | res = fwrite(&dirent, reclen, 1, dh->fp); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 451 | if (res == 0) { |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 452 | perror("fuse: writing directory file"); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 453 | return -EIO; |
| 454 | } |
| 455 | return 0; |
| 456 | } |
| 457 | |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 458 | static int send_reply_raw(struct fuse *f, char *outbuf, size_t outsize, |
| 459 | int locked) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 460 | { |
| 461 | int res; |
| 462 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 463 | if ((f->flags & FUSE_DEBUG)) { |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 464 | struct fuse_out_header *out = (struct fuse_out_header *) outbuf; |
| 465 | printf(" unique: %i, error: %i (%s), outsize: %i\n", out->unique, |
| 466 | out->error, strerror(-out->error), outsize); |
| 467 | fflush(stdout); |
| 468 | } |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 469 | |
Miklos Szeredi | 4e71c9f | 2004-02-09 12:05:14 +0000 | [diff] [blame] | 470 | /* This needs to be done before the reply, otherwise the scheduler |
| 471 | could play tricks with us, and only let the counter be increased |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 472 | long after the operation is done */ |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 473 | if (!locked) |
| 474 | pthread_mutex_lock(&f->lock); |
| 475 | f->numavail ++; |
| 476 | if (!locked) |
| 477 | pthread_mutex_unlock(&f->lock); |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 478 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 479 | res = write(f->fd, outbuf, outsize); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 480 | if (res == -1) { |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 481 | /* ENOENT means the operation was interrupted */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 482 | if (!f->exited && errno != ENOENT) |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 483 | perror("fuse: writing device"); |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 484 | return -errno; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 485 | } |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 486 | return 0; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 489 | static int __send_reply(struct fuse *f, struct fuse_in_header *in, int error, |
| 490 | void *arg, size_t argsize, int locked) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 491 | { |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 492 | int res; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 493 | char *outbuf; |
| 494 | size_t outsize; |
| 495 | struct fuse_out_header *out; |
| 496 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 497 | if (error <= -1000 || error > 0) { |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 498 | fprintf(stderr, "fuse: bad error value: %i\n", error); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 499 | error = -ERANGE; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 502 | if (error) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 503 | argsize = 0; |
| 504 | |
| 505 | outsize = sizeof(struct fuse_out_header) + argsize; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 506 | outbuf = (char *) malloc(outsize); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 507 | if (outbuf == NULL) { |
| 508 | fprintf(stderr, "fuse: failed to allocate reply buffer\n"); |
| 509 | res = -ENOMEM; |
| 510 | } else { |
| 511 | out = (struct fuse_out_header *) outbuf; |
| 512 | memset(out, 0, sizeof(struct fuse_out_header)); |
| 513 | out->unique = in->unique; |
| 514 | out->error = error; |
| 515 | if (argsize != 0) |
| 516 | memcpy(outbuf + sizeof(struct fuse_out_header), arg, argsize); |
| 517 | |
| 518 | res = send_reply_raw(f, outbuf, outsize, locked); |
| 519 | free(outbuf); |
| 520 | } |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 521 | |
| 522 | return res; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 525 | static int send_reply(struct fuse *f, struct fuse_in_header *in, int error, |
| 526 | void *arg, size_t argsize) |
| 527 | { |
| 528 | return __send_reply(f, in, error, arg, argsize, 0); |
| 529 | } |
| 530 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 531 | static int is_open(struct fuse *f, nodeid_t dir, const char *name) |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 532 | { |
| 533 | struct node *node; |
| 534 | int isopen = 0; |
| 535 | pthread_mutex_lock(&f->lock); |
| 536 | node = __lookup_node(f, dir, name); |
| 537 | if (node && node->open_count > 0) |
| 538 | isopen = 1; |
| 539 | pthread_mutex_unlock(&f->lock); |
| 540 | return isopen; |
| 541 | } |
| 542 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 543 | static char *hidden_name(struct fuse *f, nodeid_t dir, const char *oldname, |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 544 | char *newname, size_t bufsize) |
| 545 | { |
| 546 | struct stat buf; |
| 547 | struct node *node; |
| 548 | struct node *newnode; |
| 549 | char *newpath; |
| 550 | int res; |
| 551 | int failctr = 10; |
| 552 | |
| 553 | if (!f->op.getattr) |
| 554 | return NULL; |
| 555 | |
| 556 | do { |
| 557 | node = lookup_node(f, dir, oldname); |
| 558 | pthread_mutex_lock(&f->lock); |
| 559 | do { |
| 560 | f->hidectr ++; |
| 561 | snprintf(newname, bufsize, ".fuse_hidden%08x%08x", |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 562 | (unsigned int) node->nodeid, f->hidectr); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 563 | newnode = __lookup_node(f, dir, newname); |
| 564 | } while(newnode); |
| 565 | pthread_mutex_unlock(&f->lock); |
| 566 | |
| 567 | newpath = get_path_name(f, dir, newname); |
| 568 | if (!newpath) |
| 569 | break; |
| 570 | |
| 571 | res = f->op.getattr(newpath, &buf); |
| 572 | if (res != 0) |
| 573 | break; |
| 574 | free(newpath); |
| 575 | newpath = NULL; |
| 576 | } while(--failctr); |
| 577 | |
| 578 | return newpath; |
| 579 | } |
| 580 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 581 | static int hide_node(struct fuse *f, const char *oldpath, nodeid_t dir, |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 582 | const char *oldname) |
| 583 | { |
| 584 | char newname[64]; |
| 585 | char *newpath; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 586 | int err = -EBUSY; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 587 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 588 | if (f->op.rename && f->op.unlink) { |
| 589 | newpath = hidden_name(f, dir, oldname, newname, sizeof(newname)); |
| 590 | if (newpath) { |
| 591 | int res = f->op.rename(oldpath, newpath); |
| 592 | if (res == 0) |
| 593 | err = rename_node(f, dir, oldname, dir, newname, 1); |
| 594 | free(newpath); |
| 595 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 596 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 597 | return err; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 600 | static int lookup_path(struct fuse *f, nodeid_t nodeid, int version, char *name, |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 601 | const char *path, struct fuse_entry_out *arg) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 602 | { |
| 603 | int res; |
| 604 | struct stat buf; |
| 605 | |
| 606 | res = f->op.getattr(path, &buf); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 607 | if (res == 0) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 608 | struct node *node; |
| 609 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 610 | memset(arg, 0, sizeof(struct fuse_entry_out)); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 611 | convert_stat(&buf, &arg->attr); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 612 | node = find_node(f, nodeid, name, &arg->attr, version); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 613 | if (node == NULL) |
| 614 | res = -ENOMEM; |
| 615 | else { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 616 | arg->nodeid = node->nodeid; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 617 | arg->generation = node->generation; |
| 618 | arg->entry_valid = ENTRY_REVALIDATE_TIME; |
| 619 | arg->entry_valid_nsec = 0; |
| 620 | arg->attr_valid = ATTR_REVALIDATE_TIME; |
| 621 | arg->attr_valid_nsec = 0; |
| 622 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 623 | printf(" NODEID: %li\n", arg->nodeid); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 624 | fflush(stdout); |
| 625 | } |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | return res; |
| 629 | } |
| 630 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 631 | static void do_lookup(struct fuse *f, struct fuse_in_header *in, char *name) |
| 632 | { |
| 633 | int res; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 634 | int res2; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 635 | char *path; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 636 | struct fuse_entry_out arg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 637 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 638 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 639 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 640 | if (path != NULL) { |
| 641 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 642 | printf("LOOKUP %s\n", path); |
| 643 | fflush(stdout); |
| 644 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 645 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 646 | if (f->op.getattr) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 647 | res = lookup_path(f, in->nodeid, in->unique, name, path, &arg); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 648 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 649 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 650 | res2 = send_reply(f, in, res, &arg, sizeof(arg)); |
| 651 | if (res == 0 && res2 == -ENOENT) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 652 | destroy_node(f, arg.nodeid, in->unique); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 655 | static void do_forget(struct fuse *f, struct fuse_in_header *in, |
| 656 | struct fuse_forget_in *arg) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 657 | { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 658 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 659 | printf("FORGET %li/%i\n", in->nodeid, arg->version); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 660 | fflush(stdout); |
| 661 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 662 | destroy_node(f, in->nodeid, arg->version); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static void do_getattr(struct fuse *f, struct fuse_in_header *in) |
| 666 | { |
| 667 | int res; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 668 | char *path; |
| 669 | struct stat buf; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 670 | struct fuse_attr_out arg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 671 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 672 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 673 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 674 | if (path != NULL) { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 675 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 676 | if (f->op.getattr) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 677 | res = f->op.getattr(path, &buf); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 678 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 679 | } |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 680 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 681 | if (res == 0) { |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 682 | memset(&arg, 0, sizeof(struct fuse_attr_out)); |
| 683 | arg.attr_valid = ATTR_REVALIDATE_TIME; |
| 684 | arg.attr_valid_nsec = 0; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 685 | convert_stat(&buf, &arg.attr); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 686 | if (!(f->flags & FUSE_USE_INO)) |
| 687 | arg.attr.ino = in->nodeid; |
| 688 | else { |
| 689 | struct node *node = get_node(f, in->nodeid); |
| 690 | node->ino = arg.attr.ino; |
| 691 | } |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 692 | } |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 693 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 694 | send_reply(f, in, res, &arg, sizeof(arg)); |
| 695 | } |
| 696 | |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 697 | static int do_chmod(struct fuse *f, const char *path, struct fuse_attr *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 698 | { |
| 699 | int res; |
| 700 | |
| 701 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 702 | if (f->op.chmod) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 703 | res = f->op.chmod(path, attr->mode); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 704 | |
| 705 | return res; |
| 706 | } |
| 707 | |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 708 | static int do_chown(struct fuse *f, const char *path, struct fuse_attr *attr, |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 709 | int valid) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 710 | { |
| 711 | int res; |
| 712 | uid_t uid = (valid & FATTR_UID) ? attr->uid : (uid_t) -1; |
| 713 | gid_t gid = (valid & FATTR_GID) ? attr->gid : (gid_t) -1; |
| 714 | |
| 715 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 716 | if (f->op.chown) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 717 | res = f->op.chown(path, uid, gid); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 718 | |
| 719 | return res; |
| 720 | } |
| 721 | |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 722 | static int do_truncate(struct fuse *f, const char *path, |
| 723 | struct fuse_attr *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 724 | { |
| 725 | int res; |
| 726 | |
| 727 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 728 | if (f->op.truncate) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 729 | res = f->op.truncate(path, attr->size); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 730 | |
| 731 | return res; |
| 732 | } |
| 733 | |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 734 | static int do_utime(struct fuse *f, const char *path, struct fuse_attr *attr) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 735 | { |
| 736 | int res; |
| 737 | struct utimbuf buf; |
| 738 | buf.actime = attr->atime; |
| 739 | buf.modtime = attr->mtime; |
| 740 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 741 | if (f->op.utime) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 742 | res = f->op.utime(path, &buf); |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 743 | |
| 744 | return res; |
| 745 | } |
| 746 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 747 | static void do_setattr(struct fuse *f, struct fuse_in_header *in, |
| 748 | struct fuse_setattr_in *arg) |
| 749 | { |
| 750 | int res; |
| 751 | char *path; |
| 752 | int valid = arg->valid; |
| 753 | struct fuse_attr *attr = &arg->attr; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 754 | struct fuse_attr_out outarg; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 755 | |
| 756 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 757 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 758 | if (path != NULL) { |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 759 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 760 | if (f->op.getattr) { |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 761 | res = 0; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 762 | if (!res && (valid & FATTR_MODE)) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 763 | res = do_chmod(f, path, attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 764 | if (!res && (valid & (FATTR_UID | FATTR_GID))) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 765 | res = do_chown(f, path, attr, valid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 766 | if (!res && (valid & FATTR_SIZE)) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 767 | res = do_truncate(f, path, attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 768 | if (!res && (valid & (FATTR_ATIME | FATTR_MTIME)) == |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 769 | (FATTR_ATIME | FATTR_MTIME)) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 770 | res = do_utime(f, path, attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 771 | if (!res) { |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 772 | struct stat buf; |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 773 | res = f->op.getattr(path, &buf); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 774 | if (!res) { |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 775 | memset(&outarg, 0, sizeof(struct fuse_attr_out)); |
| 776 | outarg.attr_valid = ATTR_REVALIDATE_TIME; |
| 777 | outarg.attr_valid_nsec = 0; |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 778 | convert_stat(&buf, &outarg.attr); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 779 | if (!(f->flags & FUSE_USE_INO)) |
| 780 | outarg.attr.ino = in->nodeid; |
| 781 | else { |
| 782 | struct node *node = get_node(f, in->nodeid); |
| 783 | node->ino = outarg.attr.ino; |
| 784 | } |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 785 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 786 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 787 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 788 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 789 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 790 | send_reply(f, in, res, &outarg, sizeof(outarg)); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 793 | static void do_readlink(struct fuse *f, struct fuse_in_header *in) |
| 794 | { |
| 795 | int res; |
| 796 | char link[PATH_MAX + 1]; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 797 | char *path; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 798 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 799 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 800 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 801 | if (path != NULL) { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 802 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 803 | if (f->op.readlink) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 804 | res = f->op.readlink(path, link, sizeof(link)); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 805 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 806 | } |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 807 | link[PATH_MAX] = '\0'; |
Miklos Szeredi | 4b2bef4 | 2002-01-09 12:23:27 +0000 | [diff] [blame] | 808 | send_reply(f, in, res, link, res == 0 ? strlen(link) : 0); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | static void do_getdir(struct fuse *f, struct fuse_in_header *in) |
| 812 | { |
| 813 | int res; |
| 814 | struct fuse_getdir_out arg; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 815 | struct fuse_dirhandle dh; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 816 | char *path; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 817 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 818 | dh.fuse = f; |
| 819 | dh.fp = tmpfile(); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 820 | dh.dir = in->nodeid; |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 821 | |
Miklos Szeredi | 65afea1 | 2004-09-14 07:13:45 +0000 | [diff] [blame] | 822 | res = -EIO; |
| 823 | if (dh.fp == NULL) |
| 824 | perror("fuse: failed to create temporary file"); |
| 825 | else { |
| 826 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 827 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 65afea1 | 2004-09-14 07:13:45 +0000 | [diff] [blame] | 828 | if (path != NULL) { |
| 829 | res = -ENOSYS; |
| 830 | if (f->op.getdir) |
Miklos Szeredi | 8fb48fe | 2004-11-08 14:48:52 +0000 | [diff] [blame] | 831 | res = f->op.getdir(path, &dh, fill_dir); |
Miklos Szeredi | 65afea1 | 2004-09-14 07:13:45 +0000 | [diff] [blame] | 832 | free(path); |
| 833 | } |
| 834 | fflush(dh.fp); |
| 835 | } |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 836 | memset(&arg, 0, sizeof(struct fuse_getdir_out)); |
Miklos Szeredi | 65afea1 | 2004-09-14 07:13:45 +0000 | [diff] [blame] | 837 | if (res == 0) |
| 838 | arg.fd = fileno(dh.fp); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 839 | send_reply(f, in, res, &arg, sizeof(arg)); |
Miklos Szeredi | 65afea1 | 2004-09-14 07:13:45 +0000 | [diff] [blame] | 840 | if (dh.fp != NULL) |
| 841 | fclose(dh.fp); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 844 | static void do_mknod(struct fuse *f, struct fuse_in_header *in, |
| 845 | struct fuse_mknod_in *inarg) |
| 846 | { |
| 847 | int res; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 848 | int res2; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 849 | char *path; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 850 | char *name = PARAM(inarg); |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 851 | struct fuse_entry_out outarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 852 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 853 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 854 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 855 | if (path != NULL) { |
| 856 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 857 | printf("MKNOD %s\n", path); |
| 858 | fflush(stdout); |
| 859 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 860 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 861 | if (f->op.mknod && f->op.getattr) { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 862 | res = f->op.mknod(path, inarg->mode, inarg->rdev); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 863 | if (res == 0) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 864 | res = lookup_path(f, in->nodeid, in->unique, name, path, &outarg); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 865 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 866 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 867 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 868 | res2 = send_reply(f, in, res, &outarg, sizeof(outarg)); |
| 869 | if (res == 0 && res2 == -ENOENT) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 870 | destroy_node(f, outarg.nodeid, in->unique); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void do_mkdir(struct fuse *f, struct fuse_in_header *in, |
| 874 | struct fuse_mkdir_in *inarg) |
| 875 | { |
| 876 | int res; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 877 | int res2; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 878 | char *path; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 879 | char *name = PARAM(inarg); |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 880 | struct fuse_entry_out outarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 881 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 882 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 883 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 884 | if (path != NULL) { |
| 885 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 886 | printf("MKDIR %s\n", path); |
| 887 | fflush(stdout); |
| 888 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 889 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 890 | if (f->op.mkdir && f->op.getattr) { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 891 | res = f->op.mkdir(path, inarg->mode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 892 | if (res == 0) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 893 | res = lookup_path(f, in->nodeid, in->unique, name, path, &outarg); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 894 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 895 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 896 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 897 | res2 = send_reply(f, in, res, &outarg, sizeof(outarg)); |
| 898 | if (res == 0 && res2 == -ENOENT) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 899 | destroy_node(f, outarg.nodeid, in->unique); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 902 | static void do_unlink(struct fuse *f, struct fuse_in_header *in, char *name) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 903 | { |
| 904 | int res; |
| 905 | char *path; |
| 906 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 907 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 908 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 909 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 910 | if (f->flags & FUSE_DEBUG) { |
| 911 | printf("UNLINK %s\n", path); |
| 912 | fflush(stdout); |
| 913 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 914 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 915 | if (f->op.unlink) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 916 | if (!(f->flags & FUSE_HARD_REMOVE) && is_open(f, in->nodeid, name)) |
| 917 | res = hide_node(f, path, in->nodeid, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 918 | else { |
| 919 | res = f->op.unlink(path); |
| 920 | if (res == 0) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 921 | remove_node(f, in->nodeid, name); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 922 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 923 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 924 | free(path); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 925 | } |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 926 | send_reply(f, in, res, NULL, 0); |
| 927 | } |
| 928 | |
| 929 | static void do_rmdir(struct fuse *f, struct fuse_in_header *in, char *name) |
| 930 | { |
| 931 | int res; |
| 932 | char *path; |
| 933 | |
| 934 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 935 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 936 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 937 | if (f->flags & FUSE_DEBUG) { |
| 938 | printf("RMDIR %s\n", path); |
| 939 | fflush(stdout); |
| 940 | } |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 941 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 942 | if (f->op.rmdir) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 943 | res = f->op.rmdir(path); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 944 | if (res == 0) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 945 | remove_node(f, in->nodeid, name); |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 946 | } |
| 947 | free(path); |
| 948 | } |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 949 | send_reply(f, in, res, NULL, 0); |
| 950 | } |
| 951 | |
| 952 | static void do_symlink(struct fuse *f, struct fuse_in_header *in, char *name, |
| 953 | char *link) |
| 954 | { |
| 955 | int res; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 956 | int res2; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 957 | char *path; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 958 | struct fuse_entry_out outarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 959 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 960 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 961 | path = get_path_name(f, in->nodeid, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 962 | if (path != NULL) { |
| 963 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 964 | printf("SYMLINK %s\n", path); |
| 965 | fflush(stdout); |
| 966 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 967 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 968 | if (f->op.symlink && f->op.getattr) { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 969 | res = f->op.symlink(link, path); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 970 | if (res == 0) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 971 | res = lookup_path(f, in->nodeid, in->unique, name, path, &outarg); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 972 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 973 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 974 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 975 | res2 = send_reply(f, in, res, &outarg, sizeof(outarg)); |
| 976 | if (res == 0 && res2 == -ENOENT) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 977 | destroy_node(f, outarg.nodeid, in->unique); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 978 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 981 | static void do_rename(struct fuse *f, struct fuse_in_header *in, |
| 982 | struct fuse_rename_in *inarg) |
| 983 | { |
| 984 | int res; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 985 | nodeid_t olddir = in->nodeid; |
| 986 | nodeid_t newdir = inarg->newdir; |
Miklos Szeredi | 6bf8b68 | 2002-10-28 08:49:39 +0000 | [diff] [blame] | 987 | char *oldname = PARAM(inarg); |
| 988 | char *newname = oldname + strlen(oldname) + 1; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 989 | char *oldpath; |
| 990 | char *newpath; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 991 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 992 | res = -ENOENT; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 993 | oldpath = get_path_name(f, olddir, oldname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 994 | if (oldpath != NULL) { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 995 | newpath = get_path_name(f, newdir, newname); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 996 | if (newpath != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 997 | if (f->flags & FUSE_DEBUG) { |
| 998 | printf("RENAME %s -> %s\n", oldpath, newpath); |
| 999 | fflush(stdout); |
| 1000 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1001 | res = -ENOSYS; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1002 | if (f->op.rename) { |
| 1003 | res = 0; |
Miklos Szeredi | 2529ca2 | 2004-07-13 15:36:52 +0000 | [diff] [blame] | 1004 | if (!(f->flags & FUSE_HARD_REMOVE) && |
| 1005 | is_open(f, newdir, newname)) |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1006 | res = hide_node(f, newpath, newdir, newname); |
| 1007 | if (res == 0) { |
| 1008 | res = f->op.rename(oldpath, newpath); |
| 1009 | if (res == 0) |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1010 | res = rename_node(f, olddir, oldname, newdir, newname, 0); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1011 | } |
| 1012 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1013 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1014 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1015 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1016 | } |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1017 | send_reply(f, in, res, NULL, 0); |
| 1018 | } |
| 1019 | |
| 1020 | static void do_link(struct fuse *f, struct fuse_in_header *in, |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1021 | struct fuse_link_in *arg) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1022 | { |
| 1023 | int res; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 1024 | int res2; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1025 | char *oldpath; |
| 1026 | char *newpath; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1027 | char *name = PARAM(arg); |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 1028 | struct fuse_entry_out outarg; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1029 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1030 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1031 | oldpath = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1032 | if (oldpath != NULL) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1033 | newpath = get_path_name(f, arg->newdir, name); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1034 | if (newpath != NULL) { |
| 1035 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1036 | printf("LINK %s\n", newpath); |
| 1037 | fflush(stdout); |
| 1038 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1039 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1040 | if (f->op.link && f->op.getattr) { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 1041 | res = f->op.link(oldpath, newpath); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1042 | if (res == 0) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1043 | res = lookup_path(f, arg->newdir, in->unique, name, |
| 1044 | newpath, &outarg); |
| 1045 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1046 | free(newpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1047 | } |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1048 | free(oldpath); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1049 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 1050 | res2 = send_reply(f, in, res, &outarg, sizeof(outarg)); |
| 1051 | if (res == 0 && res2 == -ENOENT) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1052 | destroy_node(f, outarg.nodeid, in->unique); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1055 | static void do_open(struct fuse *f, struct fuse_in_header *in, |
| 1056 | struct fuse_open_in *arg) |
| 1057 | { |
| 1058 | int res; |
| 1059 | char *path; |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1060 | struct fuse_open_out outarg; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1061 | |
| 1062 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1063 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1064 | if (path != NULL) { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1065 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1066 | if (f->op.open) |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 1067 | res = f->op.open(path, arg->flags); |
Miklos Szeredi | 40b9a5a | 2002-12-10 16:09:02 +0000 | [diff] [blame] | 1068 | } |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1069 | if (res == 0) { |
| 1070 | int res2; |
| 1071 | |
| 1072 | /* If the request is interrupted the lock must be held until |
| 1073 | the cancellation is finished. Otherwise there could be |
| 1074 | races with rename/unlink, against which the kernel can't |
| 1075 | protect */ |
| 1076 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1077 | f->fh_ctr ++; |
| 1078 | outarg.fh = f->fh_ctr; |
| 1079 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1080 | printf("OPEN[%lu] flags: 0x%x\n", outarg.fh, arg->flags); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1081 | fflush(stdout); |
| 1082 | } |
| 1083 | |
| 1084 | res2 = __send_reply(f, in, res, &outarg, sizeof(outarg), 1); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1085 | if(res2 == -ENOENT) { |
| 1086 | /* The open syscall was interrupted, so it must be cancelled */ |
| 1087 | if(f->op.release) |
| 1088 | f->op.release(path, arg->flags); |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1089 | } else |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1090 | get_node(f, in->nodeid)->open_count ++; |
Miklos Szeredi | 73798f9 | 2004-07-12 15:55:11 +0000 | [diff] [blame] | 1091 | pthread_mutex_unlock(&f->lock); |
| 1092 | |
| 1093 | } else |
| 1094 | send_reply(f, in, res, NULL, 0); |
| 1095 | |
Miklos Szeredi | 9a31cca | 2004-06-26 21:11:25 +0000 | [diff] [blame] | 1096 | if (path) |
| 1097 | free(path); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1100 | static void do_flush(struct fuse *f, struct fuse_in_header *in, |
| 1101 | struct fuse_flush_in *arg) |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1102 | { |
| 1103 | char *path; |
| 1104 | int res; |
| 1105 | |
| 1106 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1107 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1108 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1109 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1110 | printf("FLUSH[%lu]\n", arg->fh); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1111 | fflush(stdout); |
| 1112 | } |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1113 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1114 | if (f->op.flush) |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1115 | res = f->op.flush(path); |
| 1116 | free(path); |
| 1117 | } |
| 1118 | send_reply(f, in, res, NULL, 0); |
| 1119 | } |
| 1120 | |
Miklos Szeredi | 9478e86 | 2002-12-11 09:50:26 +0000 | [diff] [blame] | 1121 | static void do_release(struct fuse *f, struct fuse_in_header *in, |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1122 | struct fuse_release_in *arg) |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1123 | { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1124 | struct node *node; |
| 1125 | char *path; |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1126 | |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1127 | pthread_mutex_lock(&f->lock); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1128 | node = get_node(f, in->nodeid); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1129 | --node->open_count; |
| 1130 | pthread_mutex_unlock(&f->lock); |
| 1131 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1132 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1133 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1134 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1135 | printf("RELEASE[%lu]\n", arg->fh); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1136 | fflush(stdout); |
| 1137 | } |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1138 | if (f->op.release) |
Miklos Szeredi | b321058 | 2004-06-23 13:54:33 +0000 | [diff] [blame] | 1139 | f->op.release(path, arg->flags); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1140 | |
| 1141 | if(node->is_hidden && node->open_count == 0) |
| 1142 | /* can now clean up this hidden file */ |
| 1143 | f->op.unlink(path); |
| 1144 | |
| 1145 | free(path); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1146 | } |
Miklos Szeredi | 556d03d | 2004-06-30 11:13:41 +0000 | [diff] [blame] | 1147 | send_reply(f, in, 0, NULL, 0); |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1150 | static void do_read(struct fuse *f, struct fuse_in_header *in, |
| 1151 | struct fuse_read_in *arg) |
| 1152 | { |
| 1153 | int res; |
| 1154 | char *path; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1155 | char *outbuf = (char *) malloc(sizeof(struct fuse_out_header) + arg->size); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1156 | if (outbuf == NULL) |
| 1157 | send_reply(f, in, -ENOMEM, NULL, 0); |
| 1158 | else { |
| 1159 | struct fuse_out_header *out = (struct fuse_out_header *) outbuf; |
| 1160 | char *buf = outbuf + sizeof(struct fuse_out_header); |
| 1161 | size_t size; |
| 1162 | size_t outsize; |
| 1163 | |
| 1164 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1165 | path = get_path(f, in->nodeid); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1166 | if (path != NULL) { |
| 1167 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1168 | printf("READ[%lu] %u bytes from %llu\n", arg->fh, arg->size, |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1169 | arg->offset); |
| 1170 | fflush(stdout); |
| 1171 | } |
| 1172 | |
| 1173 | res = -ENOSYS; |
| 1174 | if (f->op.read) |
| 1175 | res = f->op.read(path, buf, arg->size, arg->offset); |
| 1176 | free(path); |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1177 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1178 | |
| 1179 | size = 0; |
| 1180 | if (res >= 0) { |
| 1181 | size = res; |
| 1182 | res = 0; |
| 1183 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1184 | printf(" READ[%lu] %u bytes\n", arg->fh, size); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1185 | fflush(stdout); |
| 1186 | } |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1187 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1188 | memset(out, 0, sizeof(struct fuse_out_header)); |
| 1189 | out->unique = in->unique; |
| 1190 | out->error = res; |
| 1191 | outsize = sizeof(struct fuse_out_header) + size; |
| 1192 | |
| 1193 | send_reply_raw(f, outbuf, outsize, 0); |
| 1194 | free(outbuf); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1195 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 1196 | } |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 1197 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1198 | static void do_write(struct fuse *f, struct fuse_in_header *in, |
| 1199 | struct fuse_write_in *arg) |
| 1200 | { |
| 1201 | int res; |
| 1202 | char *path; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 1203 | struct fuse_write_out outarg; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1204 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1205 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1206 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1207 | if (path != NULL) { |
| 1208 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1209 | printf("WRITE%s[%lu] %u bytes to %llu\n", |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1210 | arg->writepage ? "PAGE" : "", arg->fh, arg->size, |
| 1211 | arg->offset); |
Miklos Szeredi | 6ebe234 | 2002-01-06 21:44:16 +0000 | [diff] [blame] | 1212 | fflush(stdout); |
| 1213 | } |
| 1214 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1215 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1216 | if (f->op.write) |
Miklos Szeredi | 6bf8b68 | 2002-10-28 08:49:39 +0000 | [diff] [blame] | 1217 | res = f->op.write(path, PARAM(arg), arg->size, arg->offset); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1218 | free(path); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 1221 | if (res >= 0) { |
| 1222 | outarg.size = res; |
| 1223 | res = 0; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 1226 | send_reply(f, in, res, &outarg, sizeof(outarg)); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1229 | static int default_statfs(struct statfs *buf) |
| 1230 | { |
| 1231 | buf->f_namelen = 255; |
| 1232 | buf->f_bsize = 512; |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 1236 | static void convert_statfs(struct statfs *statfs, struct fuse_kstatfs *kstatfs) |
| 1237 | { |
| 1238 | kstatfs->bsize = statfs->f_bsize; |
| 1239 | kstatfs->blocks = statfs->f_blocks; |
| 1240 | kstatfs->bfree = statfs->f_bfree; |
| 1241 | kstatfs->bavail = statfs->f_bavail; |
| 1242 | kstatfs->files = statfs->f_files; |
| 1243 | kstatfs->ffree = statfs->f_ffree; |
| 1244 | kstatfs->namelen = statfs->f_namelen; |
| 1245 | } |
| 1246 | |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1247 | static void do_statfs(struct fuse *f, struct fuse_in_header *in) |
| 1248 | { |
| 1249 | int res; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1250 | struct fuse_statfs_out arg; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 1251 | struct statfs buf; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1252 | |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1253 | memset(&buf, 0, sizeof(struct statfs)); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1254 | if (f->op.statfs) |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 1255 | res = f->op.statfs("/", &buf); |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1256 | else |
| 1257 | res = default_statfs(&buf); |
| 1258 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1259 | if (res == 0) |
Miklos Szeredi | 77f3994 | 2004-03-25 11:17:52 +0000 | [diff] [blame] | 1260 | convert_statfs(&buf, &arg.st); |
Miklos Szeredi | 4b2bef4 | 2002-01-09 12:23:27 +0000 | [diff] [blame] | 1261 | |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1262 | send_reply(f, in, res, &arg, sizeof(arg)); |
| 1263 | } |
| 1264 | |
Miklos Szeredi | 5e43f2c | 2003-12-12 14:06:41 +0000 | [diff] [blame] | 1265 | static void do_fsync(struct fuse *f, struct fuse_in_header *in, |
| 1266 | struct fuse_fsync_in *inarg) |
| 1267 | { |
| 1268 | int res; |
| 1269 | char *path; |
| 1270 | |
| 1271 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1272 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1273 | if (path != NULL) { |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1274 | if (f->flags & FUSE_DEBUG) { |
Miklos Szeredi | 1eea032 | 2004-09-27 18:50:11 +0000 | [diff] [blame] | 1275 | printf("FSYNC[%lu]\n", inarg->fh); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1276 | fflush(stdout); |
| 1277 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1278 | res = -ENOSYS; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1279 | if (f->op.fsync) |
Miklos Szeredi | 5e43f2c | 2003-12-12 14:06:41 +0000 | [diff] [blame] | 1280 | res = f->op.fsync(path, inarg->datasync); |
| 1281 | free(path); |
| 1282 | } |
| 1283 | send_reply(f, in, res, NULL, 0); |
| 1284 | } |
| 1285 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1286 | static void do_setxattr(struct fuse *f, struct fuse_in_header *in, |
| 1287 | struct fuse_setxattr_in *arg) |
| 1288 | { |
| 1289 | int res; |
| 1290 | char *path; |
| 1291 | char *name = PARAM(arg); |
| 1292 | unsigned char *value = name + strlen(name) + 1; |
| 1293 | |
| 1294 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1295 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1296 | if (path != NULL) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1297 | res = -ENOSYS; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1298 | if (f->op.setxattr) |
| 1299 | res = f->op.setxattr(path, name, value, arg->size, arg->flags); |
| 1300 | free(path); |
| 1301 | } |
| 1302 | send_reply(f, in, res, NULL, 0); |
| 1303 | } |
| 1304 | |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1305 | static int common_getxattr(struct fuse *f, struct fuse_in_header *in, |
| 1306 | const char *name, char *value, size_t size) |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1307 | { |
| 1308 | int res; |
| 1309 | char *path; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1310 | |
| 1311 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1312 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1313 | if (path != NULL) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1314 | res = -ENOSYS; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1315 | if (f->op.getxattr) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1316 | res = f->op.getxattr(path, name, value, size); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1317 | free(path); |
| 1318 | } |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1319 | return res; |
| 1320 | } |
| 1321 | |
| 1322 | static void do_getxattr_read(struct fuse *f, struct fuse_in_header *in, |
| 1323 | const char *name, size_t size) |
| 1324 | { |
| 1325 | int res; |
| 1326 | char *outbuf = (char *) malloc(sizeof(struct fuse_out_header) + size); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1327 | if (outbuf == NULL) |
| 1328 | send_reply(f, in, -ENOMEM, NULL, 0); |
| 1329 | else { |
| 1330 | struct fuse_out_header *out = (struct fuse_out_header *) outbuf; |
| 1331 | char *value = outbuf + sizeof(struct fuse_out_header); |
| 1332 | |
| 1333 | res = common_getxattr(f, in, name, value, size); |
| 1334 | size = 0; |
| 1335 | if (res > 0) { |
| 1336 | size = res; |
| 1337 | res = 0; |
| 1338 | } |
| 1339 | memset(out, 0, sizeof(struct fuse_out_header)); |
| 1340 | out->unique = in->unique; |
| 1341 | out->error = res; |
| 1342 | |
| 1343 | send_reply_raw(f, outbuf, sizeof(struct fuse_out_header) + size, 0); |
| 1344 | free(outbuf); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1345 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1348 | static void do_getxattr_size(struct fuse *f, struct fuse_in_header *in, |
| 1349 | const char *name) |
| 1350 | { |
| 1351 | int res; |
| 1352 | struct fuse_getxattr_out arg; |
| 1353 | |
| 1354 | res = common_getxattr(f, in, name, NULL, 0); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1355 | if (res >= 0) { |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1356 | arg.size = res; |
| 1357 | res = 0; |
| 1358 | } |
| 1359 | send_reply(f, in, res, &arg, sizeof(arg)); |
| 1360 | } |
| 1361 | |
| 1362 | static void do_getxattr(struct fuse *f, struct fuse_in_header *in, |
| 1363 | struct fuse_getxattr_in *arg) |
| 1364 | { |
| 1365 | char *name = PARAM(arg); |
| 1366 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1367 | if (arg->size) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1368 | do_getxattr_read(f, in, name, arg->size); |
| 1369 | else |
| 1370 | do_getxattr_size(f, in, name); |
| 1371 | } |
| 1372 | |
| 1373 | static int common_listxattr(struct fuse *f, struct fuse_in_header *in, |
| 1374 | char *list, size_t size) |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1375 | { |
| 1376 | int res; |
| 1377 | char *path; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1378 | |
| 1379 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1380 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1381 | if (path != NULL) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1382 | res = -ENOSYS; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1383 | if (f->op.listxattr) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1384 | res = f->op.listxattr(path, list, size); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1385 | free(path); |
| 1386 | } |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1387 | return res; |
| 1388 | } |
| 1389 | |
| 1390 | static void do_listxattr_read(struct fuse *f, struct fuse_in_header *in, |
| 1391 | size_t size) |
| 1392 | { |
| 1393 | int res; |
| 1394 | char *outbuf = (char *) malloc(sizeof(struct fuse_out_header) + size); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1395 | if (outbuf == NULL) |
| 1396 | send_reply(f, in, -ENOMEM, NULL, 0); |
| 1397 | else { |
| 1398 | struct fuse_out_header *out = (struct fuse_out_header *) outbuf; |
| 1399 | char *list = outbuf + sizeof(struct fuse_out_header); |
| 1400 | |
| 1401 | res = common_listxattr(f, in, list, size); |
| 1402 | size = 0; |
| 1403 | if (res > 0) { |
| 1404 | size = res; |
| 1405 | res = 0; |
| 1406 | } |
| 1407 | memset(out, 0, sizeof(struct fuse_out_header)); |
| 1408 | out->unique = in->unique; |
| 1409 | out->error = res; |
| 1410 | |
| 1411 | send_reply_raw(f, outbuf, sizeof(struct fuse_out_header) + size, 0); |
| 1412 | free(outbuf); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1413 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1416 | static void do_listxattr_size(struct fuse *f, struct fuse_in_header *in) |
| 1417 | { |
| 1418 | int res; |
| 1419 | struct fuse_getxattr_out arg; |
| 1420 | |
| 1421 | res = common_listxattr(f, in, NULL, 0); |
| 1422 | if (res >= 0) { |
| 1423 | arg.size = res; |
| 1424 | res = 0; |
| 1425 | } |
| 1426 | send_reply(f, in, res, &arg, sizeof(arg)); |
| 1427 | } |
| 1428 | |
| 1429 | static void do_listxattr(struct fuse *f, struct fuse_in_header *in, |
| 1430 | struct fuse_getxattr_in *arg) |
| 1431 | { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1432 | if (arg->size) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1433 | do_listxattr_read(f, in, arg->size); |
| 1434 | else |
| 1435 | do_listxattr_size(f, in); |
| 1436 | } |
| 1437 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1438 | static void do_removexattr(struct fuse *f, struct fuse_in_header *in, |
| 1439 | char *name) |
| 1440 | { |
| 1441 | int res; |
| 1442 | char *path; |
| 1443 | |
| 1444 | res = -ENOENT; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1445 | path = get_path(f, in->nodeid); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1446 | if (path != NULL) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1447 | res = -ENOSYS; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1448 | if (f->op.removexattr) |
| 1449 | res = f->op.removexattr(path, name); |
| 1450 | free(path); |
| 1451 | } |
| 1452 | send_reply(f, in, res, NULL, 0); |
| 1453 | } |
| 1454 | |
| 1455 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1456 | static void free_cmd(struct fuse_cmd *cmd) |
| 1457 | { |
| 1458 | free(cmd->buf); |
| 1459 | free(cmd); |
| 1460 | } |
| 1461 | |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1462 | void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1463 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1464 | struct fuse_in_header *in = (struct fuse_in_header *) cmd->buf; |
| 1465 | void *inarg = cmd->buf + sizeof(struct fuse_in_header); |
| 1466 | size_t argsize; |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1467 | struct fuse_context *ctx = fuse_get_context(); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1468 | |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1469 | dec_avail(f); |
Miklos Szeredi | 3323203 | 2001-11-19 17:55:51 +0000 | [diff] [blame] | 1470 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1471 | if ((f->flags & FUSE_DEBUG)) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1472 | printf("unique: %i, opcode: %s (%i), nodeid: %li, insize: %i\n", |
| 1473 | in->unique, opname(in->opcode), in->opcode, in->nodeid, |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 1474 | cmd->buflen); |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 1475 | fflush(stdout); |
| 1476 | } |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 1477 | |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1478 | ctx->fuse = f; |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 1479 | ctx->uid = in->uid; |
| 1480 | ctx->gid = in->gid; |
Miklos Szeredi | 1f18db5 | 2004-09-27 06:54:49 +0000 | [diff] [blame] | 1481 | ctx->pid = in->pid; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1482 | |
| 1483 | argsize = cmd->buflen - sizeof(struct fuse_in_header); |
| 1484 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1485 | switch (in->opcode) { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1486 | case FUSE_LOOKUP: |
| 1487 | do_lookup(f, in, (char *) inarg); |
| 1488 | break; |
| 1489 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1490 | case FUSE_GETATTR: |
| 1491 | do_getattr(f, in); |
| 1492 | break; |
| 1493 | |
| 1494 | case FUSE_SETATTR: |
| 1495 | do_setattr(f, in, (struct fuse_setattr_in *) inarg); |
| 1496 | break; |
| 1497 | |
| 1498 | case FUSE_READLINK: |
| 1499 | do_readlink(f, in); |
| 1500 | break; |
| 1501 | |
| 1502 | case FUSE_GETDIR: |
| 1503 | do_getdir(f, in); |
| 1504 | break; |
| 1505 | |
| 1506 | case FUSE_MKNOD: |
| 1507 | do_mknod(f, in, (struct fuse_mknod_in *) inarg); |
| 1508 | break; |
| 1509 | |
| 1510 | case FUSE_MKDIR: |
| 1511 | do_mkdir(f, in, (struct fuse_mkdir_in *) inarg); |
| 1512 | break; |
| 1513 | |
| 1514 | case FUSE_UNLINK: |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1515 | do_unlink(f, in, (char *) inarg); |
| 1516 | break; |
| 1517 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1518 | case FUSE_RMDIR: |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 1519 | do_rmdir(f, in, (char *) inarg); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | |
| 1522 | case FUSE_SYMLINK: |
| 1523 | do_symlink(f, in, (char *) inarg, |
| 1524 | ((char *) inarg) + strlen((char *) inarg) + 1); |
| 1525 | break; |
| 1526 | |
| 1527 | case FUSE_RENAME: |
| 1528 | do_rename(f, in, (struct fuse_rename_in *) inarg); |
| 1529 | break; |
| 1530 | |
| 1531 | case FUSE_LINK: |
| 1532 | do_link(f, in, (struct fuse_link_in *) inarg); |
| 1533 | break; |
| 1534 | |
| 1535 | case FUSE_OPEN: |
| 1536 | do_open(f, in, (struct fuse_open_in *) inarg); |
| 1537 | break; |
| 1538 | |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1539 | case FUSE_FLUSH: |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1540 | do_flush(f, in, (struct fuse_flush_in *) inarg); |
Miklos Szeredi | e2e4ac2 | 2004-05-18 08:45:28 +0000 | [diff] [blame] | 1541 | break; |
| 1542 | |
Miklos Szeredi | 9478e86 | 2002-12-11 09:50:26 +0000 | [diff] [blame] | 1543 | case FUSE_RELEASE: |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 1544 | do_release(f, in, (struct fuse_release_in *) inarg); |
Miklos Szeredi | 9478e86 | 2002-12-11 09:50:26 +0000 | [diff] [blame] | 1545 | break; |
| 1546 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1547 | case FUSE_READ: |
| 1548 | do_read(f, in, (struct fuse_read_in *) inarg); |
| 1549 | break; |
| 1550 | |
| 1551 | case FUSE_WRITE: |
| 1552 | do_write(f, in, (struct fuse_write_in *) inarg); |
| 1553 | break; |
| 1554 | |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 1555 | case FUSE_STATFS: |
| 1556 | do_statfs(f, in); |
| 1557 | break; |
| 1558 | |
Miklos Szeredi | 5e43f2c | 2003-12-12 14:06:41 +0000 | [diff] [blame] | 1559 | case FUSE_FSYNC: |
| 1560 | do_fsync(f, in, (struct fuse_fsync_in *) inarg); |
| 1561 | break; |
| 1562 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1563 | case FUSE_SETXATTR: |
| 1564 | do_setxattr(f, in, (struct fuse_setxattr_in *) inarg); |
| 1565 | break; |
| 1566 | |
| 1567 | case FUSE_GETXATTR: |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1568 | do_getxattr(f, in, (struct fuse_getxattr_in *) inarg); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1569 | break; |
| 1570 | |
| 1571 | case FUSE_LISTXATTR: |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1572 | do_listxattr(f, in, (struct fuse_getxattr_in *) inarg); |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | case FUSE_REMOVEXATTR: |
| 1576 | do_removexattr(f, in, (char *) inarg); |
| 1577 | break; |
| 1578 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1579 | default: |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1580 | send_reply(f, in, -ENOSYS, NULL, 0); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1581 | } |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1582 | |
| 1583 | free_cmd(cmd); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1586 | int __fuse_exited(struct fuse* f) |
| 1587 | { |
| 1588 | return f->exited; |
| 1589 | } |
| 1590 | |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1591 | struct fuse_cmd *__fuse_read_cmd(struct fuse *f) |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1592 | { |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1593 | ssize_t res; |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1594 | struct fuse_cmd *cmd; |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1595 | struct fuse_in_header *in; |
| 1596 | void *inarg; |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1597 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1598 | cmd = (struct fuse_cmd *) malloc(sizeof(struct fuse_cmd)); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1599 | if (cmd == NULL) { |
| 1600 | fprintf(stderr, "fuse: failed to allocate cmd in read\n"); |
| 1601 | return NULL; |
| 1602 | } |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1603 | cmd->buf = (char *) malloc(FUSE_MAX_IN); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1604 | if (cmd->buf == NULL) { |
| 1605 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 1606 | free(cmd); |
| 1607 | return NULL; |
| 1608 | } |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1609 | in = (struct fuse_in_header *) cmd->buf; |
| 1610 | inarg = cmd->buf + sizeof(struct fuse_in_header); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1611 | |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1612 | res = read(f->fd, cmd->buf, FUSE_MAX_IN); |
| 1613 | if (res == -1) { |
| 1614 | free_cmd(cmd); |
| 1615 | if (__fuse_exited(f) || errno == EINTR) |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1616 | return NULL; |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1617 | |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1618 | /* ENODEV means we got unmounted, so we silenty return failure */ |
| 1619 | if (errno != ENODEV) { |
| 1620 | /* BAD... This will happen again */ |
| 1621 | perror("fuse: reading device"); |
| 1622 | } |
| 1623 | |
| 1624 | fuse_exit(f); |
| 1625 | return NULL; |
| 1626 | } |
| 1627 | if ((size_t) res < sizeof(struct fuse_in_header)) { |
| 1628 | free_cmd(cmd); |
| 1629 | /* Cannot happen */ |
| 1630 | fprintf(stderr, "short read on fuse device\n"); |
| 1631 | fuse_exit(f); |
| 1632 | return NULL; |
| 1633 | } |
| 1634 | cmd->buflen = res; |
| 1635 | |
| 1636 | /* Forget is special, it can be done without messing with threads. */ |
| 1637 | if (in->opcode == FUSE_FORGET) { |
| 1638 | do_forget(f, in, (struct fuse_forget_in *) inarg); |
| 1639 | free_cmd(cmd); |
| 1640 | return NULL; |
| 1641 | } |
Miklos Szeredi | 99ddf0e | 2001-11-25 17:19:59 +0000 | [diff] [blame] | 1642 | |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1643 | return cmd; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1646 | int fuse_loop(struct fuse *f) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1647 | { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1648 | if (f == NULL) |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1649 | return -1; |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1650 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1651 | while (1) { |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1652 | struct fuse_cmd *cmd; |
| 1653 | |
Miklos Szeredi | 65cf7c7 | 2004-06-30 11:34:56 +0000 | [diff] [blame] | 1654 | if (__fuse_exited(f)) |
Miklos Szeredi | 874e3c1 | 2004-11-01 23:15:20 +0000 | [diff] [blame] | 1655 | break; |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1656 | |
| 1657 | cmd = __fuse_read_cmd(f); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1658 | if (cmd == NULL) |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1659 | continue; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1660 | |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1661 | __fuse_process_cmd(f, cmd); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1662 | } |
Miklos Szeredi | 874e3c1 | 2004-11-01 23:15:20 +0000 | [diff] [blame] | 1663 | f->exited = 0; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1664 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1667 | int fuse_invalidate(struct fuse *f, const char *path) |
| 1668 | { |
| 1669 | int res; |
| 1670 | int err; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1671 | nodeid_t nodeid; |
| 1672 | unsigned long ino; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1673 | struct fuse_user_header h; |
| 1674 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1675 | err = path_lookup(f, path, &nodeid, &ino); |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1676 | if (err) { |
| 1677 | if (err == -ENOENT) |
| 1678 | return 0; |
| 1679 | else |
| 1680 | return err; |
| 1681 | } |
| 1682 | |
| 1683 | memset(&h, 0, sizeof(struct fuse_user_header)); |
| 1684 | h.opcode = FUSE_INVALIDATE; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1685 | h.nodeid = nodeid; |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1686 | h.ino = ino; |
| 1687 | |
| 1688 | if ((f->flags & FUSE_DEBUG)) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1689 | printf("INVALIDATE nodeid: %li\n", nodeid); |
Miklos Szeredi | 891b874 | 2004-07-29 09:27:49 +0000 | [diff] [blame] | 1690 | fflush(stdout); |
| 1691 | } |
| 1692 | |
| 1693 | res = write(f->fd, &h, sizeof(struct fuse_user_header)); |
| 1694 | if (res == -1) { |
| 1695 | if (errno != ENOENT) { |
| 1696 | perror("fuse: writing device"); |
| 1697 | return -errno; |
| 1698 | } |
| 1699 | } |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1703 | void fuse_exit(struct fuse *f) |
| 1704 | { |
| 1705 | f->exited = 1; |
| 1706 | } |
| 1707 | |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1708 | struct fuse_context *fuse_get_context() |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1709 | { |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1710 | static struct fuse_context context; |
| 1711 | if (fuse_getcontext) |
| 1712 | return fuse_getcontext(); |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1713 | else |
Miklos Szeredi | d169f31 | 2004-09-22 08:48:26 +0000 | [diff] [blame] | 1714 | return &context; |
| 1715 | } |
| 1716 | |
| 1717 | void __fuse_set_getcontext_func(struct fuse_context *(*func)(void)) |
| 1718 | { |
| 1719 | fuse_getcontext = func; |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1722 | static int check_version(struct fuse *f) |
| 1723 | { |
| 1724 | int res; |
Miklos Szeredi | f3845c4 | 2004-11-20 11:18:34 +0000 | [diff] [blame] | 1725 | const char *version_file = FUSE_VERSION_FILE; |
| 1726 | FILE *vf = fopen(version_file, "r"); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1727 | if (vf == NULL) { |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame^] | 1728 | version_file = FUSE_VERSION_FILE_OLD; |
Miklos Szeredi | f3845c4 | 2004-11-20 11:18:34 +0000 | [diff] [blame] | 1729 | vf = fopen(version_file, "r"); |
| 1730 | if (vf == NULL) { |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame^] | 1731 | struct stat tmp; |
| 1732 | if (stat(FUSE_DEV_OLD, &tmp) != -1) { |
| 1733 | fprintf(stderr, "fuse: kernel interface too old, need >= %i.%i\n", |
| 1734 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); |
| 1735 | return -1; |
| 1736 | } else { |
| 1737 | fprintf(stderr, "fuse: warning: version of kernel interface unknown\n"); |
| 1738 | return 0; |
| 1739 | } |
Miklos Szeredi | f3845c4 | 2004-11-20 11:18:34 +0000 | [diff] [blame] | 1740 | } |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1741 | } |
| 1742 | res = fscanf(vf, "%i.%i", &f->majorver, &f->minorver); |
| 1743 | fclose(vf); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1744 | if (res != 2) { |
Miklos Szeredi | f3845c4 | 2004-11-20 11:18:34 +0000 | [diff] [blame] | 1745 | fprintf(stderr, "fuse: error reading %s\n", version_file); |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1746 | return -1; |
| 1747 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1748 | if (f->majorver != FUSE_KERNEL_VERSION) { |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1749 | fprintf(stderr, "fuse: bad kernel interface major version: needs %i\n", |
| 1750 | FUSE_KERNEL_VERSION); |
| 1751 | return -1; |
| 1752 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1753 | if (f->minorver < FUSE_KERNEL_MINOR_VERSION) { |
Miklos Szeredi | 256739a | 2004-11-20 12:22:37 +0000 | [diff] [blame] | 1754 | fprintf(stderr, "fuse: kernel interface too old: need >= %i.%i\n", |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1755 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); |
| 1756 | return -1; |
| 1757 | } |
| 1758 | |
| 1759 | return 0; |
| 1760 | } |
| 1761 | |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1762 | |
| 1763 | int fuse_is_lib_option(const char *opt) |
| 1764 | { |
| 1765 | if (strcmp(opt, "debug") == 0 || |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1766 | strcmp(opt, "hard_remove") == 0 || |
| 1767 | strcmp(opt, "use_ino") == 0) |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1768 | return 1; |
| 1769 | else |
| 1770 | return 0; |
| 1771 | } |
| 1772 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1773 | static int parse_lib_opts(struct fuse *f, const char *opts) |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1774 | { |
| 1775 | if (opts) { |
| 1776 | char *xopts = strdup(opts); |
| 1777 | char *s = xopts; |
| 1778 | char *opt; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1779 | |
| 1780 | if (xopts == NULL) |
| 1781 | return -1; |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1782 | |
| 1783 | while((opt = strsep(&s, ","))) { |
| 1784 | if (strcmp(opt, "debug") == 0) |
| 1785 | f->flags |= FUSE_DEBUG; |
| 1786 | else if (strcmp(opt, "hard_remove") == 0) |
| 1787 | f->flags |= FUSE_HARD_REMOVE; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1788 | else if (strcmp(opt, "use_ino") == 0) |
| 1789 | f->flags |= FUSE_USE_INO; |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1790 | else |
| 1791 | fprintf(stderr, "fuse: warning: unknown option `%s'\n", opt); |
| 1792 | } |
| 1793 | free(xopts); |
| 1794 | } |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1795 | return 0; |
Miklos Szeredi | bd7661b | 2004-07-23 17:16:29 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | struct fuse *fuse_new(int fd, const char *opts, const struct fuse_operations *op) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1799 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1800 | struct fuse *f; |
| 1801 | struct node *root; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1802 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1803 | f = (struct fuse *) calloc(1, sizeof(struct fuse)); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1804 | if (f == NULL) |
| 1805 | goto out; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 1806 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1807 | if (check_version(f) == -1) |
| 1808 | goto out_free; |
Miklos Szeredi | c40748a | 2004-02-20 16:38:45 +0000 | [diff] [blame] | 1809 | |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1810 | if (parse_lib_opts(f, opts) == -1) |
| 1811 | goto out_free; |
| 1812 | |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 1813 | f->fd = fd; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1814 | f->ctr = 0; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1815 | f->generation = 0; |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 1816 | /* FIXME: Dynamic hash table */ |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1817 | f->name_table_size = 14057; |
| 1818 | f->name_table = (struct node **) |
| 1819 | calloc(1, sizeof(struct node *) * f->name_table_size); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1820 | if (f->name_table == NULL) |
| 1821 | goto out_free; |
| 1822 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1823 | f->id_table_size = 14057; |
| 1824 | f->id_table = (struct node **) |
| 1825 | calloc(1, sizeof(struct node *) * f->id_table_size); |
| 1826 | if (f->id_table == NULL) |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1827 | goto out_free_name_table; |
| 1828 | |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame^] | 1829 | #ifndef USE_UCLIBC |
| 1830 | pthread_mutex_init(&f->lock, NULL); |
| 1831 | #else |
| 1832 | { |
| 1833 | pthread_mutexattr_t attr; |
| 1834 | pthread_mutexattr_init(&attr); |
| 1835 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); |
| 1836 | pthread_mutex_init(&f->lock, &attr); |
| 1837 | pthread_mutexattr_destroy(&attr); |
| 1838 | } |
| 1839 | #endif |
Miklos Szeredi | 3323203 | 2001-11-19 17:55:51 +0000 | [diff] [blame] | 1840 | f->numworker = 0; |
| 1841 | f->numavail = 0; |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 1842 | f->op = *op; |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 1843 | f->exited = 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1844 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1845 | root = (struct node *) calloc(1, sizeof(struct node)); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1846 | if (root == NULL) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1847 | goto out_free_id_table; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1848 | |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 1849 | root->mode = 0; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1850 | root->rdev = 0; |
| 1851 | root->name = strdup("/"); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1852 | if (root->name == NULL) |
| 1853 | goto out_free_root; |
| 1854 | |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1855 | root->parent = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1856 | root->nodeid = FUSE_ROOT_ID; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 1857 | root->generation = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1858 | hash_id(f, root); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1859 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1860 | return f; |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1861 | |
| 1862 | out_free_root: |
| 1863 | free(root); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1864 | out_free_id_table: |
| 1865 | free(f->id_table); |
Miklos Szeredi | b2cf956 | 2004-09-16 08:42:40 +0000 | [diff] [blame] | 1866 | out_free_name_table: |
| 1867 | free(f->name_table); |
| 1868 | out_free: |
| 1869 | free(f); |
| 1870 | out: |
| 1871 | fprintf(stderr, "fuse: failed to allocate fuse object\n"); |
| 1872 | return NULL; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1875 | void fuse_destroy(struct fuse *f) |
| 1876 | { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1877 | size_t i; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1878 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1879 | struct node *node; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1880 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1881 | for (node = f->id_table[i]; node != NULL; node = node->id_next) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1882 | if (node->is_hidden) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1883 | char *path = get_path(f, node->nodeid); |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1884 | if (path) |
| 1885 | f->op.unlink(path); |
| 1886 | } |
| 1887 | } |
| 1888 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1889 | for (i = 0; i < f->id_table_size; i++) { |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1890 | struct node *node; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1891 | struct node *next; |
Miklos Szeredi | 1ea9c96 | 2004-06-24 21:00:00 +0000 | [diff] [blame] | 1892 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1893 | for (node = f->id_table[i]; node != NULL; node = next) { |
| 1894 | next = node->id_next; |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1895 | free_node(node); |
| 1896 | } |
| 1897 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 1898 | free(f->id_table); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1899 | free(f->name_table); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 1900 | pthread_mutex_destroy(&f->lock); |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 1901 | free(f); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1902 | } |