Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/file.h> |
| 13 | #include <linux/gfp.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/namei.h> |
| 16 | |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 17 | #if BITS_PER_LONG >= 64 |
| 18 | static inline void fuse_dentry_settime(struct dentry *entry, u64 time) |
| 19 | { |
| 20 | entry->d_time = time; |
| 21 | } |
| 22 | |
| 23 | static inline u64 fuse_dentry_time(struct dentry *entry) |
| 24 | { |
| 25 | return entry->d_time; |
| 26 | } |
| 27 | #else |
| 28 | /* |
| 29 | * On 32 bit archs store the high 32 bits of time in d_fsdata |
| 30 | */ |
| 31 | static void fuse_dentry_settime(struct dentry *entry, u64 time) |
| 32 | { |
| 33 | entry->d_time = time; |
| 34 | entry->d_fsdata = (void *) (unsigned long) (time >> 32); |
| 35 | } |
| 36 | |
| 37 | static u64 fuse_dentry_time(struct dentry *entry) |
| 38 | { |
| 39 | return (u64) entry->d_time + |
| 40 | ((u64) (unsigned long) entry->d_fsdata << 32); |
| 41 | } |
| 42 | #endif |
| 43 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 44 | /* |
| 45 | * FUSE caches dentries and attributes with separate timeout. The |
| 46 | * time in jiffies until the dentry/attributes are valid is stored in |
| 47 | * dentry->d_time and fuse_inode->i_time respectively. |
| 48 | */ |
| 49 | |
| 50 | /* |
| 51 | * Calculate the time in jiffies until a dentry/attributes are valid |
| 52 | */ |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 53 | static u64 time_to_jiffies(unsigned long sec, unsigned long nsec) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 54 | { |
Miklos Szeredi | 685d16d | 2006-07-30 03:04:08 -0700 | [diff] [blame] | 55 | if (sec || nsec) { |
| 56 | struct timespec ts = {sec, nsec}; |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 57 | return get_jiffies_64() + timespec_to_jiffies(&ts); |
Miklos Szeredi | 685d16d | 2006-07-30 03:04:08 -0700 | [diff] [blame] | 58 | } else |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 59 | return 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 62 | /* |
| 63 | * Set dentry and possibly attribute timeouts from the lookup/mk* |
| 64 | * replies |
| 65 | */ |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 66 | static void fuse_change_entry_timeout(struct dentry *entry, |
| 67 | struct fuse_entry_out *o) |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 68 | { |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 69 | fuse_dentry_settime(entry, |
| 70 | time_to_jiffies(o->entry_valid, o->entry_valid_nsec)); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static u64 attr_timeout(struct fuse_attr_out *o) |
| 74 | { |
| 75 | return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); |
| 76 | } |
| 77 | |
| 78 | static u64 entry_attr_timeout(struct fuse_entry_out *o) |
| 79 | { |
| 80 | return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 83 | /* |
| 84 | * Mark the attributes as stale, so that at the next call to |
| 85 | * ->getattr() they will be fetched from userspace |
| 86 | */ |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 87 | void fuse_invalidate_attr(struct inode *inode) |
| 88 | { |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 89 | get_fuse_inode(inode)->i_time = 0; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 92 | /* |
| 93 | * Just mark the entry as stale, so that a next attempt to look it up |
| 94 | * will result in a new lookup call to userspace |
| 95 | * |
| 96 | * This is called when a dentry is about to become negative and the |
| 97 | * timeout is unknown (unlink, rmdir, rename and in some cases |
| 98 | * lookup) |
| 99 | */ |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 100 | static void fuse_invalidate_entry_cache(struct dentry *entry) |
| 101 | { |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 102 | fuse_dentry_settime(entry, 0); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 105 | /* |
| 106 | * Same as fuse_invalidate_entry_cache(), but also try to remove the |
| 107 | * dentry from the hash |
| 108 | */ |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 109 | static void fuse_invalidate_entry(struct dentry *entry) |
| 110 | { |
| 111 | d_invalidate(entry); |
| 112 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 115 | static void fuse_lookup_init(struct fuse_req *req, struct inode *dir, |
| 116 | struct dentry *entry, |
| 117 | struct fuse_entry_out *outarg) |
| 118 | { |
| 119 | req->in.h.opcode = FUSE_LOOKUP; |
| 120 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 121 | req->in.numargs = 1; |
| 122 | req->in.args[0].size = entry->d_name.len + 1; |
| 123 | req->in.args[0].value = entry->d_name.name; |
| 124 | req->out.numargs = 1; |
| 125 | req->out.args[0].size = sizeof(struct fuse_entry_out); |
| 126 | req->out.args[0].value = outarg; |
| 127 | } |
| 128 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 129 | /* |
| 130 | * Check whether the dentry is still valid |
| 131 | * |
| 132 | * If the entry validity timeout has expired and the dentry is |
| 133 | * positive, try to redo the lookup. If the lookup results in a |
| 134 | * different inode, then let the VFS invalidate the dentry and redo |
| 135 | * the lookup once more. If the lookup results in the same inode, |
| 136 | * then refresh the attributes, timeouts and mark the dentry valid. |
| 137 | */ |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 138 | static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) |
| 139 | { |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 140 | struct inode *inode = entry->d_inode; |
| 141 | |
| 142 | if (inode && is_bad_inode(inode)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 143 | return 0; |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 144 | else if (fuse_dentry_time(entry) < get_jiffies_64()) { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 145 | int err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 146 | struct fuse_entry_out outarg; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 147 | struct fuse_conn *fc; |
| 148 | struct fuse_req *req; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 149 | struct fuse_req *forget_req; |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 150 | struct dentry *parent; |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 151 | u64 attr_version; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 152 | |
Miklos Szeredi | 50322fe | 2006-02-28 16:59:03 -0800 | [diff] [blame] | 153 | /* For negative dentries, always do a fresh lookup */ |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 154 | if (!inode) |
| 155 | return 0; |
| 156 | |
| 157 | fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 158 | req = fuse_get_req(fc); |
| 159 | if (IS_ERR(req)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 160 | return 0; |
| 161 | |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 162 | forget_req = fuse_get_req(fc); |
| 163 | if (IS_ERR(forget_req)) { |
| 164 | fuse_put_request(fc, req); |
| 165 | return 0; |
| 166 | } |
| 167 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 168 | spin_lock(&fc->lock); |
| 169 | attr_version = fc->attr_version; |
| 170 | spin_unlock(&fc->lock); |
| 171 | |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 172 | parent = dget_parent(entry); |
| 173 | fuse_lookup_init(req, parent->d_inode, entry, &outarg); |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 174 | request_send(fc, req); |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 175 | dput(parent); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 176 | err = req->out.h.error; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 177 | fuse_put_request(fc, req); |
Miklos Szeredi | 50322fe | 2006-02-28 16:59:03 -0800 | [diff] [blame] | 178 | /* Zero nodeid is same as -ENOENT */ |
| 179 | if (!err && !outarg.nodeid) |
| 180 | err = -ENOENT; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 181 | if (!err) { |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 182 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 183 | if (outarg.nodeid != get_node_id(inode)) { |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 184 | fuse_send_forget(fc, forget_req, |
| 185 | outarg.nodeid, 1); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 186 | return 0; |
| 187 | } |
Miklos Szeredi | 8da5ff2 | 2006-10-17 00:10:08 -0700 | [diff] [blame] | 188 | spin_lock(&fc->lock); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 189 | fi->nlookup ++; |
Miklos Szeredi | 8da5ff2 | 2006-10-17 00:10:08 -0700 | [diff] [blame] | 190 | spin_unlock(&fc->lock); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 191 | } |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 192 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 193 | if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 194 | return 0; |
| 195 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 196 | fuse_change_attributes(inode, &outarg.attr, |
| 197 | entry_attr_timeout(&outarg), |
| 198 | attr_version); |
| 199 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 200 | } |
| 201 | return 1; |
| 202 | } |
| 203 | |
Miklos Szeredi | 8bfc016 | 2006-01-16 22:14:28 -0800 | [diff] [blame] | 204 | static int invalid_nodeid(u64 nodeid) |
Miklos Szeredi | 2827d0b2 | 2005-11-28 13:44:16 -0800 | [diff] [blame] | 205 | { |
| 206 | return !nodeid || nodeid == FUSE_ROOT_ID; |
| 207 | } |
| 208 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 209 | static struct dentry_operations fuse_dentry_operations = { |
| 210 | .d_revalidate = fuse_dentry_revalidate, |
| 211 | }; |
| 212 | |
Timo Savola | a5bfffac | 2007-04-08 16:04:00 -0700 | [diff] [blame] | 213 | int fuse_valid_type(int m) |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 214 | { |
| 215 | return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) || |
| 216 | S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); |
| 217 | } |
| 218 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 219 | /* |
| 220 | * Add a directory inode to a dentry, ensuring that no other dentry |
| 221 | * refers to this inode. Called with fc->inst_mutex. |
| 222 | */ |
| 223 | static int fuse_d_add_directory(struct dentry *entry, struct inode *inode) |
| 224 | { |
| 225 | struct dentry *alias = d_find_alias(inode); |
| 226 | if (alias) { |
| 227 | /* This tries to shrink the subtree below alias */ |
| 228 | fuse_invalidate_entry(alias); |
| 229 | dput(alias); |
| 230 | if (!list_empty(&inode->i_dentry)) |
| 231 | return -EBUSY; |
| 232 | } |
| 233 | d_add(entry, inode); |
| 234 | return 0; |
| 235 | } |
| 236 | |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 237 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
| 238 | struct nameidata *nd) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 239 | { |
| 240 | int err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 241 | struct fuse_entry_out outarg; |
| 242 | struct inode *inode = NULL; |
| 243 | struct fuse_conn *fc = get_fuse_conn(dir); |
| 244 | struct fuse_req *req; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 245 | struct fuse_req *forget_req; |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 246 | u64 attr_version; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 247 | |
| 248 | if (entry->d_name.len > FUSE_NAME_MAX) |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 249 | return ERR_PTR(-ENAMETOOLONG); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 250 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 251 | req = fuse_get_req(fc); |
| 252 | if (IS_ERR(req)) |
| 253 | return ERR_PTR(PTR_ERR(req)); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 254 | |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 255 | forget_req = fuse_get_req(fc); |
| 256 | if (IS_ERR(forget_req)) { |
| 257 | fuse_put_request(fc, req); |
| 258 | return ERR_PTR(PTR_ERR(forget_req)); |
| 259 | } |
| 260 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 261 | spin_lock(&fc->lock); |
| 262 | attr_version = fc->attr_version; |
| 263 | spin_unlock(&fc->lock); |
| 264 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 265 | fuse_lookup_init(req, dir, entry, &outarg); |
| 266 | request_send(fc, req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 267 | err = req->out.h.error; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 268 | fuse_put_request(fc, req); |
Miklos Szeredi | 50322fe | 2006-02-28 16:59:03 -0800 | [diff] [blame] | 269 | /* Zero nodeid is same as -ENOENT, but with valid timeout */ |
| 270 | if (!err && outarg.nodeid && |
Timo Savola | a5bfffac | 2007-04-08 16:04:00 -0700 | [diff] [blame] | 271 | (invalid_nodeid(outarg.nodeid) || |
| 272 | !fuse_valid_type(outarg.attr.mode))) |
Miklos Szeredi | ee4e527 | 2005-09-27 21:45:21 -0700 | [diff] [blame] | 273 | err = -EIO; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 274 | if (!err && outarg.nodeid) { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 275 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 276 | &outarg.attr, entry_attr_timeout(&outarg), |
| 277 | attr_version); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 278 | if (!inode) { |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 279 | fuse_send_forget(fc, forget_req, outarg.nodeid, 1); |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 280 | return ERR_PTR(-ENOMEM); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 283 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 284 | if (err && err != -ENOENT) |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 285 | return ERR_PTR(err); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 286 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 287 | if (inode && S_ISDIR(inode->i_mode)) { |
| 288 | mutex_lock(&fc->inst_mutex); |
| 289 | err = fuse_d_add_directory(entry, inode); |
| 290 | mutex_unlock(&fc->inst_mutex); |
| 291 | if (err) { |
| 292 | iput(inode); |
| 293 | return ERR_PTR(err); |
| 294 | } |
| 295 | } else |
| 296 | d_add(entry, inode); |
| 297 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 298 | entry->d_op = &fuse_dentry_operations; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 299 | if (!err) |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 300 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 301 | else |
| 302 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 303 | return NULL; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 306 | /* |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 307 | * Synchronous release for the case when something goes wrong in CREATE_OPEN |
| 308 | */ |
| 309 | static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff, |
| 310 | u64 nodeid, int flags) |
| 311 | { |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 312 | fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE); |
| 313 | ff->reserved_req->force = 1; |
| 314 | request_send(fc, ff->reserved_req); |
| 315 | fuse_put_request(fc, ff->reserved_req); |
| 316 | kfree(ff); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /* |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 320 | * Atomic create+open operation |
| 321 | * |
| 322 | * If the filesystem doesn't support this, then fall back to separate |
| 323 | * 'mknod' + 'open' requests. |
| 324 | */ |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 325 | static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, |
| 326 | struct nameidata *nd) |
| 327 | { |
| 328 | int err; |
| 329 | struct inode *inode; |
| 330 | struct fuse_conn *fc = get_fuse_conn(dir); |
| 331 | struct fuse_req *req; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 332 | struct fuse_req *forget_req; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 333 | struct fuse_open_in inarg; |
| 334 | struct fuse_open_out outopen; |
| 335 | struct fuse_entry_out outentry; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 336 | struct fuse_file *ff; |
| 337 | struct file *file; |
| 338 | int flags = nd->intent.open.flags - 1; |
| 339 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 340 | if (fc->no_create) |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 341 | return -ENOSYS; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 342 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 343 | forget_req = fuse_get_req(fc); |
| 344 | if (IS_ERR(forget_req)) |
| 345 | return PTR_ERR(forget_req); |
| 346 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 347 | req = fuse_get_req(fc); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 348 | err = PTR_ERR(req); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 349 | if (IS_ERR(req)) |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 350 | goto out_put_forget_req; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 351 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 352 | err = -ENOMEM; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 353 | ff = fuse_file_alloc(); |
| 354 | if (!ff) |
| 355 | goto out_put_request; |
| 356 | |
| 357 | flags &= ~O_NOCTTY; |
| 358 | memset(&inarg, 0, sizeof(inarg)); |
| 359 | inarg.flags = flags; |
| 360 | inarg.mode = mode; |
| 361 | req->in.h.opcode = FUSE_CREATE; |
| 362 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 363 | req->in.numargs = 2; |
| 364 | req->in.args[0].size = sizeof(inarg); |
| 365 | req->in.args[0].value = &inarg; |
| 366 | req->in.args[1].size = entry->d_name.len + 1; |
| 367 | req->in.args[1].value = entry->d_name.name; |
| 368 | req->out.numargs = 2; |
| 369 | req->out.args[0].size = sizeof(outentry); |
| 370 | req->out.args[0].value = &outentry; |
| 371 | req->out.args[1].size = sizeof(outopen); |
| 372 | req->out.args[1].value = &outopen; |
| 373 | request_send(fc, req); |
| 374 | err = req->out.h.error; |
| 375 | if (err) { |
| 376 | if (err == -ENOSYS) |
| 377 | fc->no_create = 1; |
| 378 | goto out_free_ff; |
| 379 | } |
| 380 | |
| 381 | err = -EIO; |
Miklos Szeredi | 2827d0b2 | 2005-11-28 13:44:16 -0800 | [diff] [blame] | 382 | if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid)) |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 383 | goto out_free_ff; |
| 384 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 385 | fuse_put_request(fc, req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 386 | inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 387 | &outentry.attr, entry_attr_timeout(&outentry), 0); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 388 | if (!inode) { |
| 389 | flags &= ~(O_CREAT | O_EXCL | O_TRUNC); |
| 390 | ff->fh = outopen.fh; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 391 | fuse_sync_release(fc, ff, outentry.nodeid, flags); |
| 392 | fuse_send_forget(fc, forget_req, outentry.nodeid, 1); |
| 393 | return -ENOMEM; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 394 | } |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 395 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 396 | d_instantiate(entry, inode); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 397 | fuse_change_entry_timeout(entry, &outentry); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 398 | file = lookup_instantiate_filp(nd, entry, generic_file_open); |
| 399 | if (IS_ERR(file)) { |
| 400 | ff->fh = outopen.fh; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 401 | fuse_sync_release(fc, ff, outentry.nodeid, flags); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 402 | return PTR_ERR(file); |
| 403 | } |
| 404 | fuse_finish_open(inode, file, ff, &outopen); |
| 405 | return 0; |
| 406 | |
| 407 | out_free_ff: |
| 408 | fuse_file_free(ff); |
| 409 | out_put_request: |
| 410 | fuse_put_request(fc, req); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 411 | out_put_forget_req: |
| 412 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 413 | return err; |
| 414 | } |
| 415 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 416 | /* |
| 417 | * Code shared between mknod, mkdir, symlink and link |
| 418 | */ |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 419 | static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, |
| 420 | struct inode *dir, struct dentry *entry, |
| 421 | int mode) |
| 422 | { |
| 423 | struct fuse_entry_out outarg; |
| 424 | struct inode *inode; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 425 | int err; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 426 | struct fuse_req *forget_req; |
| 427 | |
| 428 | forget_req = fuse_get_req(fc); |
| 429 | if (IS_ERR(forget_req)) { |
| 430 | fuse_put_request(fc, req); |
| 431 | return PTR_ERR(forget_req); |
| 432 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 433 | |
| 434 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 435 | req->out.numargs = 1; |
| 436 | req->out.args[0].size = sizeof(outarg); |
| 437 | req->out.args[0].value = &outarg; |
| 438 | request_send(fc, req); |
| 439 | err = req->out.h.error; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 440 | fuse_put_request(fc, req); |
| 441 | if (err) |
| 442 | goto out_put_forget_req; |
| 443 | |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 444 | err = -EIO; |
| 445 | if (invalid_nodeid(outarg.nodeid)) |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 446 | goto out_put_forget_req; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 447 | |
| 448 | if ((outarg.attr.mode ^ mode) & S_IFMT) |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 449 | goto out_put_forget_req; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 450 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 451 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 452 | &outarg.attr, entry_attr_timeout(&outarg), 0); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 453 | if (!inode) { |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 454 | fuse_send_forget(fc, forget_req, outarg.nodeid, 1); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 455 | return -ENOMEM; |
| 456 | } |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 457 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 458 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 459 | if (S_ISDIR(inode->i_mode)) { |
| 460 | struct dentry *alias; |
| 461 | mutex_lock(&fc->inst_mutex); |
| 462 | alias = d_find_alias(inode); |
| 463 | if (alias) { |
| 464 | /* New directory must have moved since mkdir */ |
| 465 | mutex_unlock(&fc->inst_mutex); |
| 466 | dput(alias); |
| 467 | iput(inode); |
| 468 | return -EBUSY; |
| 469 | } |
| 470 | d_instantiate(entry, inode); |
| 471 | mutex_unlock(&fc->inst_mutex); |
| 472 | } else |
| 473 | d_instantiate(entry, inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 474 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 475 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 476 | fuse_invalidate_attr(dir); |
| 477 | return 0; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 478 | |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 479 | out_put_forget_req: |
| 480 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 481 | return err; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
| 485 | dev_t rdev) |
| 486 | { |
| 487 | struct fuse_mknod_in inarg; |
| 488 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 489 | struct fuse_req *req = fuse_get_req(fc); |
| 490 | if (IS_ERR(req)) |
| 491 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 492 | |
| 493 | memset(&inarg, 0, sizeof(inarg)); |
| 494 | inarg.mode = mode; |
| 495 | inarg.rdev = new_encode_dev(rdev); |
| 496 | req->in.h.opcode = FUSE_MKNOD; |
| 497 | req->in.numargs = 2; |
| 498 | req->in.args[0].size = sizeof(inarg); |
| 499 | req->in.args[0].value = &inarg; |
| 500 | req->in.args[1].size = entry->d_name.len + 1; |
| 501 | req->in.args[1].value = entry->d_name.name; |
| 502 | return create_new_entry(fc, req, dir, entry, mode); |
| 503 | } |
| 504 | |
| 505 | static int fuse_create(struct inode *dir, struct dentry *entry, int mode, |
| 506 | struct nameidata *nd) |
| 507 | { |
Miklos Szeredi | b9ba347 | 2007-05-23 13:57:32 -0700 | [diff] [blame] | 508 | if (nd && (nd->flags & LOOKUP_OPEN)) { |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 509 | int err = fuse_create_open(dir, entry, mode, nd); |
| 510 | if (err != -ENOSYS) |
| 511 | return err; |
| 512 | /* Fall back on mknod */ |
| 513 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 514 | return fuse_mknod(dir, entry, mode, 0); |
| 515 | } |
| 516 | |
| 517 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) |
| 518 | { |
| 519 | struct fuse_mkdir_in inarg; |
| 520 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 521 | struct fuse_req *req = fuse_get_req(fc); |
| 522 | if (IS_ERR(req)) |
| 523 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 524 | |
| 525 | memset(&inarg, 0, sizeof(inarg)); |
| 526 | inarg.mode = mode; |
| 527 | req->in.h.opcode = FUSE_MKDIR; |
| 528 | req->in.numargs = 2; |
| 529 | req->in.args[0].size = sizeof(inarg); |
| 530 | req->in.args[0].value = &inarg; |
| 531 | req->in.args[1].size = entry->d_name.len + 1; |
| 532 | req->in.args[1].value = entry->d_name.name; |
| 533 | return create_new_entry(fc, req, dir, entry, S_IFDIR); |
| 534 | } |
| 535 | |
| 536 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
| 537 | const char *link) |
| 538 | { |
| 539 | struct fuse_conn *fc = get_fuse_conn(dir); |
| 540 | unsigned len = strlen(link) + 1; |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 541 | struct fuse_req *req = fuse_get_req(fc); |
| 542 | if (IS_ERR(req)) |
| 543 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 544 | |
| 545 | req->in.h.opcode = FUSE_SYMLINK; |
| 546 | req->in.numargs = 2; |
| 547 | req->in.args[0].size = entry->d_name.len + 1; |
| 548 | req->in.args[0].value = entry->d_name.name; |
| 549 | req->in.args[1].size = len; |
| 550 | req->in.args[1].value = link; |
| 551 | return create_new_entry(fc, req, dir, entry, S_IFLNK); |
| 552 | } |
| 553 | |
| 554 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
| 555 | { |
| 556 | int err; |
| 557 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 558 | struct fuse_req *req = fuse_get_req(fc); |
| 559 | if (IS_ERR(req)) |
| 560 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 561 | |
| 562 | req->in.h.opcode = FUSE_UNLINK; |
| 563 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 564 | req->in.numargs = 1; |
| 565 | req->in.args[0].size = entry->d_name.len + 1; |
| 566 | req->in.args[0].value = entry->d_name.name; |
| 567 | request_send(fc, req); |
| 568 | err = req->out.h.error; |
| 569 | fuse_put_request(fc, req); |
| 570 | if (!err) { |
| 571 | struct inode *inode = entry->d_inode; |
| 572 | |
| 573 | /* Set nlink to zero so the inode can be cleared, if |
| 574 | the inode does have more links this will be |
| 575 | discovered at the next lookup/getattr */ |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 576 | clear_nlink(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 577 | fuse_invalidate_attr(inode); |
| 578 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 579 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 580 | } else if (err == -EINTR) |
| 581 | fuse_invalidate_entry(entry); |
| 582 | return err; |
| 583 | } |
| 584 | |
| 585 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
| 586 | { |
| 587 | int err; |
| 588 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 589 | struct fuse_req *req = fuse_get_req(fc); |
| 590 | if (IS_ERR(req)) |
| 591 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 592 | |
| 593 | req->in.h.opcode = FUSE_RMDIR; |
| 594 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 595 | req->in.numargs = 1; |
| 596 | req->in.args[0].size = entry->d_name.len + 1; |
| 597 | req->in.args[0].value = entry->d_name.name; |
| 598 | request_send(fc, req); |
| 599 | err = req->out.h.error; |
| 600 | fuse_put_request(fc, req); |
| 601 | if (!err) { |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 602 | clear_nlink(entry->d_inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 603 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 604 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 605 | } else if (err == -EINTR) |
| 606 | fuse_invalidate_entry(entry); |
| 607 | return err; |
| 608 | } |
| 609 | |
| 610 | static int fuse_rename(struct inode *olddir, struct dentry *oldent, |
| 611 | struct inode *newdir, struct dentry *newent) |
| 612 | { |
| 613 | int err; |
| 614 | struct fuse_rename_in inarg; |
| 615 | struct fuse_conn *fc = get_fuse_conn(olddir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 616 | struct fuse_req *req = fuse_get_req(fc); |
| 617 | if (IS_ERR(req)) |
| 618 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 619 | |
| 620 | memset(&inarg, 0, sizeof(inarg)); |
| 621 | inarg.newdir = get_node_id(newdir); |
| 622 | req->in.h.opcode = FUSE_RENAME; |
| 623 | req->in.h.nodeid = get_node_id(olddir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 624 | req->in.numargs = 3; |
| 625 | req->in.args[0].size = sizeof(inarg); |
| 626 | req->in.args[0].value = &inarg; |
| 627 | req->in.args[1].size = oldent->d_name.len + 1; |
| 628 | req->in.args[1].value = oldent->d_name.name; |
| 629 | req->in.args[2].size = newent->d_name.len + 1; |
| 630 | req->in.args[2].value = newent->d_name.name; |
| 631 | request_send(fc, req); |
| 632 | err = req->out.h.error; |
| 633 | fuse_put_request(fc, req); |
| 634 | if (!err) { |
| 635 | fuse_invalidate_attr(olddir); |
| 636 | if (olddir != newdir) |
| 637 | fuse_invalidate_attr(newdir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 638 | |
| 639 | /* newent will end up negative */ |
| 640 | if (newent->d_inode) |
| 641 | fuse_invalidate_entry_cache(newent); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 642 | } else if (err == -EINTR) { |
| 643 | /* If request was interrupted, DEITY only knows if the |
| 644 | rename actually took place. If the invalidation |
| 645 | fails (e.g. some process has CWD under the renamed |
| 646 | directory), then there can be inconsistency between |
| 647 | the dcache and the real filesystem. Tough luck. */ |
| 648 | fuse_invalidate_entry(oldent); |
| 649 | if (newent->d_inode) |
| 650 | fuse_invalidate_entry(newent); |
| 651 | } |
| 652 | |
| 653 | return err; |
| 654 | } |
| 655 | |
| 656 | static int fuse_link(struct dentry *entry, struct inode *newdir, |
| 657 | struct dentry *newent) |
| 658 | { |
| 659 | int err; |
| 660 | struct fuse_link_in inarg; |
| 661 | struct inode *inode = entry->d_inode; |
| 662 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 663 | struct fuse_req *req = fuse_get_req(fc); |
| 664 | if (IS_ERR(req)) |
| 665 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 666 | |
| 667 | memset(&inarg, 0, sizeof(inarg)); |
| 668 | inarg.oldnodeid = get_node_id(inode); |
| 669 | req->in.h.opcode = FUSE_LINK; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 670 | req->in.numargs = 2; |
| 671 | req->in.args[0].size = sizeof(inarg); |
| 672 | req->in.args[0].value = &inarg; |
| 673 | req->in.args[1].size = newent->d_name.len + 1; |
| 674 | req->in.args[1].value = newent->d_name.name; |
| 675 | err = create_new_entry(fc, req, newdir, newent, inode->i_mode); |
| 676 | /* Contrary to "normal" filesystems it can happen that link |
| 677 | makes two "logical" inodes point to the same "physical" |
| 678 | inode. We invalidate the attributes of the old one, so it |
| 679 | will reflect changes in the backing inode (link count, |
| 680 | etc.) |
| 681 | */ |
| 682 | if (!err || err == -EINTR) |
| 683 | fuse_invalidate_attr(inode); |
| 684 | return err; |
| 685 | } |
| 686 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 687 | static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr, |
| 688 | struct kstat *stat) |
| 689 | { |
| 690 | stat->dev = inode->i_sb->s_dev; |
| 691 | stat->ino = attr->ino; |
| 692 | stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777); |
| 693 | stat->nlink = attr->nlink; |
| 694 | stat->uid = attr->uid; |
| 695 | stat->gid = attr->gid; |
| 696 | stat->rdev = inode->i_rdev; |
| 697 | stat->atime.tv_sec = attr->atime; |
| 698 | stat->atime.tv_nsec = attr->atimensec; |
| 699 | stat->mtime.tv_sec = attr->mtime; |
| 700 | stat->mtime.tv_nsec = attr->mtimensec; |
| 701 | stat->ctime.tv_sec = attr->ctime; |
| 702 | stat->ctime.tv_nsec = attr->ctimensec; |
| 703 | stat->size = attr->size; |
| 704 | stat->blocks = attr->blocks; |
| 705 | stat->blksize = (1 << inode->i_blkbits); |
| 706 | } |
| 707 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 708 | static int fuse_do_getattr(struct inode *inode, struct kstat *stat, |
| 709 | struct file *file) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 710 | { |
| 711 | int err; |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 712 | struct fuse_getattr_in inarg; |
| 713 | struct fuse_attr_out outarg; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 714 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 715 | struct fuse_req *req; |
| 716 | u64 attr_version; |
| 717 | |
| 718 | req = fuse_get_req(fc); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 719 | if (IS_ERR(req)) |
| 720 | return PTR_ERR(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 721 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 722 | spin_lock(&fc->lock); |
| 723 | attr_version = fc->attr_version; |
| 724 | spin_unlock(&fc->lock); |
| 725 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 726 | memset(&inarg, 0, sizeof(inarg)); |
| 727 | /* Directories have separate file-handle space */ |
| 728 | if (file && S_ISREG(inode->i_mode)) { |
| 729 | struct fuse_file *ff = file->private_data; |
| 730 | |
| 731 | inarg.getattr_flags |= FUSE_GETATTR_FH; |
| 732 | inarg.fh = ff->fh; |
| 733 | } |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 734 | req->in.h.opcode = FUSE_GETATTR; |
| 735 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 736 | req->in.numargs = 1; |
| 737 | req->in.args[0].size = sizeof(inarg); |
| 738 | req->in.args[0].value = &inarg; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 739 | req->out.numargs = 1; |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 740 | req->out.args[0].size = sizeof(outarg); |
| 741 | req->out.args[0].value = &outarg; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 742 | request_send(fc, req); |
| 743 | err = req->out.h.error; |
| 744 | fuse_put_request(fc, req); |
| 745 | if (!err) { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 746 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 747 | make_bad_inode(inode); |
| 748 | err = -EIO; |
| 749 | } else { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 750 | fuse_change_attributes(inode, &outarg.attr, |
| 751 | attr_timeout(&outarg), |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 752 | attr_version); |
| 753 | if (stat) |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 754 | fuse_fillattr(inode, &outarg.attr, stat); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | return err; |
| 758 | } |
| 759 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 760 | /* |
| 761 | * Calling into a user-controlled filesystem gives the filesystem |
| 762 | * daemon ptrace-like capabilities over the requester process. This |
| 763 | * means, that the filesystem daemon is able to record the exact |
| 764 | * filesystem operations performed, and can also control the behavior |
| 765 | * of the requester process in otherwise impossible ways. For example |
| 766 | * it can delay the operation for arbitrary length of time allowing |
| 767 | * DoS against the requester. |
| 768 | * |
| 769 | * For this reason only those processes can call into the filesystem, |
| 770 | * for which the owner of the mount has ptrace privilege. This |
| 771 | * excludes processes started by other users, suid or sgid processes. |
| 772 | */ |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 773 | int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task) |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 774 | { |
| 775 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 776 | return 1; |
| 777 | |
| 778 | if (task->euid == fc->user_id && |
| 779 | task->suid == fc->user_id && |
| 780 | task->uid == fc->user_id && |
| 781 | task->egid == fc->group_id && |
| 782 | task->sgid == fc->group_id && |
| 783 | task->gid == fc->group_id) |
| 784 | return 1; |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 789 | static int fuse_access(struct inode *inode, int mask) |
| 790 | { |
| 791 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 792 | struct fuse_req *req; |
| 793 | struct fuse_access_in inarg; |
| 794 | int err; |
| 795 | |
| 796 | if (fc->no_access) |
| 797 | return 0; |
| 798 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 799 | req = fuse_get_req(fc); |
| 800 | if (IS_ERR(req)) |
| 801 | return PTR_ERR(req); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 802 | |
| 803 | memset(&inarg, 0, sizeof(inarg)); |
| 804 | inarg.mask = mask; |
| 805 | req->in.h.opcode = FUSE_ACCESS; |
| 806 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 807 | req->in.numargs = 1; |
| 808 | req->in.args[0].size = sizeof(inarg); |
| 809 | req->in.args[0].value = &inarg; |
| 810 | request_send(fc, req); |
| 811 | err = req->out.h.error; |
| 812 | fuse_put_request(fc, req); |
| 813 | if (err == -ENOSYS) { |
| 814 | fc->no_access = 1; |
| 815 | err = 0; |
| 816 | } |
| 817 | return err; |
| 818 | } |
| 819 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 820 | /* |
| 821 | * Check permission. The two basic access models of FUSE are: |
| 822 | * |
| 823 | * 1) Local access checking ('default_permissions' mount option) based |
| 824 | * on file mode. This is the plain old disk filesystem permission |
| 825 | * modell. |
| 826 | * |
| 827 | * 2) "Remote" access checking, where server is responsible for |
| 828 | * checking permission in each inode operation. An exception to this |
| 829 | * is if ->permission() was invoked from sys_access() in which case an |
| 830 | * access request is sent. Execute permission is still checked |
| 831 | * locally based on file mode. |
| 832 | */ |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 833 | static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) |
| 834 | { |
| 835 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 836 | bool refreshed = false; |
| 837 | int err = 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 838 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 839 | if (!fuse_allow_task(fc, current)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 840 | return -EACCES; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 841 | |
| 842 | /* |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 843 | * If attributes are needed, refresh them before proceeding |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 844 | */ |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 845 | if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) || |
| 846 | ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) { |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 847 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 848 | if (fi->i_time < get_jiffies_64()) { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 849 | err = fuse_do_getattr(inode, NULL, NULL); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 850 | if (err) |
| 851 | return err; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 852 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 853 | refreshed = true; |
| 854 | } |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 858 | int err = generic_permission(inode, mask, NULL); |
| 859 | |
| 860 | /* If permission is denied, try to refresh file |
| 861 | attributes. This is also needed, because the root |
| 862 | node will at first have no permissions */ |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 863 | if (err == -EACCES && !refreshed) { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 864 | err = fuse_do_getattr(inode, NULL, NULL); |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 865 | if (!err) |
| 866 | err = generic_permission(inode, mask, NULL); |
| 867 | } |
| 868 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 869 | /* Note: the opposite of the above test does not |
| 870 | exist. So if permissions are revoked this won't be |
| 871 | noticed immediately, only after the attribute |
| 872 | timeout has expired */ |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 873 | } else if (nd && (nd->flags & (LOOKUP_ACCESS | LOOKUP_CHDIR))) { |
| 874 | err = fuse_access(inode, mask); |
| 875 | } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) { |
| 876 | if (!(inode->i_mode & S_IXUGO)) { |
| 877 | if (refreshed) |
| 878 | return -EACCES; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 879 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 880 | err = fuse_do_getattr(inode, NULL, NULL); |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 881 | if (!err && !(inode->i_mode & S_IXUGO)) |
| 882 | return -EACCES; |
| 883 | } |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 884 | } |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 885 | return err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 889 | void *dstbuf, filldir_t filldir) |
| 890 | { |
| 891 | while (nbytes >= FUSE_NAME_OFFSET) { |
| 892 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
| 893 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 894 | int over; |
| 895 | if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX) |
| 896 | return -EIO; |
| 897 | if (reclen > nbytes) |
| 898 | break; |
| 899 | |
| 900 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
| 901 | file->f_pos, dirent->ino, dirent->type); |
| 902 | if (over) |
| 903 | break; |
| 904 | |
| 905 | buf += reclen; |
| 906 | nbytes -= reclen; |
| 907 | file->f_pos = dirent->off; |
| 908 | } |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 913 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 914 | { |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 915 | int err; |
| 916 | size_t nbytes; |
| 917 | struct page *page; |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 918 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 919 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 920 | struct fuse_file *ff = file->private_data; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 921 | struct fuse_req *req; |
| 922 | |
| 923 | if (is_bad_inode(inode)) |
| 924 | return -EIO; |
| 925 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 926 | req = fuse_get_req(fc); |
| 927 | if (IS_ERR(req)) |
| 928 | return PTR_ERR(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 929 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 930 | page = alloc_page(GFP_KERNEL); |
| 931 | if (!page) { |
| 932 | fuse_put_request(fc, req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 933 | return -ENOMEM; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 934 | } |
| 935 | req->num_pages = 1; |
| 936 | req->pages[0] = page; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 937 | fuse_read_fill(req, ff, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR); |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 938 | request_send(fc, req); |
| 939 | nbytes = req->out.args[0].size; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 940 | err = req->out.h.error; |
| 941 | fuse_put_request(fc, req); |
| 942 | if (!err) |
| 943 | err = parse_dirfile(page_address(page), nbytes, file, dstbuf, |
| 944 | filldir); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 945 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 946 | __free_page(page); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 947 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 948 | return err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static char *read_link(struct dentry *dentry) |
| 952 | { |
| 953 | struct inode *inode = dentry->d_inode; |
| 954 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 955 | struct fuse_req *req = fuse_get_req(fc); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 956 | char *link; |
| 957 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 958 | if (IS_ERR(req)) |
| 959 | return ERR_PTR(PTR_ERR(req)); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 960 | |
| 961 | link = (char *) __get_free_page(GFP_KERNEL); |
| 962 | if (!link) { |
| 963 | link = ERR_PTR(-ENOMEM); |
| 964 | goto out; |
| 965 | } |
| 966 | req->in.h.opcode = FUSE_READLINK; |
| 967 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 968 | req->out.argvar = 1; |
| 969 | req->out.numargs = 1; |
| 970 | req->out.args[0].size = PAGE_SIZE - 1; |
| 971 | req->out.args[0].value = link; |
| 972 | request_send(fc, req); |
| 973 | if (req->out.h.error) { |
| 974 | free_page((unsigned long) link); |
| 975 | link = ERR_PTR(req->out.h.error); |
| 976 | } else |
| 977 | link[req->out.args[0].size] = '\0'; |
| 978 | out: |
| 979 | fuse_put_request(fc, req); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 980 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 981 | return link; |
| 982 | } |
| 983 | |
| 984 | static void free_link(char *link) |
| 985 | { |
| 986 | if (!IS_ERR(link)) |
| 987 | free_page((unsigned long) link); |
| 988 | } |
| 989 | |
| 990 | static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 991 | { |
| 992 | nd_set_link(nd, read_link(dentry)); |
| 993 | return NULL; |
| 994 | } |
| 995 | |
| 996 | static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c) |
| 997 | { |
| 998 | free_link(nd_get_link(nd)); |
| 999 | } |
| 1000 | |
| 1001 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 1002 | { |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1003 | return fuse_open_common(inode, file, 1); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 1007 | { |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1008 | return fuse_release_common(inode, file, 1); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1011 | static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync) |
| 1012 | { |
| 1013 | /* nfsd can call this with no file */ |
| 1014 | return file ? fuse_fsync_common(file, de, datasync, 1) : 0; |
| 1015 | } |
| 1016 | |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1017 | static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg) |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1018 | { |
| 1019 | unsigned ivalid = iattr->ia_valid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1020 | |
| 1021 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1022 | arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1023 | if (ivalid & ATTR_UID) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1024 | arg->valid |= FATTR_UID, arg->uid = iattr->ia_uid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1025 | if (ivalid & ATTR_GID) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1026 | arg->valid |= FATTR_GID, arg->gid = iattr->ia_gid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1027 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1028 | arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1029 | /* You can only _set_ these together (they may change by themselves) */ |
| 1030 | if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1031 | arg->valid |= FATTR_ATIME | FATTR_MTIME; |
| 1032 | arg->atime = iattr->ia_atime.tv_sec; |
| 1033 | arg->mtime = iattr->ia_mtime.tv_sec; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1034 | } |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1035 | if (ivalid & ATTR_FILE) { |
| 1036 | struct fuse_file *ff = iattr->ia_file->private_data; |
| 1037 | arg->valid |= FATTR_FH; |
| 1038 | arg->fh = ff->fh; |
| 1039 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1042 | /* |
| 1043 | * Set attributes, and at the same time refresh them. |
| 1044 | * |
| 1045 | * Truncation is slightly complicated, because the 'truncate' request |
| 1046 | * may fail, in which case we don't want to touch the mapping. |
Miklos Szeredi | 9ffbb91 | 2006-10-17 00:10:06 -0700 | [diff] [blame] | 1047 | * vmtruncate() doesn't allow for this case, so do the rlimit checking |
| 1048 | * and the actual truncation by hand. |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1049 | */ |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1050 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 1051 | { |
| 1052 | struct inode *inode = entry->d_inode; |
| 1053 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1054 | struct fuse_req *req; |
| 1055 | struct fuse_setattr_in inarg; |
| 1056 | struct fuse_attr_out outarg; |
| 1057 | int err; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1058 | |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1059 | if (!fuse_allow_task(fc, current)) |
| 1060 | return -EACCES; |
| 1061 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1062 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
| 1063 | err = inode_change_ok(inode, attr); |
| 1064 | if (err) |
| 1065 | return err; |
| 1066 | } |
| 1067 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1068 | if (attr->ia_valid & ATTR_SIZE) { |
| 1069 | unsigned long limit; |
Miklos Szeredi | b2d2272 | 2006-12-06 20:35:51 -0800 | [diff] [blame] | 1070 | if (IS_SWAPFILE(inode)) |
| 1071 | return -ETXTBSY; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1072 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; |
| 1073 | if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) { |
| 1074 | send_sig(SIGXFSZ, current, 0); |
| 1075 | return -EFBIG; |
| 1076 | } |
| 1077 | } |
| 1078 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1079 | req = fuse_get_req(fc); |
| 1080 | if (IS_ERR(req)) |
| 1081 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1082 | |
| 1083 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1084 | iattr_to_fattr(attr, &inarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1085 | req->in.h.opcode = FUSE_SETATTR; |
| 1086 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1087 | req->in.numargs = 1; |
| 1088 | req->in.args[0].size = sizeof(inarg); |
| 1089 | req->in.args[0].value = &inarg; |
| 1090 | req->out.numargs = 1; |
| 1091 | req->out.args[0].size = sizeof(outarg); |
| 1092 | req->out.args[0].value = &outarg; |
| 1093 | request_send(fc, req); |
| 1094 | err = req->out.h.error; |
| 1095 | fuse_put_request(fc, req); |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1096 | if (err) { |
| 1097 | if (err == -EINTR) |
| 1098 | fuse_invalidate_attr(inode); |
| 1099 | return err; |
| 1100 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1101 | |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1102 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
| 1103 | make_bad_inode(inode); |
| 1104 | return -EIO; |
| 1105 | } |
| 1106 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1107 | fuse_change_attributes(inode, &outarg.attr, attr_timeout(&outarg), 0); |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1108 | return 0; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1111 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 1112 | struct kstat *stat) |
| 1113 | { |
| 1114 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1115 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 1116 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 1117 | int err; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1118 | |
| 1119 | if (!fuse_allow_task(fc, current)) |
| 1120 | return -EACCES; |
| 1121 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1122 | if (fi->i_time < get_jiffies_64()) |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame^] | 1123 | err = fuse_do_getattr(inode, stat, NULL); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1124 | else { |
| 1125 | err = 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1126 | generic_fillattr(inode, stat); |
Miklos Szeredi | ebc14c4 | 2007-10-16 23:31:03 -0700 | [diff] [blame] | 1127 | stat->mode = fi->orig_i_mode; |
| 1128 | } |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1129 | |
| 1130 | return err; |
| 1131 | } |
| 1132 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1133 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 1134 | const void *value, size_t size, int flags) |
| 1135 | { |
| 1136 | struct inode *inode = entry->d_inode; |
| 1137 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1138 | struct fuse_req *req; |
| 1139 | struct fuse_setxattr_in inarg; |
| 1140 | int err; |
| 1141 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1142 | if (fc->no_setxattr) |
| 1143 | return -EOPNOTSUPP; |
| 1144 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1145 | req = fuse_get_req(fc); |
| 1146 | if (IS_ERR(req)) |
| 1147 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1148 | |
| 1149 | memset(&inarg, 0, sizeof(inarg)); |
| 1150 | inarg.size = size; |
| 1151 | inarg.flags = flags; |
| 1152 | req->in.h.opcode = FUSE_SETXATTR; |
| 1153 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1154 | req->in.numargs = 3; |
| 1155 | req->in.args[0].size = sizeof(inarg); |
| 1156 | req->in.args[0].value = &inarg; |
| 1157 | req->in.args[1].size = strlen(name) + 1; |
| 1158 | req->in.args[1].value = name; |
| 1159 | req->in.args[2].size = size; |
| 1160 | req->in.args[2].value = value; |
| 1161 | request_send(fc, req); |
| 1162 | err = req->out.h.error; |
| 1163 | fuse_put_request(fc, req); |
| 1164 | if (err == -ENOSYS) { |
| 1165 | fc->no_setxattr = 1; |
| 1166 | err = -EOPNOTSUPP; |
| 1167 | } |
| 1168 | return err; |
| 1169 | } |
| 1170 | |
| 1171 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 1172 | void *value, size_t size) |
| 1173 | { |
| 1174 | struct inode *inode = entry->d_inode; |
| 1175 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1176 | struct fuse_req *req; |
| 1177 | struct fuse_getxattr_in inarg; |
| 1178 | struct fuse_getxattr_out outarg; |
| 1179 | ssize_t ret; |
| 1180 | |
| 1181 | if (fc->no_getxattr) |
| 1182 | return -EOPNOTSUPP; |
| 1183 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1184 | req = fuse_get_req(fc); |
| 1185 | if (IS_ERR(req)) |
| 1186 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1187 | |
| 1188 | memset(&inarg, 0, sizeof(inarg)); |
| 1189 | inarg.size = size; |
| 1190 | req->in.h.opcode = FUSE_GETXATTR; |
| 1191 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1192 | req->in.numargs = 2; |
| 1193 | req->in.args[0].size = sizeof(inarg); |
| 1194 | req->in.args[0].value = &inarg; |
| 1195 | req->in.args[1].size = strlen(name) + 1; |
| 1196 | req->in.args[1].value = name; |
| 1197 | /* This is really two different operations rolled into one */ |
| 1198 | req->out.numargs = 1; |
| 1199 | if (size) { |
| 1200 | req->out.argvar = 1; |
| 1201 | req->out.args[0].size = size; |
| 1202 | req->out.args[0].value = value; |
| 1203 | } else { |
| 1204 | req->out.args[0].size = sizeof(outarg); |
| 1205 | req->out.args[0].value = &outarg; |
| 1206 | } |
| 1207 | request_send(fc, req); |
| 1208 | ret = req->out.h.error; |
| 1209 | if (!ret) |
| 1210 | ret = size ? req->out.args[0].size : outarg.size; |
| 1211 | else { |
| 1212 | if (ret == -ENOSYS) { |
| 1213 | fc->no_getxattr = 1; |
| 1214 | ret = -EOPNOTSUPP; |
| 1215 | } |
| 1216 | } |
| 1217 | fuse_put_request(fc, req); |
| 1218 | return ret; |
| 1219 | } |
| 1220 | |
| 1221 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 1222 | { |
| 1223 | struct inode *inode = entry->d_inode; |
| 1224 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1225 | struct fuse_req *req; |
| 1226 | struct fuse_getxattr_in inarg; |
| 1227 | struct fuse_getxattr_out outarg; |
| 1228 | ssize_t ret; |
| 1229 | |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1230 | if (!fuse_allow_task(fc, current)) |
| 1231 | return -EACCES; |
| 1232 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1233 | if (fc->no_listxattr) |
| 1234 | return -EOPNOTSUPP; |
| 1235 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1236 | req = fuse_get_req(fc); |
| 1237 | if (IS_ERR(req)) |
| 1238 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1239 | |
| 1240 | memset(&inarg, 0, sizeof(inarg)); |
| 1241 | inarg.size = size; |
| 1242 | req->in.h.opcode = FUSE_LISTXATTR; |
| 1243 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1244 | req->in.numargs = 1; |
| 1245 | req->in.args[0].size = sizeof(inarg); |
| 1246 | req->in.args[0].value = &inarg; |
| 1247 | /* This is really two different operations rolled into one */ |
| 1248 | req->out.numargs = 1; |
| 1249 | if (size) { |
| 1250 | req->out.argvar = 1; |
| 1251 | req->out.args[0].size = size; |
| 1252 | req->out.args[0].value = list; |
| 1253 | } else { |
| 1254 | req->out.args[0].size = sizeof(outarg); |
| 1255 | req->out.args[0].value = &outarg; |
| 1256 | } |
| 1257 | request_send(fc, req); |
| 1258 | ret = req->out.h.error; |
| 1259 | if (!ret) |
| 1260 | ret = size ? req->out.args[0].size : outarg.size; |
| 1261 | else { |
| 1262 | if (ret == -ENOSYS) { |
| 1263 | fc->no_listxattr = 1; |
| 1264 | ret = -EOPNOTSUPP; |
| 1265 | } |
| 1266 | } |
| 1267 | fuse_put_request(fc, req); |
| 1268 | return ret; |
| 1269 | } |
| 1270 | |
| 1271 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 1272 | { |
| 1273 | struct inode *inode = entry->d_inode; |
| 1274 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1275 | struct fuse_req *req; |
| 1276 | int err; |
| 1277 | |
| 1278 | if (fc->no_removexattr) |
| 1279 | return -EOPNOTSUPP; |
| 1280 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1281 | req = fuse_get_req(fc); |
| 1282 | if (IS_ERR(req)) |
| 1283 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1284 | |
| 1285 | req->in.h.opcode = FUSE_REMOVEXATTR; |
| 1286 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1287 | req->in.numargs = 1; |
| 1288 | req->in.args[0].size = strlen(name) + 1; |
| 1289 | req->in.args[0].value = name; |
| 1290 | request_send(fc, req); |
| 1291 | err = req->out.h.error; |
| 1292 | fuse_put_request(fc, req); |
| 1293 | if (err == -ENOSYS) { |
| 1294 | fc->no_removexattr = 1; |
| 1295 | err = -EOPNOTSUPP; |
| 1296 | } |
| 1297 | return err; |
| 1298 | } |
| 1299 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1300 | static const struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1301 | .lookup = fuse_lookup, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1302 | .mkdir = fuse_mkdir, |
| 1303 | .symlink = fuse_symlink, |
| 1304 | .unlink = fuse_unlink, |
| 1305 | .rmdir = fuse_rmdir, |
| 1306 | .rename = fuse_rename, |
| 1307 | .link = fuse_link, |
| 1308 | .setattr = fuse_setattr, |
| 1309 | .create = fuse_create, |
| 1310 | .mknod = fuse_mknod, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1311 | .permission = fuse_permission, |
| 1312 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1313 | .setxattr = fuse_setxattr, |
| 1314 | .getxattr = fuse_getxattr, |
| 1315 | .listxattr = fuse_listxattr, |
| 1316 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1317 | }; |
| 1318 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 1319 | static const struct file_operations fuse_dir_operations = { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 1320 | .llseek = generic_file_llseek, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1321 | .read = generic_read_dir, |
| 1322 | .readdir = fuse_readdir, |
| 1323 | .open = fuse_dir_open, |
| 1324 | .release = fuse_dir_release, |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1325 | .fsync = fuse_dir_fsync, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1326 | }; |
| 1327 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1328 | static const struct inode_operations fuse_common_inode_operations = { |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1329 | .setattr = fuse_setattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1330 | .permission = fuse_permission, |
| 1331 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1332 | .setxattr = fuse_setxattr, |
| 1333 | .getxattr = fuse_getxattr, |
| 1334 | .listxattr = fuse_listxattr, |
| 1335 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1336 | }; |
| 1337 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1338 | static const struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1339 | .setattr = fuse_setattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1340 | .follow_link = fuse_follow_link, |
| 1341 | .put_link = fuse_put_link, |
| 1342 | .readlink = generic_readlink, |
| 1343 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1344 | .setxattr = fuse_setxattr, |
| 1345 | .getxattr = fuse_getxattr, |
| 1346 | .listxattr = fuse_listxattr, |
| 1347 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1348 | }; |
| 1349 | |
| 1350 | void fuse_init_common(struct inode *inode) |
| 1351 | { |
| 1352 | inode->i_op = &fuse_common_inode_operations; |
| 1353 | } |
| 1354 | |
| 1355 | void fuse_init_dir(struct inode *inode) |
| 1356 | { |
| 1357 | inode->i_op = &fuse_dir_inode_operations; |
| 1358 | inode->i_fop = &fuse_dir_operations; |
| 1359 | } |
| 1360 | |
| 1361 | void fuse_init_symlink(struct inode *inode) |
| 1362 | { |
| 1363 | inode->i_op = &fuse_symlink_inode_operations; |
| 1364 | } |