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