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