Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
| 3 | Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> |
| 4 | |
| 5 | This program can be distributed under the terms of the GNU LGPL. |
| 6 | See the file COPYING.LIB |
| 7 | */ |
| 8 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 9 | #include <config.h> |
| 10 | #include "fuse_lowlevel_i.h" |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 11 | #include "fuse_kernel.h" |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <string.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <unistd.h> |
| 17 | #include <limits.h> |
| 18 | #include <errno.h> |
| 19 | #include <assert.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/param.h> |
| 22 | #include <sys/uio.h> |
| 23 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 24 | #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg))) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 25 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 26 | struct fuse_cmd { |
| 27 | char *buf; |
| 28 | size_t buflen; |
| 29 | }; |
| 30 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 31 | struct fuse_req { |
| 32 | struct fuse_ll *f; |
| 33 | uint64_t unique; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 34 | struct fuse_ctx ctx; |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 37 | #ifndef USE_UCLIBC |
| 38 | #define mutex_init(mut) pthread_mutex_init(mut, NULL) |
| 39 | #else |
| 40 | static void mutex_init(pthread_mutex_t *mut) |
| 41 | { |
| 42 | pthread_mutexattr_t attr; |
| 43 | pthread_mutexattr_init(&attr); |
| 44 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP); |
| 45 | pthread_mutex_init(mut, &attr); |
| 46 | pthread_mutexattr_destroy(&attr); |
| 47 | } |
| 48 | #endif |
| 49 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 50 | static const char *opname(enum fuse_opcode opcode) |
| 51 | { |
| 52 | switch (opcode) { |
| 53 | case FUSE_LOOKUP: return "LOOKUP"; |
| 54 | case FUSE_FORGET: return "FORGET"; |
| 55 | case FUSE_GETATTR: return "GETATTR"; |
| 56 | case FUSE_SETATTR: return "SETATTR"; |
| 57 | case FUSE_READLINK: return "READLINK"; |
| 58 | case FUSE_SYMLINK: return "SYMLINK"; |
| 59 | case FUSE_MKNOD: return "MKNOD"; |
| 60 | case FUSE_MKDIR: return "MKDIR"; |
| 61 | case FUSE_UNLINK: return "UNLINK"; |
| 62 | case FUSE_RMDIR: return "RMDIR"; |
| 63 | case FUSE_RENAME: return "RENAME"; |
| 64 | case FUSE_LINK: return "LINK"; |
| 65 | case FUSE_OPEN: return "OPEN"; |
| 66 | case FUSE_READ: return "READ"; |
| 67 | case FUSE_WRITE: return "WRITE"; |
| 68 | case FUSE_STATFS: return "STATFS"; |
| 69 | case FUSE_FLUSH: return "FLUSH"; |
| 70 | case FUSE_RELEASE: return "RELEASE"; |
| 71 | case FUSE_FSYNC: return "FSYNC"; |
| 72 | case FUSE_SETXATTR: return "SETXATTR"; |
| 73 | case FUSE_GETXATTR: return "GETXATTR"; |
| 74 | case FUSE_LISTXATTR: return "LISTXATTR"; |
| 75 | case FUSE_REMOVEXATTR: return "REMOVEXATTR"; |
| 76 | case FUSE_INIT: return "INIT"; |
| 77 | case FUSE_OPENDIR: return "OPENDIR"; |
| 78 | case FUSE_READDIR: return "READDIR"; |
| 79 | case FUSE_RELEASEDIR: return "RELEASEDIR"; |
| 80 | case FUSE_FSYNCDIR: return "FSYNCDIR"; |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 81 | case FUSE_GETLK: return "GETLK"; |
| 82 | case FUSE_SETLK: return "SETLK"; |
| 83 | case FUSE_SETLKW: return "SETLKW"; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 84 | default: return "???"; |
| 85 | } |
| 86 | } |
| 87 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 88 | static inline void fuse_dec_avail(struct fuse_ll *f) |
| 89 | { |
| 90 | pthread_mutex_lock(&f->worker_lock); |
| 91 | f->numavail --; |
| 92 | pthread_mutex_unlock(&f->worker_lock); |
| 93 | } |
| 94 | |
| 95 | static inline void fuse_inc_avail(struct fuse_ll *f) |
| 96 | { |
| 97 | pthread_mutex_lock(&f->worker_lock); |
| 98 | f->numavail ++; |
| 99 | pthread_mutex_unlock(&f->worker_lock); |
| 100 | } |
| 101 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 102 | static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 103 | { |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 104 | attr->ino = stbuf->st_ino; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 105 | attr->mode = stbuf->st_mode; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 106 | attr->nlink = stbuf->st_nlink; |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 107 | attr->uid = stbuf->st_uid; |
| 108 | attr->gid = stbuf->st_gid; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 109 | attr->rdev = stbuf->st_rdev; |
| 110 | attr->size = stbuf->st_size; |
| 111 | attr->blocks = stbuf->st_blocks; |
| 112 | attr->atime = stbuf->st_atime; |
| 113 | attr->mtime = stbuf->st_mtime; |
| 114 | attr->ctime = stbuf->st_ctime; |
| 115 | #ifdef HAVE_STRUCT_STAT_ST_ATIM |
| 116 | attr->atimensec = stbuf->st_atim.tv_nsec; |
| 117 | attr->mtimensec = stbuf->st_mtim.tv_nsec; |
| 118 | attr->ctimensec = stbuf->st_ctim.tv_nsec; |
| 119 | #endif |
| 120 | } |
| 121 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 122 | static void convert_attr(const struct fuse_attr *attr, struct stat *stbuf) |
| 123 | { |
| 124 | stbuf->st_mode = attr->mode; |
| 125 | stbuf->st_uid = attr->uid; |
| 126 | stbuf->st_gid = attr->gid; |
| 127 | stbuf->st_size = attr->size; |
| 128 | stbuf->st_atime = attr->atime; |
| 129 | stbuf->st_mtime = attr->mtime; |
| 130 | stbuf->st_ctime = attr->ctime; |
| 131 | #ifdef HAVE_STRUCT_STAT_ST_ATIM |
| 132 | stbuf->st_atim.tv_nsec = attr->atimensec; |
| 133 | stbuf->st_mtim.tv_nsec = attr->mtimensec; |
| 134 | stbuf->st_ctim.tv_nsec = attr->ctimensec; |
| 135 | #endif |
| 136 | } |
| 137 | |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 138 | static void convert_file_lock(const struct fuse_file_lock *ffl, |
| 139 | struct fuse_lock_param *lk) |
| 140 | { |
| 141 | lk->type = ffl->type; |
| 142 | lk->start = ffl->start; |
| 143 | lk->end = ffl->end; |
| 144 | lk->owner = ffl->owner; |
| 145 | lk->pid = ffl->pid; |
| 146 | } |
| 147 | |
| 148 | static void convert_lock_param(const struct fuse_lock_param *lk, |
| 149 | struct fuse_file_lock *ffl) |
| 150 | { |
| 151 | ffl->type = lk->type; |
| 152 | ffl->start = lk->start; |
| 153 | ffl->end = lk->end; |
| 154 | ffl->owner = lk->owner; |
| 155 | ffl->pid = lk->pid; |
| 156 | } |
| 157 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 158 | static size_t iov_length(const struct iovec *iov, size_t count) |
| 159 | { |
| 160 | size_t seg; |
| 161 | size_t ret = 0; |
| 162 | |
| 163 | for (seg = 0; seg < count; seg++) |
| 164 | ret += iov[seg].iov_len; |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | static int send_reply_raw(struct fuse_ll *f, const struct iovec iov[], |
| 169 | size_t count) |
| 170 | { |
| 171 | int res; |
| 172 | unsigned outsize = iov_length(iov, count); |
| 173 | struct fuse_out_header *out = (struct fuse_out_header *) iov[0].iov_base; |
| 174 | out->len = outsize; |
| 175 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 176 | if (f->debug) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 177 | printf(" unique: %llu, error: %i (%s), outsize: %i\n", |
| 178 | out->unique, out->error, strerror(-out->error), outsize); |
| 179 | fflush(stdout); |
| 180 | } |
| 181 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 182 | /* This needs to be done before the reply, otherwise the scheduler |
| 183 | could play tricks with us, and only let the counter be |
| 184 | increased long after the operation is done */ |
| 185 | fuse_inc_avail(f); |
| 186 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 187 | res = writev(f->fd, iov, count); |
| 188 | if (res == -1) { |
| 189 | /* ENOENT means the operation was interrupted */ |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 190 | if (!fuse_ll_exited(f) && errno != ENOENT) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 191 | perror("fuse: writing device"); |
| 192 | return -errno; |
| 193 | } |
| 194 | return 0; |
| 195 | } |
| 196 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 197 | static int send_reply(struct fuse_ll *f, uint64_t unique, int error, |
| 198 | const void *arg, size_t argsize) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 199 | { |
| 200 | struct fuse_out_header out; |
| 201 | struct iovec iov[2]; |
| 202 | size_t count; |
| 203 | |
| 204 | if (error <= -1000 || error > 0) { |
| 205 | fprintf(stderr, "fuse: bad error value: %i\n", error); |
| 206 | error = -ERANGE; |
| 207 | } |
| 208 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 209 | out.unique = unique; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 210 | out.error = error; |
| 211 | count = 1; |
| 212 | iov[0].iov_base = &out; |
| 213 | iov[0].iov_len = sizeof(struct fuse_out_header); |
| 214 | if (argsize && !error) { |
| 215 | count++; |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 216 | iov[1].iov_base = (void *) arg; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 217 | iov[1].iov_len = argsize; |
| 218 | } |
| 219 | return send_reply_raw(f, iov, count); |
| 220 | } |
| 221 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 222 | size_t fuse_dirent_size(size_t namelen) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 223 | { |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 224 | return FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + namelen); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 227 | char *fuse_add_dirent(char *buf, const char *name, const struct stat *stat, |
| 228 | off_t off) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 229 | { |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 230 | unsigned namelen = strlen(name); |
| 231 | unsigned entlen = FUSE_NAME_OFFSET + namelen; |
| 232 | unsigned entsize = fuse_dirent_size(namelen); |
| 233 | unsigned padlen = entsize - entlen; |
| 234 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 235 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 236 | dirent->ino = stat->st_ino; |
| 237 | dirent->off = off; |
| 238 | dirent->namelen = namelen; |
| 239 | dirent->type = (stat->st_mode & 0170000) >> 12; |
| 240 | strncpy(dirent->name, name, namelen); |
| 241 | if (padlen) |
| 242 | memset(buf + entlen, 0, padlen); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 243 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 244 | return buf + entsize; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 247 | static void convert_statfs(const struct statfs *statfs, |
| 248 | struct fuse_kstatfs *kstatfs) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 249 | { |
| 250 | kstatfs->bsize = statfs->f_bsize; |
| 251 | kstatfs->blocks = statfs->f_blocks; |
| 252 | kstatfs->bfree = statfs->f_bfree; |
| 253 | kstatfs->bavail = statfs->f_bavail; |
| 254 | kstatfs->files = statfs->f_files; |
| 255 | kstatfs->ffree = statfs->f_ffree; |
| 256 | kstatfs->namelen = statfs->f_namelen; |
| 257 | } |
| 258 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 259 | static void free_req(fuse_req_t req) |
| 260 | { |
| 261 | free(req); |
| 262 | } |
| 263 | |
| 264 | static int send_reply_req(fuse_req_t req, const void *arg, size_t argsize) |
| 265 | { |
| 266 | int res = send_reply(req->f, req->unique, 0, arg, argsize); |
| 267 | free_req(req); |
| 268 | return res; |
| 269 | } |
| 270 | |
| 271 | int fuse_reply_err(fuse_req_t req, int err) |
| 272 | { |
| 273 | int res = send_reply(req->f, req->unique, -err, NULL, 0); |
| 274 | free_req(req); |
| 275 | return res; |
| 276 | } |
| 277 | |
| 278 | int fuse_reply_none(fuse_req_t req) |
| 279 | { |
| 280 | free_req(req); |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static unsigned long calc_timeout_sec(double t) |
| 285 | { |
| 286 | if (t > (double) ULONG_MAX) |
| 287 | return ULONG_MAX; |
| 288 | else if (t < 0.0) |
| 289 | return 0; |
| 290 | else |
| 291 | return (unsigned long) t; |
| 292 | } |
| 293 | |
| 294 | static unsigned int calc_timeout_nsec(double t) |
| 295 | { |
| 296 | double f = t - (double) calc_timeout_sec(t); |
| 297 | if (f < 0.0) |
| 298 | return 0; |
| 299 | else if (f >= 0.999999999) |
| 300 | return 999999999; |
| 301 | else |
| 302 | return (unsigned int) (f * 1.0e9); |
| 303 | } |
| 304 | |
| 305 | int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e) |
| 306 | { |
| 307 | struct fuse_entry_out arg; |
| 308 | |
| 309 | memset(&arg, 0, sizeof(arg)); |
| 310 | arg.nodeid = e->ino; |
| 311 | arg.generation = e->generation; |
| 312 | arg.entry_valid = calc_timeout_sec(e->entry_timeout); |
| 313 | arg.entry_valid_nsec = calc_timeout_nsec(e->entry_timeout); |
| 314 | arg.attr_valid = calc_timeout_sec(e->attr_timeout); |
| 315 | arg.attr_valid_nsec = calc_timeout_nsec(e->attr_timeout); |
| 316 | convert_stat(&e->attr, &arg.attr); |
| 317 | |
| 318 | return send_reply_req(req, &arg, sizeof(arg)); |
| 319 | } |
| 320 | |
| 321 | int fuse_reply_attr(fuse_req_t req, const struct stat *attr, |
| 322 | double attr_timeout) |
| 323 | { |
| 324 | struct fuse_attr_out arg; |
| 325 | |
| 326 | memset(&arg, 0, sizeof(arg)); |
| 327 | arg.attr_valid = calc_timeout_sec(attr_timeout); |
| 328 | arg.attr_valid_nsec = calc_timeout_nsec(attr_timeout); |
| 329 | convert_stat(attr, &arg.attr); |
| 330 | |
| 331 | return send_reply_req(req, &arg, sizeof(arg)); |
| 332 | } |
| 333 | |
| 334 | int fuse_reply_readlink(fuse_req_t req, const char *link) |
| 335 | { |
| 336 | return send_reply_req(req, link, strlen(link)); |
| 337 | } |
| 338 | |
| 339 | int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *f) |
| 340 | { |
| 341 | struct fuse_open_out arg; |
| 342 | |
| 343 | memset(&arg, 0, sizeof(arg)); |
| 344 | arg.fh = f->fh; |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 345 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 346 | return send_reply_req(req, &arg, sizeof(arg)); |
| 347 | } |
| 348 | |
| 349 | int fuse_reply_write(fuse_req_t req, size_t count) |
| 350 | { |
| 351 | struct fuse_write_out arg; |
| 352 | |
| 353 | memset(&arg, 0, sizeof(arg)); |
| 354 | arg.size = count; |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 355 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 356 | return send_reply_req(req, &arg, sizeof(arg)); |
| 357 | } |
| 358 | |
| 359 | int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size) |
| 360 | { |
| 361 | return send_reply_req(req, buf, size); |
| 362 | } |
| 363 | |
| 364 | int fuse_reply_statfs(fuse_req_t req, const struct statfs *statfs) |
| 365 | { |
| 366 | struct fuse_statfs_out arg; |
| 367 | |
| 368 | memset(&arg, 0, sizeof(arg)); |
| 369 | convert_statfs(statfs, &arg.st); |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 370 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 371 | return send_reply_req(req, &arg, sizeof(arg)); |
| 372 | } |
| 373 | |
| 374 | int fuse_reply_xattr(fuse_req_t req, size_t count) |
| 375 | { |
| 376 | struct fuse_getxattr_out arg; |
| 377 | |
| 378 | memset(&arg, 0, sizeof(arg)); |
| 379 | arg.size = count; |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 380 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 381 | return send_reply_req(req, &arg, sizeof(arg)); |
| 382 | } |
| 383 | |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 384 | int fuse_reply_getlk(fuse_req_t req, const struct fuse_lock_param *lk) |
| 385 | { |
| 386 | struct fuse_lk_in_out arg; |
| 387 | |
| 388 | memset(&arg, 0, sizeof(arg)); |
| 389 | convert_lock_param(lk, &arg.lk); |
| 390 | |
| 391 | return send_reply_req(req, &arg, sizeof(arg)); |
| 392 | } |
| 393 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 394 | static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, char *name) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 395 | { |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 396 | if (req->f->op.lookup) |
| 397 | req->f->op.lookup(req, nodeid, name); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 398 | else |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 399 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 402 | static void do_forget(fuse_req_t req, fuse_ino_t nodeid, |
| 403 | struct fuse_forget_in *arg) |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 404 | { |
| 405 | if (req->f->op.forget) |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 406 | req->f->op.forget(req, nodeid, arg->nlookup); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static void do_getattr(fuse_req_t req, fuse_ino_t nodeid) |
| 410 | { |
| 411 | if (req->f->op.getattr) |
| 412 | req->f->op.getattr(req, nodeid); |
| 413 | else |
| 414 | fuse_reply_err(req, ENOSYS); |
| 415 | } |
| 416 | |
| 417 | static void do_setattr(fuse_req_t req, fuse_ino_t nodeid, |
| 418 | struct fuse_setattr_in *arg) |
| 419 | { |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 420 | if (req->f->op.setattr) { |
| 421 | struct stat stbuf; |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 422 | memset(&stbuf, 0, sizeof(stbuf)); |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 423 | convert_attr(&arg->attr, &stbuf); |
| 424 | req->f->op.setattr(req, nodeid, &stbuf, arg->valid); |
| 425 | } else |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 426 | fuse_reply_err(req, ENOSYS); |
| 427 | } |
| 428 | |
| 429 | static void do_readlink(fuse_req_t req, fuse_ino_t nodeid) |
| 430 | { |
| 431 | if (req->f->op.readlink) |
| 432 | req->f->op.readlink(req, nodeid); |
| 433 | else |
| 434 | fuse_reply_err(req, ENOSYS); |
| 435 | } |
| 436 | |
| 437 | static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, |
| 438 | struct fuse_mknod_in *arg) |
| 439 | { |
| 440 | if (req->f->op.mknod) |
| 441 | req->f->op.mknod(req, nodeid, PARAM(arg), arg->mode, arg->rdev); |
| 442 | else |
| 443 | fuse_reply_err(req, ENOSYS); |
| 444 | } |
| 445 | |
| 446 | static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, |
| 447 | struct fuse_mkdir_in *arg) |
| 448 | { |
| 449 | if (req->f->op.mkdir) |
| 450 | req->f->op.mkdir(req, nodeid, PARAM(arg), arg->mode); |
| 451 | else |
| 452 | fuse_reply_err(req, ENOSYS); |
| 453 | } |
| 454 | |
| 455 | static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, char *name) |
| 456 | { |
| 457 | if (req->f->op.unlink) |
| 458 | req->f->op.unlink(req, nodeid, name); |
| 459 | else |
| 460 | fuse_reply_err(req, ENOSYS); |
| 461 | } |
| 462 | |
| 463 | static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, char *name) |
| 464 | { |
| 465 | if (req->f->op.rmdir) |
| 466 | req->f->op.rmdir(req, nodeid, name); |
| 467 | else |
| 468 | fuse_reply_err(req, ENOSYS); |
| 469 | } |
| 470 | |
| 471 | static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, char *name, |
| 472 | char *link) |
| 473 | { |
| 474 | if (req->f->op.symlink) |
| 475 | req->f->op.symlink(req, link, nodeid, name); |
| 476 | else |
| 477 | fuse_reply_err(req, ENOSYS); |
| 478 | } |
| 479 | |
| 480 | static void do_rename(fuse_req_t req, fuse_ino_t nodeid, |
| 481 | struct fuse_rename_in *arg) |
| 482 | { |
| 483 | char *oldname = PARAM(arg); |
| 484 | char *newname = oldname + strlen(oldname) + 1; |
| 485 | |
| 486 | if (req->f->op.rename) |
| 487 | req->f->op.rename(req, nodeid, oldname, arg->newdir, newname); |
| 488 | else |
| 489 | fuse_reply_err(req, ENOSYS); |
| 490 | } |
| 491 | |
| 492 | static void do_link(fuse_req_t req, fuse_ino_t nodeid, |
| 493 | struct fuse_link_in *arg) |
| 494 | { |
| 495 | if (req->f->op.link) |
| 496 | req->f->op.link(req, arg->oldnodeid, nodeid, PARAM(arg)); |
| 497 | else |
| 498 | fuse_reply_err(req, ENOSYS); |
| 499 | } |
| 500 | |
| 501 | static void do_open(fuse_req_t req, fuse_ino_t nodeid, |
| 502 | struct fuse_open_in *arg) |
| 503 | { |
| 504 | struct fuse_file_info fi; |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 505 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 506 | memset(&fi, 0, sizeof(fi)); |
| 507 | fi.flags = arg->flags; |
| 508 | |
| 509 | if (req->f->op.open) |
| 510 | req->f->op.open(req, nodeid, &fi); |
| 511 | else |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 512 | fuse_reply_open(req, &fi); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static void do_read(fuse_req_t req, fuse_ino_t nodeid, |
| 516 | struct fuse_read_in *arg) |
| 517 | { |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 518 | if (req->f->op.read) { |
| 519 | struct fuse_file_info fi; |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 520 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 521 | memset(&fi, 0, sizeof(fi)); |
| 522 | fi.fh = arg->fh; |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 523 | req->f->op.read(req, nodeid, arg->size, arg->offset, &fi); |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 524 | } else |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 525 | fuse_reply_err(req, ENOSYS); |
| 526 | } |
| 527 | |
| 528 | static void do_write(fuse_req_t req, fuse_ino_t nodeid, |
| 529 | struct fuse_write_in *arg) |
| 530 | { |
| 531 | struct fuse_file_info fi; |
| 532 | |
| 533 | memset(&fi, 0, sizeof(fi)); |
| 534 | fi.fh = arg->fh; |
| 535 | fi.writepage = arg->write_flags & 1; |
| 536 | |
| 537 | if (req->f->op.write) |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 538 | req->f->op.write(req, nodeid, PARAM(arg), arg->size, |
| 539 | arg->offset, &fi); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 540 | else |
| 541 | fuse_reply_err(req, ENOSYS); |
| 542 | } |
| 543 | |
| 544 | static void do_flush(fuse_req_t req, fuse_ino_t nodeid, |
| 545 | struct fuse_flush_in *arg) |
| 546 | { |
| 547 | struct fuse_file_info fi; |
| 548 | |
| 549 | memset(&fi, 0, sizeof(fi)); |
| 550 | fi.fh = arg->fh; |
| 551 | |
| 552 | if (req->f->op.flush) |
| 553 | req->f->op.flush(req, nodeid, &fi); |
| 554 | else |
| 555 | fuse_reply_err(req, ENOSYS); |
| 556 | } |
| 557 | |
| 558 | static void do_release(fuse_req_t req, fuse_ino_t nodeid, |
| 559 | struct fuse_release_in *arg) |
| 560 | { |
| 561 | struct fuse_file_info fi; |
| 562 | |
| 563 | memset(&fi, 0, sizeof(fi)); |
| 564 | fi.flags = arg->flags; |
| 565 | fi.fh = arg->fh; |
| 566 | |
| 567 | if (req->f->op.release) |
| 568 | req->f->op.release(req, nodeid, &fi); |
| 569 | else |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 570 | fuse_reply_err(req, 0); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 574 | struct fuse_fsync_in *inarg) |
| 575 | { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 576 | struct fuse_file_info fi; |
| 577 | |
| 578 | memset(&fi, 0, sizeof(fi)); |
| 579 | fi.fh = inarg->fh; |
| 580 | |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 581 | if (req->f->op.fsync) |
| 582 | req->f->op.fsync(req, nodeid, inarg->fsync_flags & 1, &fi); |
| 583 | else |
| 584 | fuse_reply_err(req, ENOSYS); |
| 585 | } |
| 586 | |
| 587 | static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, |
| 588 | struct fuse_open_in *arg) |
| 589 | { |
| 590 | struct fuse_file_info fi; |
| 591 | |
| 592 | memset(&fi, 0, sizeof(fi)); |
| 593 | fi.flags = arg->flags; |
| 594 | |
| 595 | if (req->f->op.opendir) |
| 596 | req->f->op.opendir(req, nodeid, &fi); |
| 597 | else |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 598 | fuse_reply_open(req, &fi); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, |
| 602 | struct fuse_read_in *arg) |
| 603 | { |
| 604 | struct fuse_file_info fi; |
| 605 | |
| 606 | memset(&fi, 0, sizeof(fi)); |
| 607 | fi.fh = arg->fh; |
| 608 | |
| 609 | if (req->f->op.readdir) |
| 610 | req->f->op.readdir(req, nodeid, arg->size, arg->offset, &fi); |
| 611 | else |
| 612 | fuse_reply_err(req, ENOSYS); |
| 613 | } |
| 614 | |
| 615 | static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, |
| 616 | struct fuse_release_in *arg) |
| 617 | { |
| 618 | struct fuse_file_info fi; |
| 619 | |
| 620 | memset(&fi, 0, sizeof(fi)); |
| 621 | fi.flags = arg->flags; |
| 622 | fi.fh = arg->fh; |
| 623 | |
| 624 | if (req->f->op.releasedir) |
| 625 | req->f->op.releasedir(req, nodeid, &fi); |
| 626 | else |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 627 | fuse_reply_err(req, 0); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, |
| 631 | struct fuse_fsync_in *inarg) |
| 632 | { |
| 633 | struct fuse_file_info fi; |
| 634 | |
| 635 | memset(&fi, 0, sizeof(fi)); |
| 636 | fi.fh = inarg->fh; |
| 637 | |
| 638 | if (req->f->op.fsyncdir) |
| 639 | req->f->op.fsyncdir(req, nodeid, inarg->fsync_flags & 1, &fi); |
| 640 | else |
| 641 | fuse_reply_err(req, ENOSYS); |
| 642 | } |
| 643 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 644 | static void do_statfs(fuse_req_t req) |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 645 | { |
| 646 | if (req->f->op.statfs) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 647 | req->f->op.statfs(req); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 648 | else |
| 649 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 652 | static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 653 | struct fuse_setxattr_in *arg) |
| 654 | { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 655 | char *name = PARAM(arg); |
| 656 | unsigned char *value = name + strlen(name) + 1; |
| 657 | |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 658 | if (req->f->op.setxattr) |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 659 | req->f->op.setxattr(req, nodeid, name, value, arg->size, |
| 660 | arg->flags); |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 661 | else |
| 662 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 665 | static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 666 | struct fuse_getxattr_in *arg) |
| 667 | { |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 668 | if (req->f->op.getxattr) |
| 669 | req->f->op.getxattr(req, nodeid, PARAM(arg), arg->size); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 670 | else |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 671 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 674 | static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 675 | struct fuse_getxattr_in *arg) |
| 676 | { |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 677 | if (req->f->op.listxattr) |
| 678 | req->f->op.listxattr(req, nodeid, arg->size); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 679 | else |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 680 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 683 | static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, char *name) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 684 | { |
Miklos Szeredi | 4331a27 | 2005-07-12 14:51:04 +0000 | [diff] [blame] | 685 | if (req->f->op.removexattr) |
| 686 | req->f->op.removexattr(req, nodeid, name); |
| 687 | else |
| 688 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 691 | static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, |
| 692 | struct fuse_lk_in_out *arg) |
| 693 | { |
| 694 | if (req->f->op.getlk) { |
| 695 | struct fuse_lock_param lk; |
| 696 | |
| 697 | memset(&lk, 0, sizeof(lk)); |
| 698 | convert_file_lock(&arg->lk, &lk); |
| 699 | req->f->op.getlk(req, nodeid, &lk); |
| 700 | } else |
| 701 | fuse_reply_err(req, ENOSYS); |
| 702 | } |
| 703 | |
| 704 | static void do_setlk(fuse_req_t req, fuse_ino_t nodeid, int sleep, |
| 705 | struct fuse_lk_in_out *arg) |
| 706 | { |
| 707 | if (req->f->op.setlk) { |
| 708 | struct fuse_lock_param lk; |
| 709 | |
| 710 | memset(&lk, 0, sizeof(lk)); |
| 711 | convert_file_lock(&arg->lk, &lk); |
| 712 | req->f->op.setlk(req, nodeid, sleep, &lk); |
| 713 | } else |
| 714 | fuse_reply_err(req, ENOSYS); |
| 715 | } |
| 716 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 717 | static void do_init(struct fuse_ll *f, uint64_t unique, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 718 | struct fuse_init_in_out *arg) |
| 719 | { |
| 720 | struct fuse_init_in_out outarg; |
| 721 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 722 | if (f->debug) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 723 | printf("INIT: %u.%u\n", arg->major, arg->minor); |
| 724 | fflush(stdout); |
| 725 | } |
| 726 | f->got_init = 1; |
| 727 | if (f->op.init) |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 728 | f->userdata = f->op.init(f->userdata); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 729 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 730 | f->major = FUSE_KERNEL_VERSION; |
| 731 | f->minor = FUSE_KERNEL_MINOR_VERSION; |
| 732 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 733 | memset(&outarg, 0, sizeof(outarg)); |
| 734 | outarg.major = f->major; |
| 735 | outarg.minor = f->minor; |
| 736 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 737 | if (f->debug) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 738 | printf(" INIT: %u.%u\n", outarg.major, outarg.minor); |
| 739 | fflush(stdout); |
| 740 | } |
| 741 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 742 | send_reply(f, unique, 0, &outarg, sizeof(outarg)); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 745 | void *fuse_req_userdata(fuse_req_t req) |
| 746 | { |
| 747 | return req->f->userdata; |
| 748 | } |
| 749 | |
| 750 | const struct fuse_ctx *fuse_req_ctx(fuse_req_t req) |
| 751 | { |
| 752 | return &req->ctx; |
| 753 | } |
| 754 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 755 | static void free_cmd(struct fuse_cmd *cmd) |
| 756 | { |
| 757 | free(cmd->buf); |
| 758 | free(cmd); |
| 759 | } |
| 760 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 761 | void fuse_ll_process_cmd(struct fuse_ll *f, struct fuse_cmd *cmd) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 762 | { |
| 763 | struct fuse_in_header *in = (struct fuse_in_header *) cmd->buf; |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 764 | void *inarg = cmd->buf + sizeof(struct fuse_in_header); |
| 765 | struct fuse_req *req; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 766 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 767 | fuse_dec_avail(f); |
| 768 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 769 | if (f->debug) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 770 | printf("unique: %llu, opcode: %s (%i), nodeid: %lu, insize: %i\n", |
| 771 | in->unique, opname(in->opcode), in->opcode, |
| 772 | (unsigned long) in->nodeid, cmd->buflen); |
| 773 | fflush(stdout); |
| 774 | } |
| 775 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 776 | if (!f->got_init) { |
| 777 | if (in->opcode != FUSE_INIT) |
| 778 | send_reply(f, in->unique, -EPROTO, NULL, 0); |
| 779 | else |
| 780 | do_init(f, in->unique, (struct fuse_init_in_out *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 781 | goto out; |
| 782 | } |
| 783 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 784 | if (f->allow_root && in->uid != f->owner && in->uid != 0 && |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 785 | in->opcode != FUSE_INIT && in->opcode != FUSE_READ && |
| 786 | in->opcode != FUSE_WRITE && in->opcode != FUSE_FSYNC && |
| 787 | in->opcode != FUSE_RELEASE && in->opcode != FUSE_READDIR && |
| 788 | in->opcode != FUSE_FSYNCDIR && in->opcode != FUSE_RELEASEDIR) { |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 789 | send_reply(f, in->unique, -EACCES, NULL, 0); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 790 | goto out; |
| 791 | } |
| 792 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 793 | req = (struct fuse_req *) malloc(sizeof(struct fuse_req)); |
| 794 | if (req == NULL) { |
| 795 | fprintf(stderr, "fuse: failed to allocate request\n"); |
| 796 | goto out; |
| 797 | } |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 798 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 799 | req->f = f; |
| 800 | req->unique = in->unique; |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 801 | req->ctx.uid = in->uid; |
| 802 | req->ctx.gid = in->gid; |
| 803 | req->ctx.pid = in->pid; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 804 | |
| 805 | switch (in->opcode) { |
| 806 | case FUSE_LOOKUP: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 807 | do_lookup(req, in->nodeid, (char *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 808 | break; |
| 809 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 810 | case FUSE_FORGET: |
| 811 | do_forget(req, in->nodeid, (struct fuse_forget_in *) inarg); |
Miklos Szeredi | 2482fdb | 2005-07-12 13:23:53 +0000 | [diff] [blame] | 812 | break; |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 813 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 814 | case FUSE_GETATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 815 | do_getattr(req, in->nodeid); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 816 | break; |
| 817 | |
| 818 | case FUSE_SETATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 819 | do_setattr(req, in->nodeid, (struct fuse_setattr_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case FUSE_READLINK: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 823 | do_readlink(req, in->nodeid); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 824 | break; |
| 825 | |
| 826 | case FUSE_MKNOD: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 827 | do_mknod(req, in->nodeid, (struct fuse_mknod_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case FUSE_MKDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 831 | do_mkdir(req, in->nodeid, (struct fuse_mkdir_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | case FUSE_UNLINK: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 835 | do_unlink(req, in->nodeid, (char *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case FUSE_RMDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 839 | do_rmdir(req, in->nodeid, (char *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case FUSE_SYMLINK: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 843 | do_symlink(req, in->nodeid, (char *) inarg, |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 844 | ((char *) inarg) + strlen((char *) inarg) + 1); |
| 845 | break; |
| 846 | |
| 847 | case FUSE_RENAME: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 848 | do_rename(req, in->nodeid, (struct fuse_rename_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case FUSE_LINK: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 852 | do_link(req, in->nodeid, (struct fuse_link_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 853 | break; |
| 854 | |
| 855 | case FUSE_OPEN: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 856 | do_open(req, in->nodeid, (struct fuse_open_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | case FUSE_FLUSH: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 860 | do_flush(req, in->nodeid, (struct fuse_flush_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case FUSE_RELEASE: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 864 | do_release(req, in->nodeid, (struct fuse_release_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case FUSE_READ: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 868 | do_read(req, in->nodeid, (struct fuse_read_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case FUSE_WRITE: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 872 | do_write(req, in->nodeid, (struct fuse_write_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 873 | break; |
| 874 | |
| 875 | case FUSE_STATFS: |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 876 | do_statfs(req); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case FUSE_FSYNC: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 880 | do_fsync(req, in->nodeid, (struct fuse_fsync_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case FUSE_SETXATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 884 | do_setxattr(req, in->nodeid, (struct fuse_setxattr_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case FUSE_GETXATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 888 | do_getxattr(req, in->nodeid, (struct fuse_getxattr_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case FUSE_LISTXATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 892 | do_listxattr(req, in->nodeid, (struct fuse_getxattr_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 893 | break; |
| 894 | |
| 895 | case FUSE_REMOVEXATTR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 896 | do_removexattr(req, in->nodeid, (char *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case FUSE_OPENDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 900 | do_opendir(req, in->nodeid, (struct fuse_open_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case FUSE_READDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 904 | do_readdir(req, in->nodeid, (struct fuse_read_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 905 | break; |
| 906 | |
| 907 | case FUSE_RELEASEDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 908 | do_releasedir(req, in->nodeid, (struct fuse_release_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case FUSE_FSYNCDIR: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 912 | do_fsyncdir(req, in->nodeid, (struct fuse_fsync_in *) inarg); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame^] | 915 | case FUSE_GETLK: |
| 916 | do_getlk(req, in->nodeid, (struct fuse_lk_in_out *) inarg); |
| 917 | break; |
| 918 | |
| 919 | case FUSE_SETLK: |
| 920 | do_setlk(req, in->nodeid, 0, (struct fuse_lk_in_out *) inarg); |
| 921 | break; |
| 922 | |
| 923 | case FUSE_SETLKW: |
| 924 | do_setlk(req, in->nodeid, 1, (struct fuse_lk_in_out *) inarg); |
| 925 | break; |
| 926 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 927 | default: |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 928 | fuse_reply_err(req, ENOSYS); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | out: |
| 932 | free_cmd(cmd); |
| 933 | } |
| 934 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 935 | void fuse_ll_exit(struct fuse_ll *f) |
| 936 | { |
| 937 | f->exited = 1; |
| 938 | } |
| 939 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 940 | int fuse_ll_exited(struct fuse_ll* f) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 941 | { |
| 942 | return f->exited; |
| 943 | } |
| 944 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 945 | struct fuse_cmd *fuse_ll_read_cmd(struct fuse_ll *f) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 946 | { |
| 947 | ssize_t res; |
| 948 | struct fuse_cmd *cmd; |
| 949 | struct fuse_in_header *in; |
| 950 | void *inarg; |
| 951 | |
| 952 | cmd = (struct fuse_cmd *) malloc(sizeof(struct fuse_cmd)); |
| 953 | if (cmd == NULL) { |
| 954 | fprintf(stderr, "fuse: failed to allocate cmd in read\n"); |
| 955 | return NULL; |
| 956 | } |
| 957 | cmd->buf = (char *) malloc(FUSE_MAX_IN); |
| 958 | if (cmd->buf == NULL) { |
| 959 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 960 | free(cmd); |
| 961 | return NULL; |
| 962 | } |
| 963 | in = (struct fuse_in_header *) cmd->buf; |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 964 | inarg = cmd->buf + sizeof(struct fuse_in_header); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 965 | |
| 966 | res = read(f->fd, cmd->buf, FUSE_MAX_IN); |
| 967 | if (res == -1) { |
| 968 | free_cmd(cmd); |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 969 | if (fuse_ll_exited(f) || errno == EINTR || errno == ENOENT) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 970 | return NULL; |
| 971 | |
| 972 | /* ENODEV means we got unmounted, so we silenty return failure */ |
| 973 | if (errno != ENODEV) { |
| 974 | /* BAD... This will happen again */ |
| 975 | perror("fuse: reading device"); |
| 976 | } |
| 977 | |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 978 | fuse_ll_exit(f); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 979 | return NULL; |
| 980 | } |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 981 | if ((size_t) res < sizeof(struct fuse_in_header)) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 982 | free_cmd(cmd); |
| 983 | /* Cannot happen */ |
| 984 | fprintf(stderr, "short read on fuse device\n"); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 985 | fuse_ll_exit(f); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 986 | return NULL; |
| 987 | } |
| 988 | cmd->buflen = res; |
| 989 | |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 990 | |
| 991 | return cmd; |
| 992 | } |
| 993 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 994 | int fuse_ll_loop(struct fuse_ll *f) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 995 | { |
| 996 | if (f == NULL) |
| 997 | return -1; |
| 998 | |
| 999 | while (1) { |
| 1000 | struct fuse_cmd *cmd; |
| 1001 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1002 | if (fuse_ll_exited(f)) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1003 | break; |
| 1004 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1005 | cmd = fuse_ll_read_cmd(f); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1006 | if (cmd == NULL) |
| 1007 | continue; |
| 1008 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1009 | fuse_ll_process_cmd(f, cmd); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1010 | } |
| 1011 | f->exited = 0; |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1015 | int fuse_ll_is_lib_option(const char *opt) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1016 | { |
| 1017 | if (strcmp(opt, "debug") == 0 || |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1018 | strcmp(opt, "allow_root") == 0) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1019 | return 1; |
| 1020 | else |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1024 | static int parse_ll_opts(struct fuse_ll *f, const char *opts) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1025 | { |
| 1026 | if (opts) { |
| 1027 | char *xopts = strdup(opts); |
| 1028 | char *s = xopts; |
| 1029 | char *opt; |
| 1030 | |
| 1031 | if (xopts == NULL) { |
| 1032 | fprintf(stderr, "fuse: memory allocation failed\n"); |
| 1033 | return -1; |
| 1034 | } |
| 1035 | |
| 1036 | while((opt = strsep(&s, ","))) { |
| 1037 | if (strcmp(opt, "debug") == 0) |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1038 | f->debug = 1; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1039 | else if (strcmp(opt, "allow_root") == 0) |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1040 | f->allow_root = 1; |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1041 | else |
| 1042 | fprintf(stderr, "fuse: warning: unknown option `%s'\n", opt); |
| 1043 | } |
| 1044 | free(xopts); |
| 1045 | } |
| 1046 | return 0; |
| 1047 | } |
| 1048 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1049 | struct fuse_ll *fuse_ll_new(int fd, const char *opts, |
| 1050 | const struct fuse_ll_operations *op, |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1051 | size_t op_size, void *userdata) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1052 | { |
| 1053 | struct fuse_ll *f; |
| 1054 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1055 | if (sizeof(struct fuse_ll_operations) < op_size) { |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1056 | fprintf(stderr, "fuse: warning: library too old, some operations may not not work\n"); |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1057 | op_size = sizeof(struct fuse_ll_operations); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | f = (struct fuse_ll *) calloc(1, sizeof(struct fuse_ll)); |
| 1061 | if (f == NULL) { |
| 1062 | fprintf(stderr, "fuse: failed to allocate fuse object\n"); |
| 1063 | goto out; |
| 1064 | } |
| 1065 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1066 | if (parse_ll_opts(f, opts) == -1) |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1067 | goto out_free; |
| 1068 | |
| 1069 | f->fd = fd; |
| 1070 | memcpy(&f->op, op, op_size); |
| 1071 | f->exited = 0; |
| 1072 | f->owner = getuid(); |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1073 | f->userdata = userdata; |
| 1074 | mutex_init(&f->worker_lock); |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1075 | |
| 1076 | return f; |
| 1077 | |
| 1078 | out_free: |
| 1079 | free(f); |
| 1080 | out: |
| 1081 | return NULL; |
| 1082 | } |
| 1083 | |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1084 | void fuse_ll_destroy(struct fuse_ll *f) |
| 1085 | { |
Miklos Szeredi | bd10a7b | 2005-07-15 09:59:59 +0000 | [diff] [blame] | 1086 | if (f->op.destroy) |
| 1087 | f->op.destroy(f->userdata); |
| 1088 | |
| 1089 | pthread_mutex_destroy(&f->worker_lock); |
Miklos Szeredi | 76c1752 | 2005-07-13 14:08:19 +0000 | [diff] [blame] | 1090 | free(f); |
| 1091 | } |
Miklos Szeredi | 1274494 | 2005-07-11 12:32:31 +0000 | [diff] [blame] | 1092 | |