Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 3 | Copyright (C) 2001-2008 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 | dbd561d | 2008-07-25 01:49:00 -0700 | [diff] [blame] | 100 | void fuse_invalidate_entry_cache(struct dentry *entry) |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 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 | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 115 | static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_req *req, |
| 116 | u64 nodeid, struct qstr *name, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 117 | struct fuse_entry_out *outarg) |
| 118 | { |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 119 | memset(outarg, 0, sizeof(struct fuse_entry_out)); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 120 | req->in.h.opcode = FUSE_LOOKUP; |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 121 | req->in.h.nodeid = nodeid; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 122 | req->in.numargs = 1; |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 123 | req->in.args[0].size = name->len + 1; |
| 124 | req->in.args[0].value = name->name; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 125 | req->out.numargs = 1; |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 126 | if (fc->minor < 9) |
| 127 | req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE; |
| 128 | else |
| 129 | req->out.args[0].size = sizeof(struct fuse_entry_out); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 130 | req->out.args[0].value = outarg; |
| 131 | } |
| 132 | |
Miklos Szeredi | 5c5c5e5 | 2008-04-30 00:54:43 -0700 | [diff] [blame] | 133 | u64 fuse_get_attr_version(struct fuse_conn *fc) |
Miklos Szeredi | 7dca9fd | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 134 | { |
| 135 | u64 curr_version; |
| 136 | |
| 137 | /* |
| 138 | * The spin lock isn't actually needed on 64bit archs, but we |
| 139 | * don't yet care too much about such optimizations. |
| 140 | */ |
| 141 | spin_lock(&fc->lock); |
| 142 | curr_version = fc->attr_version; |
| 143 | spin_unlock(&fc->lock); |
| 144 | |
| 145 | return curr_version; |
| 146 | } |
| 147 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 148 | /* |
| 149 | * Check whether the dentry is still valid |
| 150 | * |
| 151 | * If the entry validity timeout has expired and the dentry is |
| 152 | * positive, try to redo the lookup. If the lookup results in a |
| 153 | * different inode, then let the VFS invalidate the dentry and redo |
| 154 | * the lookup once more. If the lookup results in the same inode, |
| 155 | * then refresh the attributes, timeouts and mark the dentry valid. |
| 156 | */ |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 157 | static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) |
| 158 | { |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 159 | struct inode *inode = entry->d_inode; |
| 160 | |
| 161 | if (inode && is_bad_inode(inode)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 162 | return 0; |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 163 | else if (fuse_dentry_time(entry) < get_jiffies_64()) { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 164 | int err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 165 | struct fuse_entry_out outarg; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 166 | struct fuse_conn *fc; |
| 167 | struct fuse_req *req; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 168 | struct fuse_req *forget_req; |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 169 | struct dentry *parent; |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 170 | u64 attr_version; |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 171 | |
Miklos Szeredi | 50322fe | 2006-02-28 16:59:03 -0800 | [diff] [blame] | 172 | /* For negative dentries, always do a fresh lookup */ |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 173 | if (!inode) |
| 174 | return 0; |
| 175 | |
| 176 | fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 177 | req = fuse_get_req(fc); |
| 178 | if (IS_ERR(req)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 179 | return 0; |
| 180 | |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 181 | forget_req = fuse_get_req(fc); |
| 182 | if (IS_ERR(forget_req)) { |
| 183 | fuse_put_request(fc, req); |
| 184 | return 0; |
| 185 | } |
| 186 | |
Miklos Szeredi | 7dca9fd | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 187 | attr_version = fuse_get_attr_version(fc); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 188 | |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 189 | parent = dget_parent(entry); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 190 | fuse_lookup_init(fc, req, get_node_id(parent->d_inode), |
| 191 | &entry->d_name, &outarg); |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 192 | fuse_request_send(fc, req); |
Miklos Szeredi | e956edd | 2006-10-17 00:10:12 -0700 | [diff] [blame] | 193 | dput(parent); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 194 | err = req->out.h.error; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 195 | fuse_put_request(fc, req); |
Miklos Szeredi | 50322fe | 2006-02-28 16:59:03 -0800 | [diff] [blame] | 196 | /* Zero nodeid is same as -ENOENT */ |
| 197 | if (!err && !outarg.nodeid) |
| 198 | err = -ENOENT; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 199 | if (!err) { |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 200 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 201 | if (outarg.nodeid != get_node_id(inode)) { |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 202 | fuse_send_forget(fc, forget_req, |
| 203 | outarg.nodeid, 1); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 204 | return 0; |
| 205 | } |
Miklos Szeredi | 8da5ff2 | 2006-10-17 00:10:08 -0700 | [diff] [blame] | 206 | spin_lock(&fc->lock); |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 207 | fi->nlookup++; |
Miklos Szeredi | 8da5ff2 | 2006-10-17 00:10:08 -0700 | [diff] [blame] | 208 | spin_unlock(&fc->lock); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 209 | } |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 210 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 211 | if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 214 | fuse_change_attributes(inode, &outarg.attr, |
| 215 | entry_attr_timeout(&outarg), |
| 216 | attr_version); |
| 217 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 218 | } |
| 219 | return 1; |
| 220 | } |
| 221 | |
Miklos Szeredi | 8bfc016 | 2006-01-16 22:14:28 -0800 | [diff] [blame] | 222 | static int invalid_nodeid(u64 nodeid) |
Miklos Szeredi | 2827d0b2 | 2005-11-28 13:44:16 -0800 | [diff] [blame] | 223 | { |
| 224 | return !nodeid || nodeid == FUSE_ROOT_ID; |
| 225 | } |
| 226 | |
Al Viro | 4269590 | 2009-02-20 05:59:13 +0000 | [diff] [blame] | 227 | const struct dentry_operations fuse_dentry_operations = { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 228 | .d_revalidate = fuse_dentry_revalidate, |
| 229 | }; |
| 230 | |
Timo Savola | a5bfffac | 2007-04-08 16:04:00 -0700 | [diff] [blame] | 231 | int fuse_valid_type(int m) |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 232 | { |
| 233 | return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) || |
| 234 | S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); |
| 235 | } |
| 236 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 237 | /* |
| 238 | * Add a directory inode to a dentry, ensuring that no other dentry |
| 239 | * refers to this inode. Called with fc->inst_mutex. |
| 240 | */ |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 241 | static struct dentry *fuse_d_add_directory(struct dentry *entry, |
| 242 | struct inode *inode) |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 243 | { |
| 244 | struct dentry *alias = d_find_alias(inode); |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 245 | if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) { |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 246 | /* This tries to shrink the subtree below alias */ |
| 247 | fuse_invalidate_entry(alias); |
| 248 | dput(alias); |
| 249 | if (!list_empty(&inode->i_dentry)) |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 250 | return ERR_PTR(-EBUSY); |
| 251 | } else { |
| 252 | dput(alias); |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 253 | } |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 254 | return d_splice_alias(inode, entry); |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 257 | int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name, |
| 258 | struct fuse_entry_out *outarg, struct inode **inode) |
| 259 | { |
| 260 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 261 | struct fuse_req *req; |
| 262 | struct fuse_req *forget_req; |
| 263 | u64 attr_version; |
| 264 | int err; |
| 265 | |
| 266 | *inode = NULL; |
| 267 | err = -ENAMETOOLONG; |
| 268 | if (name->len > FUSE_NAME_MAX) |
| 269 | goto out; |
| 270 | |
| 271 | req = fuse_get_req(fc); |
| 272 | err = PTR_ERR(req); |
| 273 | if (IS_ERR(req)) |
| 274 | goto out; |
| 275 | |
| 276 | forget_req = fuse_get_req(fc); |
| 277 | err = PTR_ERR(forget_req); |
| 278 | if (IS_ERR(forget_req)) { |
| 279 | fuse_put_request(fc, req); |
| 280 | goto out; |
| 281 | } |
| 282 | |
| 283 | attr_version = fuse_get_attr_version(fc); |
| 284 | |
| 285 | fuse_lookup_init(fc, req, nodeid, name, outarg); |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 286 | fuse_request_send(fc, req); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 287 | err = req->out.h.error; |
| 288 | fuse_put_request(fc, req); |
| 289 | /* Zero nodeid is same as -ENOENT, but with valid timeout */ |
| 290 | if (err || !outarg->nodeid) |
| 291 | goto out_put_forget; |
| 292 | |
| 293 | err = -EIO; |
| 294 | if (!outarg->nodeid) |
| 295 | goto out_put_forget; |
| 296 | if (!fuse_valid_type(outarg->attr.mode)) |
| 297 | goto out_put_forget; |
| 298 | |
| 299 | *inode = fuse_iget(sb, outarg->nodeid, outarg->generation, |
| 300 | &outarg->attr, entry_attr_timeout(outarg), |
| 301 | attr_version); |
| 302 | err = -ENOMEM; |
| 303 | if (!*inode) { |
| 304 | fuse_send_forget(fc, forget_req, outarg->nodeid, 1); |
| 305 | goto out; |
| 306 | } |
| 307 | err = 0; |
| 308 | |
| 309 | out_put_forget: |
| 310 | fuse_put_request(fc, forget_req); |
| 311 | out: |
| 312 | return err; |
| 313 | } |
| 314 | |
Miklos Szeredi | 0aa7c69 | 2006-01-06 00:19:34 -0800 | [diff] [blame] | 315 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
| 316 | struct nameidata *nd) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 317 | { |
| 318 | int err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 319 | struct fuse_entry_out outarg; |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 320 | struct inode *inode; |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 321 | struct dentry *newent; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 322 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 323 | bool outarg_valid = true; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 324 | |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 325 | err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name, |
| 326 | &outarg, &inode); |
| 327 | if (err == -ENOENT) { |
| 328 | outarg_valid = false; |
| 329 | err = 0; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 330 | } |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 331 | if (err) |
| 332 | goto out_err; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 333 | |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 334 | err = -EIO; |
| 335 | if (inode && get_node_id(inode) == FUSE_ROOT_ID) |
| 336 | goto out_iput; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 337 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 338 | if (inode && S_ISDIR(inode->i_mode)) { |
| 339 | mutex_lock(&fc->inst_mutex); |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 340 | newent = fuse_d_add_directory(entry, inode); |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 341 | mutex_unlock(&fc->inst_mutex); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 342 | err = PTR_ERR(newent); |
| 343 | if (IS_ERR(newent)) |
| 344 | goto out_iput; |
| 345 | } else { |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 346 | newent = d_splice_alias(inode, entry); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 347 | } |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 348 | |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 349 | entry = newent ? newent : entry; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 350 | entry->d_op = &fuse_dentry_operations; |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 351 | if (outarg_valid) |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 352 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 353 | else |
| 354 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 355 | |
Miklos Szeredi | 0de6256 | 2008-07-25 01:48:59 -0700 | [diff] [blame] | 356 | return newent; |
Miklos Szeredi | c180eeb | 2008-07-25 01:49:01 -0700 | [diff] [blame] | 357 | |
| 358 | out_iput: |
| 359 | iput(inode); |
| 360 | out_err: |
| 361 | return ERR_PTR(err); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 364 | /* |
| 365 | * Atomic create+open operation |
| 366 | * |
| 367 | * If the filesystem doesn't support this, then fall back to separate |
| 368 | * 'mknod' + 'open' requests. |
| 369 | */ |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 370 | static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, |
| 371 | struct nameidata *nd) |
| 372 | { |
| 373 | int err; |
| 374 | struct inode *inode; |
| 375 | struct fuse_conn *fc = get_fuse_conn(dir); |
| 376 | struct fuse_req *req; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 377 | struct fuse_req *forget_req; |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 378 | struct fuse_create_in inarg; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 379 | struct fuse_open_out outopen; |
| 380 | struct fuse_entry_out outentry; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 381 | struct fuse_file *ff; |
| 382 | struct file *file; |
| 383 | int flags = nd->intent.open.flags - 1; |
| 384 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 385 | if (fc->no_create) |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 386 | return -ENOSYS; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 387 | |
Csaba Henk | 1b73239 | 2009-11-27 19:30:14 +0530 | [diff] [blame] | 388 | if (flags & O_DIRECT) |
| 389 | return -EINVAL; |
| 390 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 391 | forget_req = fuse_get_req(fc); |
| 392 | if (IS_ERR(forget_req)) |
| 393 | return PTR_ERR(forget_req); |
| 394 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 395 | req = fuse_get_req(fc); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 396 | err = PTR_ERR(req); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 397 | if (IS_ERR(req)) |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 398 | goto out_put_forget_req; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 399 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 400 | err = -ENOMEM; |
Tejun Heo | acf9943 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 401 | ff = fuse_file_alloc(fc); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 402 | if (!ff) |
| 403 | goto out_put_request; |
| 404 | |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 405 | if (!fc->dont_mask) |
| 406 | mode &= ~current_umask(); |
| 407 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 408 | flags &= ~O_NOCTTY; |
| 409 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 410 | memset(&outentry, 0, sizeof(outentry)); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 411 | inarg.flags = flags; |
| 412 | inarg.mode = mode; |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 413 | inarg.umask = current_umask(); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 414 | req->in.h.opcode = FUSE_CREATE; |
| 415 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 416 | req->in.numargs = 2; |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 417 | req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) : |
| 418 | sizeof(inarg); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 419 | req->in.args[0].value = &inarg; |
| 420 | req->in.args[1].size = entry->d_name.len + 1; |
| 421 | req->in.args[1].value = entry->d_name.name; |
| 422 | req->out.numargs = 2; |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 423 | if (fc->minor < 9) |
| 424 | req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE; |
| 425 | else |
| 426 | req->out.args[0].size = sizeof(outentry); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 427 | req->out.args[0].value = &outentry; |
| 428 | req->out.args[1].size = sizeof(outopen); |
| 429 | req->out.args[1].value = &outopen; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 430 | fuse_request_send(fc, req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 431 | err = req->out.h.error; |
| 432 | if (err) { |
| 433 | if (err == -ENOSYS) |
| 434 | fc->no_create = 1; |
| 435 | goto out_free_ff; |
| 436 | } |
| 437 | |
| 438 | err = -EIO; |
Miklos Szeredi | 2827d0b2 | 2005-11-28 13:44:16 -0800 | [diff] [blame] | 439 | if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid)) |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 440 | goto out_free_ff; |
| 441 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 442 | fuse_put_request(fc, req); |
Miklos Szeredi | c7b7143 | 2009-04-28 16:56:37 +0200 | [diff] [blame] | 443 | ff->fh = outopen.fh; |
| 444 | ff->nodeid = outentry.nodeid; |
| 445 | ff->open_flags = outopen.open_flags; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 446 | inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 447 | &outentry.attr, entry_attr_timeout(&outentry), 0); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 448 | if (!inode) { |
| 449 | flags &= ~(O_CREAT | O_EXCL | O_TRUNC); |
Miklos Szeredi | 8b0797a | 2009-04-28 16:56:39 +0200 | [diff] [blame] | 450 | fuse_sync_release(ff, flags); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 451 | fuse_send_forget(fc, forget_req, outentry.nodeid, 1); |
| 452 | return -ENOMEM; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 453 | } |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 454 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 455 | d_instantiate(entry, inode); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 456 | fuse_change_entry_timeout(entry, &outentry); |
Miklos Szeredi | 0952b2a | 2008-02-06 01:38:38 -0800 | [diff] [blame] | 457 | fuse_invalidate_attr(dir); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 458 | file = lookup_instantiate_filp(nd, entry, generic_file_open); |
| 459 | if (IS_ERR(file)) { |
Miklos Szeredi | 8b0797a | 2009-04-28 16:56:39 +0200 | [diff] [blame] | 460 | fuse_sync_release(ff, flags); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 461 | return PTR_ERR(file); |
| 462 | } |
Miklos Szeredi | c7b7143 | 2009-04-28 16:56:37 +0200 | [diff] [blame] | 463 | file->private_data = fuse_file_get(ff); |
| 464 | fuse_finish_open(inode, file); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 465 | return 0; |
| 466 | |
| 467 | out_free_ff: |
| 468 | fuse_file_free(ff); |
| 469 | out_put_request: |
| 470 | fuse_put_request(fc, req); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 471 | out_put_forget_req: |
| 472 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 473 | return err; |
| 474 | } |
| 475 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 476 | /* |
| 477 | * Code shared between mknod, mkdir, symlink and link |
| 478 | */ |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 479 | static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, |
| 480 | struct inode *dir, struct dentry *entry, |
| 481 | int mode) |
| 482 | { |
| 483 | struct fuse_entry_out outarg; |
| 484 | struct inode *inode; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 485 | int err; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 486 | struct fuse_req *forget_req; |
| 487 | |
| 488 | forget_req = fuse_get_req(fc); |
| 489 | if (IS_ERR(forget_req)) { |
| 490 | fuse_put_request(fc, req); |
| 491 | return PTR_ERR(forget_req); |
| 492 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 493 | |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 494 | memset(&outarg, 0, sizeof(outarg)); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 495 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 496 | req->out.numargs = 1; |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 497 | if (fc->minor < 9) |
| 498 | req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE; |
| 499 | else |
| 500 | req->out.args[0].size = sizeof(outarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 501 | req->out.args[0].value = &outarg; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 502 | fuse_request_send(fc, req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 503 | err = req->out.h.error; |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 504 | fuse_put_request(fc, req); |
| 505 | if (err) |
| 506 | goto out_put_forget_req; |
| 507 | |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 508 | err = -EIO; |
| 509 | if (invalid_nodeid(outarg.nodeid)) |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 510 | goto out_put_forget_req; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 511 | |
| 512 | if ((outarg.attr.mode ^ mode) & S_IFMT) |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 513 | goto out_put_forget_req; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 514 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 515 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 516 | &outarg.attr, entry_attr_timeout(&outarg), 0); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 517 | if (!inode) { |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 518 | fuse_send_forget(fc, forget_req, outarg.nodeid, 1); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 519 | return -ENOMEM; |
| 520 | } |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 521 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 522 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 523 | if (S_ISDIR(inode->i_mode)) { |
| 524 | struct dentry *alias; |
| 525 | mutex_lock(&fc->inst_mutex); |
| 526 | alias = d_find_alias(inode); |
| 527 | if (alias) { |
| 528 | /* New directory must have moved since mkdir */ |
| 529 | mutex_unlock(&fc->inst_mutex); |
| 530 | dput(alias); |
| 531 | iput(inode); |
| 532 | return -EBUSY; |
| 533 | } |
| 534 | d_instantiate(entry, inode); |
| 535 | mutex_unlock(&fc->inst_mutex); |
| 536 | } else |
| 537 | d_instantiate(entry, inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 538 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 539 | fuse_change_entry_timeout(entry, &outarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 540 | fuse_invalidate_attr(dir); |
| 541 | return 0; |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 542 | |
Miklos Szeredi | 2d51013 | 2006-11-25 11:09:20 -0800 | [diff] [blame] | 543 | out_put_forget_req: |
| 544 | fuse_put_request(fc, forget_req); |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 545 | return err; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
| 549 | dev_t rdev) |
| 550 | { |
| 551 | struct fuse_mknod_in inarg; |
| 552 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 553 | struct fuse_req *req = fuse_get_req(fc); |
| 554 | if (IS_ERR(req)) |
| 555 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 556 | |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 557 | if (!fc->dont_mask) |
| 558 | mode &= ~current_umask(); |
| 559 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 560 | memset(&inarg, 0, sizeof(inarg)); |
| 561 | inarg.mode = mode; |
| 562 | inarg.rdev = new_encode_dev(rdev); |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 563 | inarg.umask = current_umask(); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 564 | req->in.h.opcode = FUSE_MKNOD; |
| 565 | req->in.numargs = 2; |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 566 | req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE : |
| 567 | sizeof(inarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 568 | req->in.args[0].value = &inarg; |
| 569 | req->in.args[1].size = entry->d_name.len + 1; |
| 570 | req->in.args[1].value = entry->d_name.name; |
| 571 | return create_new_entry(fc, req, dir, entry, mode); |
| 572 | } |
| 573 | |
| 574 | static int fuse_create(struct inode *dir, struct dentry *entry, int mode, |
| 575 | struct nameidata *nd) |
| 576 | { |
Miklos Szeredi | b9ba347 | 2007-05-23 13:57:32 -0700 | [diff] [blame] | 577 | if (nd && (nd->flags & LOOKUP_OPEN)) { |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 578 | int err = fuse_create_open(dir, entry, mode, nd); |
| 579 | if (err != -ENOSYS) |
| 580 | return err; |
| 581 | /* Fall back on mknod */ |
| 582 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 583 | return fuse_mknod(dir, entry, mode, 0); |
| 584 | } |
| 585 | |
| 586 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) |
| 587 | { |
| 588 | struct fuse_mkdir_in inarg; |
| 589 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 590 | struct fuse_req *req = fuse_get_req(fc); |
| 591 | if (IS_ERR(req)) |
| 592 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 593 | |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 594 | if (!fc->dont_mask) |
| 595 | mode &= ~current_umask(); |
| 596 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 597 | memset(&inarg, 0, sizeof(inarg)); |
| 598 | inarg.mode = mode; |
Miklos Szeredi | e0a43dd | 2009-06-30 20:12:23 +0200 | [diff] [blame] | 599 | inarg.umask = current_umask(); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 600 | req->in.h.opcode = FUSE_MKDIR; |
| 601 | req->in.numargs = 2; |
| 602 | req->in.args[0].size = sizeof(inarg); |
| 603 | req->in.args[0].value = &inarg; |
| 604 | req->in.args[1].size = entry->d_name.len + 1; |
| 605 | req->in.args[1].value = entry->d_name.name; |
| 606 | return create_new_entry(fc, req, dir, entry, S_IFDIR); |
| 607 | } |
| 608 | |
| 609 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
| 610 | const char *link) |
| 611 | { |
| 612 | struct fuse_conn *fc = get_fuse_conn(dir); |
| 613 | unsigned len = strlen(link) + 1; |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 614 | struct fuse_req *req = fuse_get_req(fc); |
| 615 | if (IS_ERR(req)) |
| 616 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 617 | |
| 618 | req->in.h.opcode = FUSE_SYMLINK; |
| 619 | req->in.numargs = 2; |
| 620 | req->in.args[0].size = entry->d_name.len + 1; |
| 621 | req->in.args[0].value = entry->d_name.name; |
| 622 | req->in.args[1].size = len; |
| 623 | req->in.args[1].value = link; |
| 624 | return create_new_entry(fc, req, dir, entry, S_IFLNK); |
| 625 | } |
| 626 | |
| 627 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
| 628 | { |
| 629 | int err; |
| 630 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 631 | struct fuse_req *req = fuse_get_req(fc); |
| 632 | if (IS_ERR(req)) |
| 633 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 634 | |
| 635 | req->in.h.opcode = FUSE_UNLINK; |
| 636 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 637 | req->in.numargs = 1; |
| 638 | req->in.args[0].size = entry->d_name.len + 1; |
| 639 | req->in.args[0].value = entry->d_name.name; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 640 | fuse_request_send(fc, req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 641 | err = req->out.h.error; |
| 642 | fuse_put_request(fc, req); |
| 643 | if (!err) { |
| 644 | struct inode *inode = entry->d_inode; |
| 645 | |
Miklos Szeredi | 1729a16 | 2008-11-26 12:03:54 +0100 | [diff] [blame] | 646 | /* |
| 647 | * Set nlink to zero so the inode can be cleared, if the inode |
| 648 | * does have more links this will be discovered at the next |
| 649 | * lookup/getattr. |
| 650 | */ |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 651 | clear_nlink(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 652 | fuse_invalidate_attr(inode); |
| 653 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 654 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 655 | } else if (err == -EINTR) |
| 656 | fuse_invalidate_entry(entry); |
| 657 | return err; |
| 658 | } |
| 659 | |
| 660 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
| 661 | { |
| 662 | int err; |
| 663 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 664 | struct fuse_req *req = fuse_get_req(fc); |
| 665 | if (IS_ERR(req)) |
| 666 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 667 | |
| 668 | req->in.h.opcode = FUSE_RMDIR; |
| 669 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 670 | req->in.numargs = 1; |
| 671 | req->in.args[0].size = entry->d_name.len + 1; |
| 672 | req->in.args[0].value = entry->d_name.name; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 673 | fuse_request_send(fc, req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 674 | err = req->out.h.error; |
| 675 | fuse_put_request(fc, req); |
| 676 | if (!err) { |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 677 | clear_nlink(entry->d_inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 678 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 679 | fuse_invalidate_entry_cache(entry); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 680 | } else if (err == -EINTR) |
| 681 | fuse_invalidate_entry(entry); |
| 682 | return err; |
| 683 | } |
| 684 | |
| 685 | static int fuse_rename(struct inode *olddir, struct dentry *oldent, |
| 686 | struct inode *newdir, struct dentry *newent) |
| 687 | { |
| 688 | int err; |
| 689 | struct fuse_rename_in inarg; |
| 690 | struct fuse_conn *fc = get_fuse_conn(olddir); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 691 | struct fuse_req *req = fuse_get_req(fc); |
| 692 | if (IS_ERR(req)) |
| 693 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 694 | |
| 695 | memset(&inarg, 0, sizeof(inarg)); |
| 696 | inarg.newdir = get_node_id(newdir); |
| 697 | req->in.h.opcode = FUSE_RENAME; |
| 698 | req->in.h.nodeid = get_node_id(olddir); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 699 | req->in.numargs = 3; |
| 700 | req->in.args[0].size = sizeof(inarg); |
| 701 | req->in.args[0].value = &inarg; |
| 702 | req->in.args[1].size = oldent->d_name.len + 1; |
| 703 | req->in.args[1].value = oldent->d_name.name; |
| 704 | req->in.args[2].size = newent->d_name.len + 1; |
| 705 | req->in.args[2].value = newent->d_name.name; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 706 | fuse_request_send(fc, req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 707 | err = req->out.h.error; |
| 708 | fuse_put_request(fc, req); |
| 709 | if (!err) { |
Miklos Szeredi | 08b6330 | 2007-11-28 16:22:03 -0800 | [diff] [blame] | 710 | /* ctime changes */ |
| 711 | fuse_invalidate_attr(oldent->d_inode); |
| 712 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 713 | fuse_invalidate_attr(olddir); |
| 714 | if (olddir != newdir) |
| 715 | fuse_invalidate_attr(newdir); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 716 | |
| 717 | /* newent will end up negative */ |
Miklos Szeredi | 5219f34 | 2009-11-04 10:24:52 +0100 | [diff] [blame] | 718 | if (newent->d_inode) { |
| 719 | fuse_invalidate_attr(newent->d_inode); |
Miklos Szeredi | 8cbdf1e | 2006-01-06 00:19:38 -0800 | [diff] [blame] | 720 | fuse_invalidate_entry_cache(newent); |
Miklos Szeredi | 5219f34 | 2009-11-04 10:24:52 +0100 | [diff] [blame] | 721 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 722 | } else if (err == -EINTR) { |
| 723 | /* If request was interrupted, DEITY only knows if the |
| 724 | rename actually took place. If the invalidation |
| 725 | fails (e.g. some process has CWD under the renamed |
| 726 | directory), then there can be inconsistency between |
| 727 | the dcache and the real filesystem. Tough luck. */ |
| 728 | fuse_invalidate_entry(oldent); |
| 729 | if (newent->d_inode) |
| 730 | fuse_invalidate_entry(newent); |
| 731 | } |
| 732 | |
| 733 | return err; |
| 734 | } |
| 735 | |
| 736 | static int fuse_link(struct dentry *entry, struct inode *newdir, |
| 737 | struct dentry *newent) |
| 738 | { |
| 739 | int err; |
| 740 | struct fuse_link_in inarg; |
| 741 | struct inode *inode = entry->d_inode; |
| 742 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 743 | struct fuse_req *req = fuse_get_req(fc); |
| 744 | if (IS_ERR(req)) |
| 745 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 746 | |
| 747 | memset(&inarg, 0, sizeof(inarg)); |
| 748 | inarg.oldnodeid = get_node_id(inode); |
| 749 | req->in.h.opcode = FUSE_LINK; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 750 | req->in.numargs = 2; |
| 751 | req->in.args[0].size = sizeof(inarg); |
| 752 | req->in.args[0].value = &inarg; |
| 753 | req->in.args[1].size = newent->d_name.len + 1; |
| 754 | req->in.args[1].value = newent->d_name.name; |
| 755 | err = create_new_entry(fc, req, newdir, newent, inode->i_mode); |
| 756 | /* Contrary to "normal" filesystems it can happen that link |
| 757 | makes two "logical" inodes point to the same "physical" |
| 758 | inode. We invalidate the attributes of the old one, so it |
| 759 | will reflect changes in the backing inode (link count, |
| 760 | etc.) |
| 761 | */ |
| 762 | if (!err || err == -EINTR) |
| 763 | fuse_invalidate_attr(inode); |
| 764 | return err; |
| 765 | } |
| 766 | |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 767 | static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr, |
| 768 | struct kstat *stat) |
| 769 | { |
| 770 | stat->dev = inode->i_sb->s_dev; |
| 771 | stat->ino = attr->ino; |
| 772 | stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777); |
| 773 | stat->nlink = attr->nlink; |
| 774 | stat->uid = attr->uid; |
| 775 | stat->gid = attr->gid; |
| 776 | stat->rdev = inode->i_rdev; |
| 777 | stat->atime.tv_sec = attr->atime; |
| 778 | stat->atime.tv_nsec = attr->atimensec; |
| 779 | stat->mtime.tv_sec = attr->mtime; |
| 780 | stat->mtime.tv_nsec = attr->mtimensec; |
| 781 | stat->ctime.tv_sec = attr->ctime; |
| 782 | stat->ctime.tv_nsec = attr->ctimensec; |
| 783 | stat->size = attr->size; |
| 784 | stat->blocks = attr->blocks; |
| 785 | stat->blksize = (1 << inode->i_blkbits); |
| 786 | } |
| 787 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 788 | static int fuse_do_getattr(struct inode *inode, struct kstat *stat, |
| 789 | struct file *file) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 790 | { |
| 791 | int err; |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 792 | struct fuse_getattr_in inarg; |
| 793 | struct fuse_attr_out outarg; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 794 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 795 | struct fuse_req *req; |
| 796 | u64 attr_version; |
| 797 | |
| 798 | req = fuse_get_req(fc); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 799 | if (IS_ERR(req)) |
| 800 | return PTR_ERR(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 801 | |
Miklos Szeredi | 7dca9fd | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 802 | attr_version = fuse_get_attr_version(fc); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 803 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 804 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 805 | memset(&outarg, 0, sizeof(outarg)); |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 806 | /* Directories have separate file-handle space */ |
| 807 | if (file && S_ISREG(inode->i_mode)) { |
| 808 | struct fuse_file *ff = file->private_data; |
| 809 | |
| 810 | inarg.getattr_flags |= FUSE_GETATTR_FH; |
| 811 | inarg.fh = ff->fh; |
| 812 | } |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 813 | req->in.h.opcode = FUSE_GETATTR; |
| 814 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 815 | req->in.numargs = 1; |
| 816 | req->in.args[0].size = sizeof(inarg); |
| 817 | req->in.args[0].value = &inarg; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 818 | req->out.numargs = 1; |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 819 | if (fc->minor < 9) |
| 820 | req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE; |
| 821 | else |
| 822 | req->out.args[0].size = sizeof(outarg); |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 823 | req->out.args[0].value = &outarg; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 824 | fuse_request_send(fc, req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 825 | err = req->out.h.error; |
| 826 | fuse_put_request(fc, req); |
| 827 | if (!err) { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 828 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 829 | make_bad_inode(inode); |
| 830 | err = -EIO; |
| 831 | } else { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 832 | fuse_change_attributes(inode, &outarg.attr, |
| 833 | attr_timeout(&outarg), |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 834 | attr_version); |
| 835 | if (stat) |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 836 | fuse_fillattr(inode, &outarg.attr, stat); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | return err; |
| 840 | } |
| 841 | |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 842 | int fuse_update_attributes(struct inode *inode, struct kstat *stat, |
| 843 | struct file *file, bool *refreshed) |
| 844 | { |
| 845 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 846 | int err; |
| 847 | bool r; |
| 848 | |
| 849 | if (fi->i_time < get_jiffies_64()) { |
| 850 | r = true; |
| 851 | err = fuse_do_getattr(inode, stat, file); |
| 852 | } else { |
| 853 | r = false; |
| 854 | err = 0; |
| 855 | if (stat) { |
| 856 | generic_fillattr(inode, stat); |
| 857 | stat->mode = fi->orig_i_mode; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | if (refreshed != NULL) |
| 862 | *refreshed = r; |
| 863 | |
| 864 | return err; |
| 865 | } |
| 866 | |
John Muir | 3b463ae | 2009-05-31 11:13:57 -0400 | [diff] [blame] | 867 | int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, |
| 868 | struct qstr *name) |
| 869 | { |
| 870 | int err = -ENOTDIR; |
| 871 | struct inode *parent; |
| 872 | struct dentry *dir; |
| 873 | struct dentry *entry; |
| 874 | |
| 875 | parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid); |
| 876 | if (!parent) |
| 877 | return -ENOENT; |
| 878 | |
| 879 | mutex_lock(&parent->i_mutex); |
| 880 | if (!S_ISDIR(parent->i_mode)) |
| 881 | goto unlock; |
| 882 | |
| 883 | err = -ENOENT; |
| 884 | dir = d_find_alias(parent); |
| 885 | if (!dir) |
| 886 | goto unlock; |
| 887 | |
| 888 | entry = d_lookup(dir, name); |
| 889 | dput(dir); |
| 890 | if (!entry) |
| 891 | goto unlock; |
| 892 | |
| 893 | fuse_invalidate_attr(parent); |
| 894 | fuse_invalidate_entry(entry); |
| 895 | dput(entry); |
| 896 | err = 0; |
| 897 | |
| 898 | unlock: |
| 899 | mutex_unlock(&parent->i_mutex); |
| 900 | iput(parent); |
| 901 | return err; |
| 902 | } |
| 903 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 904 | /* |
| 905 | * Calling into a user-controlled filesystem gives the filesystem |
| 906 | * daemon ptrace-like capabilities over the requester process. This |
| 907 | * means, that the filesystem daemon is able to record the exact |
| 908 | * filesystem operations performed, and can also control the behavior |
| 909 | * of the requester process in otherwise impossible ways. For example |
| 910 | * it can delay the operation for arbitrary length of time allowing |
| 911 | * DoS against the requester. |
| 912 | * |
| 913 | * For this reason only those processes can call into the filesystem, |
| 914 | * for which the owner of the mount has ptrace privilege. This |
| 915 | * excludes processes started by other users, suid or sgid processes. |
| 916 | */ |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 917 | int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task) |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 918 | { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 919 | const struct cred *cred; |
| 920 | int ret; |
| 921 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 922 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 923 | return 1; |
| 924 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 925 | rcu_read_lock(); |
| 926 | ret = 0; |
| 927 | cred = __task_cred(task); |
| 928 | if (cred->euid == fc->user_id && |
| 929 | cred->suid == fc->user_id && |
| 930 | cred->uid == fc->user_id && |
| 931 | cred->egid == fc->group_id && |
| 932 | cred->sgid == fc->group_id && |
| 933 | cred->gid == fc->group_id) |
| 934 | ret = 1; |
| 935 | rcu_read_unlock(); |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 936 | |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 937 | return ret; |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 940 | static int fuse_access(struct inode *inode, int mask) |
| 941 | { |
| 942 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 943 | struct fuse_req *req; |
| 944 | struct fuse_access_in inarg; |
| 945 | int err; |
| 946 | |
| 947 | if (fc->no_access) |
| 948 | return 0; |
| 949 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 950 | req = fuse_get_req(fc); |
| 951 | if (IS_ERR(req)) |
| 952 | return PTR_ERR(req); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 953 | |
| 954 | memset(&inarg, 0, sizeof(inarg)); |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 955 | inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 956 | req->in.h.opcode = FUSE_ACCESS; |
| 957 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 958 | req->in.numargs = 1; |
| 959 | req->in.args[0].size = sizeof(inarg); |
| 960 | req->in.args[0].value = &inarg; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 961 | fuse_request_send(fc, req); |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 962 | err = req->out.h.error; |
| 963 | fuse_put_request(fc, req); |
| 964 | if (err == -ENOSYS) { |
| 965 | fc->no_access = 1; |
| 966 | err = 0; |
| 967 | } |
| 968 | return err; |
| 969 | } |
| 970 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 971 | /* |
| 972 | * Check permission. The two basic access models of FUSE are: |
| 973 | * |
| 974 | * 1) Local access checking ('default_permissions' mount option) based |
| 975 | * on file mode. This is the plain old disk filesystem permission |
| 976 | * modell. |
| 977 | * |
| 978 | * 2) "Remote" access checking, where server is responsible for |
| 979 | * checking permission in each inode operation. An exception to this |
| 980 | * is if ->permission() was invoked from sys_access() in which case an |
| 981 | * access request is sent. Execute permission is still checked |
| 982 | * locally based on file mode. |
| 983 | */ |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 984 | static int fuse_permission(struct inode *inode, int mask) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 985 | { |
| 986 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 987 | bool refreshed = false; |
| 988 | int err = 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 989 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 990 | if (!fuse_allow_task(fc, current)) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 991 | return -EACCES; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 992 | |
| 993 | /* |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 994 | * If attributes are needed, refresh them before proceeding |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 995 | */ |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 996 | if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) || |
| 997 | ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) { |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 998 | err = fuse_update_attributes(inode, NULL, NULL, &refreshed); |
| 999 | if (err) |
| 1000 | return err; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 1a823ac | 2008-02-23 15:23:27 -0800 | [diff] [blame] | 1004 | err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1005 | |
| 1006 | /* If permission is denied, try to refresh file |
| 1007 | attributes. This is also needed, because the root |
| 1008 | node will at first have no permissions */ |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1009 | if (err == -EACCES && !refreshed) { |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 1010 | err = fuse_do_getattr(inode, NULL, NULL); |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1011 | if (!err) |
| 1012 | err = generic_permission(inode, mask, NULL); |
| 1013 | } |
| 1014 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1015 | /* Note: the opposite of the above test does not |
| 1016 | exist. So if permissions are revoked this won't be |
| 1017 | noticed immediately, only after the attribute |
| 1018 | timeout has expired */ |
Eric Paris | 9cfcac8 | 2010-07-23 11:43:51 -0400 | [diff] [blame] | 1019 | } else if (mask & (MAY_ACCESS | MAY_CHDIR)) { |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 1020 | err = fuse_access(inode, mask); |
| 1021 | } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) { |
| 1022 | if (!(inode->i_mode & S_IXUGO)) { |
| 1023 | if (refreshed) |
| 1024 | return -EACCES; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1025 | |
Miklos Szeredi | c79e322 | 2007-10-18 03:06:59 -0700 | [diff] [blame] | 1026 | err = fuse_do_getattr(inode, NULL, NULL); |
Miklos Szeredi | e8e9615 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 1027 | if (!err && !(inode->i_mode & S_IXUGO)) |
| 1028 | return -EACCES; |
| 1029 | } |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1030 | } |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1031 | return err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 1035 | void *dstbuf, filldir_t filldir) |
| 1036 | { |
| 1037 | while (nbytes >= FUSE_NAME_OFFSET) { |
| 1038 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
| 1039 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 1040 | int over; |
| 1041 | if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX) |
| 1042 | return -EIO; |
| 1043 | if (reclen > nbytes) |
| 1044 | break; |
| 1045 | |
| 1046 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
| 1047 | file->f_pos, dirent->ino, dirent->type); |
| 1048 | if (over) |
| 1049 | break; |
| 1050 | |
| 1051 | buf += reclen; |
| 1052 | nbytes -= reclen; |
| 1053 | file->f_pos = dirent->off; |
| 1054 | } |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1059 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 1060 | { |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1061 | int err; |
| 1062 | size_t nbytes; |
| 1063 | struct page *page; |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 1064 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1065 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1066 | struct fuse_req *req; |
| 1067 | |
| 1068 | if (is_bad_inode(inode)) |
| 1069 | return -EIO; |
| 1070 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1071 | req = fuse_get_req(fc); |
| 1072 | if (IS_ERR(req)) |
| 1073 | return PTR_ERR(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1074 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1075 | page = alloc_page(GFP_KERNEL); |
| 1076 | if (!page) { |
| 1077 | fuse_put_request(fc, req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1078 | return -ENOMEM; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1079 | } |
Miklos Szeredi | f4975c6 | 2009-04-02 14:25:34 +0200 | [diff] [blame] | 1080 | req->out.argpages = 1; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1081 | req->num_pages = 1; |
| 1082 | req->pages[0] = page; |
Miklos Szeredi | 2106cb1 | 2009-04-28 16:56:37 +0200 | [diff] [blame] | 1083 | fuse_read_fill(req, file, file->f_pos, PAGE_SIZE, FUSE_READDIR); |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1084 | fuse_request_send(fc, req); |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 1085 | nbytes = req->out.args[0].size; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1086 | err = req->out.h.error; |
| 1087 | fuse_put_request(fc, req); |
| 1088 | if (!err) |
| 1089 | err = parse_dirfile(page_address(page), nbytes, file, dstbuf, |
| 1090 | filldir); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1091 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1092 | __free_page(page); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1093 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 1094 | return err; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static char *read_link(struct dentry *dentry) |
| 1098 | { |
| 1099 | struct inode *inode = dentry->d_inode; |
| 1100 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1101 | struct fuse_req *req = fuse_get_req(fc); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1102 | char *link; |
| 1103 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1104 | if (IS_ERR(req)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 1105 | return ERR_CAST(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1106 | |
| 1107 | link = (char *) __get_free_page(GFP_KERNEL); |
| 1108 | if (!link) { |
| 1109 | link = ERR_PTR(-ENOMEM); |
| 1110 | goto out; |
| 1111 | } |
| 1112 | req->in.h.opcode = FUSE_READLINK; |
| 1113 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1114 | req->out.argvar = 1; |
| 1115 | req->out.numargs = 1; |
| 1116 | req->out.args[0].size = PAGE_SIZE - 1; |
| 1117 | req->out.args[0].value = link; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1118 | fuse_request_send(fc, req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1119 | if (req->out.h.error) { |
| 1120 | free_page((unsigned long) link); |
| 1121 | link = ERR_PTR(req->out.h.error); |
| 1122 | } else |
| 1123 | link[req->out.args[0].size] = '\0'; |
| 1124 | out: |
| 1125 | fuse_put_request(fc, req); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1126 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1127 | return link; |
| 1128 | } |
| 1129 | |
| 1130 | static void free_link(char *link) |
| 1131 | { |
| 1132 | if (!IS_ERR(link)) |
| 1133 | free_page((unsigned long) link); |
| 1134 | } |
| 1135 | |
| 1136 | static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 1137 | { |
| 1138 | nd_set_link(nd, read_link(dentry)); |
| 1139 | return NULL; |
| 1140 | } |
| 1141 | |
| 1142 | static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c) |
| 1143 | { |
| 1144 | free_link(nd_get_link(nd)); |
| 1145 | } |
| 1146 | |
| 1147 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 1148 | { |
Miklos Szeredi | 91fe96b | 2009-04-28 16:56:37 +0200 | [diff] [blame] | 1149 | return fuse_open_common(inode, file, true); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 1153 | { |
Miklos Szeredi | 8b0797a | 2009-04-28 16:56:39 +0200 | [diff] [blame] | 1154 | fuse_release_common(file, FUSE_RELEASEDIR); |
| 1155 | |
| 1156 | return 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Christoph Hellwig | 7ea8085 | 2010-05-26 17:53:25 +0200 | [diff] [blame] | 1159 | static int fuse_dir_fsync(struct file *file, int datasync) |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1160 | { |
Christoph Hellwig | 7ea8085 | 2010-05-26 17:53:25 +0200 | [diff] [blame] | 1161 | return fuse_fsync_common(file, datasync, 1); |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
Miklos Szeredi | 17637cb | 2007-10-18 03:07:01 -0700 | [diff] [blame] | 1164 | static bool update_mtime(unsigned ivalid) |
| 1165 | { |
| 1166 | /* Always update if mtime is explicitly set */ |
| 1167 | if (ivalid & ATTR_MTIME_SET) |
| 1168 | return true; |
| 1169 | |
| 1170 | /* If it's an open(O_TRUNC) or an ftruncate(), don't update */ |
| 1171 | if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE))) |
| 1172 | return false; |
| 1173 | |
| 1174 | /* In all other cases update */ |
| 1175 | return true; |
| 1176 | } |
| 1177 | |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1178 | 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] | 1179 | { |
| 1180 | unsigned ivalid = iattr->ia_valid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1181 | |
| 1182 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1183 | arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1184 | if (ivalid & ATTR_UID) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1185 | arg->valid |= FATTR_UID, arg->uid = iattr->ia_uid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1186 | if (ivalid & ATTR_GID) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1187 | arg->valid |= FATTR_GID, arg->gid = iattr->ia_gid; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1188 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1189 | arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size; |
Miklos Szeredi | 17637cb | 2007-10-18 03:07:01 -0700 | [diff] [blame] | 1190 | if (ivalid & ATTR_ATIME) { |
| 1191 | arg->valid |= FATTR_ATIME; |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1192 | arg->atime = iattr->ia_atime.tv_sec; |
Miklos Szeredi | 17637cb | 2007-10-18 03:07:01 -0700 | [diff] [blame] | 1193 | arg->atimensec = iattr->ia_atime.tv_nsec; |
| 1194 | if (!(ivalid & ATTR_ATIME_SET)) |
| 1195 | arg->valid |= FATTR_ATIME_NOW; |
| 1196 | } |
| 1197 | if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) { |
| 1198 | arg->valid |= FATTR_MTIME; |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1199 | arg->mtime = iattr->ia_mtime.tv_sec; |
Miklos Szeredi | 17637cb | 2007-10-18 03:07:01 -0700 | [diff] [blame] | 1200 | arg->mtimensec = iattr->ia_mtime.tv_nsec; |
| 1201 | if (!(ivalid & ATTR_MTIME_SET)) |
| 1202 | arg->valid |= FATTR_MTIME_NOW; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1203 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1206 | /* |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1207 | * Prevent concurrent writepages on inode |
| 1208 | * |
| 1209 | * This is done by adding a negative bias to the inode write counter |
| 1210 | * and waiting for all pending writes to finish. |
| 1211 | */ |
| 1212 | void fuse_set_nowrite(struct inode *inode) |
| 1213 | { |
| 1214 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1215 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 1216 | |
| 1217 | BUG_ON(!mutex_is_locked(&inode->i_mutex)); |
| 1218 | |
| 1219 | spin_lock(&fc->lock); |
| 1220 | BUG_ON(fi->writectr < 0); |
| 1221 | fi->writectr += FUSE_NOWRITE; |
| 1222 | spin_unlock(&fc->lock); |
| 1223 | wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE); |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | * Allow writepages on inode |
| 1228 | * |
| 1229 | * Remove the bias from the writecounter and send any queued |
| 1230 | * writepages. |
| 1231 | */ |
| 1232 | static void __fuse_release_nowrite(struct inode *inode) |
| 1233 | { |
| 1234 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 1235 | |
| 1236 | BUG_ON(fi->writectr != FUSE_NOWRITE); |
| 1237 | fi->writectr = 0; |
| 1238 | fuse_flush_writepages(inode); |
| 1239 | } |
| 1240 | |
| 1241 | void fuse_release_nowrite(struct inode *inode) |
| 1242 | { |
| 1243 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1244 | |
| 1245 | spin_lock(&fc->lock); |
| 1246 | __fuse_release_nowrite(inode); |
| 1247 | spin_unlock(&fc->lock); |
| 1248 | } |
| 1249 | |
| 1250 | /* |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1251 | * Set attributes, and at the same time refresh them. |
| 1252 | * |
| 1253 | * Truncation is slightly complicated, because the 'truncate' request |
| 1254 | * 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] | 1255 | * vmtruncate() doesn't allow for this case, so do the rlimit checking |
| 1256 | * and the actual truncation by hand. |
Miklos Szeredi | 6f9f118 | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 1257 | */ |
Miklos Szeredi | 49d4914 | 2007-10-18 03:07:00 -0700 | [diff] [blame] | 1258 | static int fuse_do_setattr(struct dentry *entry, struct iattr *attr, |
| 1259 | struct file *file) |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1260 | { |
| 1261 | struct inode *inode = entry->d_inode; |
| 1262 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1263 | struct fuse_req *req; |
| 1264 | struct fuse_setattr_in inarg; |
| 1265 | struct fuse_attr_out outarg; |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1266 | bool is_truncate = false; |
| 1267 | loff_t oldsize; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1268 | int err; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1269 | |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1270 | if (!fuse_allow_task(fc, current)) |
| 1271 | return -EACCES; |
| 1272 | |
Christoph Hellwig | db78b87 | 2010-06-04 11:30:03 +0200 | [diff] [blame] | 1273 | if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS)) |
| 1274 | attr->ia_valid |= ATTR_FORCE; |
| 1275 | |
| 1276 | err = inode_change_ok(inode, attr); |
| 1277 | if (err) |
| 1278 | return err; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1279 | |
Miklos Szeredi | 6ff958e | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 1280 | if ((attr->ia_valid & ATTR_OPEN) && fc->atomic_o_trunc) |
| 1281 | return 0; |
| 1282 | |
Christoph Hellwig | 2c27c65 | 2010-06-04 11:30:04 +0200 | [diff] [blame] | 1283 | if (attr->ia_valid & ATTR_SIZE) |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1284 | is_truncate = true; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1285 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1286 | req = fuse_get_req(fc); |
| 1287 | if (IS_ERR(req)) |
| 1288 | return PTR_ERR(req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1289 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1290 | if (is_truncate) |
| 1291 | fuse_set_nowrite(inode); |
| 1292 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1293 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 1294 | memset(&outarg, 0, sizeof(outarg)); |
Miklos Szeredi | befc649 | 2005-11-07 00:59:52 -0800 | [diff] [blame] | 1295 | iattr_to_fattr(attr, &inarg); |
Miklos Szeredi | 49d4914 | 2007-10-18 03:07:00 -0700 | [diff] [blame] | 1296 | if (file) { |
| 1297 | struct fuse_file *ff = file->private_data; |
| 1298 | inarg.valid |= FATTR_FH; |
| 1299 | inarg.fh = ff->fh; |
| 1300 | } |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 1301 | if (attr->ia_valid & ATTR_SIZE) { |
| 1302 | /* For mandatory locking in truncate */ |
| 1303 | inarg.valid |= FATTR_LOCKOWNER; |
| 1304 | inarg.lock_owner = fuse_lock_owner_id(fc, current->files); |
| 1305 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1306 | req->in.h.opcode = FUSE_SETATTR; |
| 1307 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1308 | req->in.numargs = 1; |
| 1309 | req->in.args[0].size = sizeof(inarg); |
| 1310 | req->in.args[0].value = &inarg; |
| 1311 | req->out.numargs = 1; |
Miklos Szeredi | 0e9663e | 2007-10-18 03:07:05 -0700 | [diff] [blame] | 1312 | if (fc->minor < 9) |
| 1313 | req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE; |
| 1314 | else |
| 1315 | req->out.args[0].size = sizeof(outarg); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1316 | req->out.args[0].value = &outarg; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1317 | fuse_request_send(fc, req); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1318 | err = req->out.h.error; |
| 1319 | fuse_put_request(fc, req); |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1320 | if (err) { |
| 1321 | if (err == -EINTR) |
| 1322 | fuse_invalidate_attr(inode); |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1323 | goto error; |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1324 | } |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1325 | |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1326 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
| 1327 | make_bad_inode(inode); |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1328 | err = -EIO; |
| 1329 | goto error; |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1332 | spin_lock(&fc->lock); |
| 1333 | fuse_change_attributes_common(inode, &outarg.attr, |
| 1334 | attr_timeout(&outarg)); |
| 1335 | oldsize = inode->i_size; |
| 1336 | i_size_write(inode, outarg.attr.size); |
| 1337 | |
| 1338 | if (is_truncate) { |
| 1339 | /* NOTE: this may release/reacquire fc->lock */ |
| 1340 | __fuse_release_nowrite(inode); |
| 1341 | } |
| 1342 | spin_unlock(&fc->lock); |
| 1343 | |
| 1344 | /* |
| 1345 | * Only call invalidate_inode_pages2() after removing |
| 1346 | * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock. |
| 1347 | */ |
| 1348 | if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) { |
npiggin@suse.de | c08d3b0 | 2009-08-21 02:35:06 +1000 | [diff] [blame] | 1349 | truncate_pagecache(inode, oldsize, outarg.attr.size); |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1350 | invalidate_inode_pages2(inode->i_mapping); |
| 1351 | } |
| 1352 | |
Miklos Szeredi | e00d2c2 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 1353 | return 0; |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 1354 | |
| 1355 | error: |
| 1356 | if (is_truncate) |
| 1357 | fuse_release_nowrite(inode); |
| 1358 | |
| 1359 | return err; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Miklos Szeredi | 49d4914 | 2007-10-18 03:07:00 -0700 | [diff] [blame] | 1362 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 1363 | { |
| 1364 | if (attr->ia_valid & ATTR_FILE) |
| 1365 | return fuse_do_setattr(entry, attr, attr->ia_file); |
| 1366 | else |
| 1367 | return fuse_do_setattr(entry, attr, NULL); |
| 1368 | } |
| 1369 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1370 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 1371 | struct kstat *stat) |
| 1372 | { |
| 1373 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1374 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 244f638 | 2007-10-16 23:31:02 -0700 | [diff] [blame] | 1375 | |
| 1376 | if (!fuse_allow_task(fc, current)) |
| 1377 | return -EACCES; |
| 1378 | |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 1379 | return fuse_update_attributes(inode, stat, NULL, NULL); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1382 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 1383 | const void *value, size_t size, int flags) |
| 1384 | { |
| 1385 | struct inode *inode = entry->d_inode; |
| 1386 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1387 | struct fuse_req *req; |
| 1388 | struct fuse_setxattr_in inarg; |
| 1389 | int err; |
| 1390 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1391 | if (fc->no_setxattr) |
| 1392 | return -EOPNOTSUPP; |
| 1393 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1394 | req = fuse_get_req(fc); |
| 1395 | if (IS_ERR(req)) |
| 1396 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1397 | |
| 1398 | memset(&inarg, 0, sizeof(inarg)); |
| 1399 | inarg.size = size; |
| 1400 | inarg.flags = flags; |
| 1401 | req->in.h.opcode = FUSE_SETXATTR; |
| 1402 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1403 | req->in.numargs = 3; |
| 1404 | req->in.args[0].size = sizeof(inarg); |
| 1405 | req->in.args[0].value = &inarg; |
| 1406 | req->in.args[1].size = strlen(name) + 1; |
| 1407 | req->in.args[1].value = name; |
| 1408 | req->in.args[2].size = size; |
| 1409 | req->in.args[2].value = value; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1410 | fuse_request_send(fc, req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1411 | err = req->out.h.error; |
| 1412 | fuse_put_request(fc, req); |
| 1413 | if (err == -ENOSYS) { |
| 1414 | fc->no_setxattr = 1; |
| 1415 | err = -EOPNOTSUPP; |
| 1416 | } |
| 1417 | return err; |
| 1418 | } |
| 1419 | |
| 1420 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 1421 | void *value, size_t size) |
| 1422 | { |
| 1423 | struct inode *inode = entry->d_inode; |
| 1424 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1425 | struct fuse_req *req; |
| 1426 | struct fuse_getxattr_in inarg; |
| 1427 | struct fuse_getxattr_out outarg; |
| 1428 | ssize_t ret; |
| 1429 | |
| 1430 | if (fc->no_getxattr) |
| 1431 | return -EOPNOTSUPP; |
| 1432 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1433 | req = fuse_get_req(fc); |
| 1434 | if (IS_ERR(req)) |
| 1435 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1436 | |
| 1437 | memset(&inarg, 0, sizeof(inarg)); |
| 1438 | inarg.size = size; |
| 1439 | req->in.h.opcode = FUSE_GETXATTR; |
| 1440 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1441 | req->in.numargs = 2; |
| 1442 | req->in.args[0].size = sizeof(inarg); |
| 1443 | req->in.args[0].value = &inarg; |
| 1444 | req->in.args[1].size = strlen(name) + 1; |
| 1445 | req->in.args[1].value = name; |
| 1446 | /* This is really two different operations rolled into one */ |
| 1447 | req->out.numargs = 1; |
| 1448 | if (size) { |
| 1449 | req->out.argvar = 1; |
| 1450 | req->out.args[0].size = size; |
| 1451 | req->out.args[0].value = value; |
| 1452 | } else { |
| 1453 | req->out.args[0].size = sizeof(outarg); |
| 1454 | req->out.args[0].value = &outarg; |
| 1455 | } |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1456 | fuse_request_send(fc, req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1457 | ret = req->out.h.error; |
| 1458 | if (!ret) |
| 1459 | ret = size ? req->out.args[0].size : outarg.size; |
| 1460 | else { |
| 1461 | if (ret == -ENOSYS) { |
| 1462 | fc->no_getxattr = 1; |
| 1463 | ret = -EOPNOTSUPP; |
| 1464 | } |
| 1465 | } |
| 1466 | fuse_put_request(fc, req); |
| 1467 | return ret; |
| 1468 | } |
| 1469 | |
| 1470 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 1471 | { |
| 1472 | struct inode *inode = entry->d_inode; |
| 1473 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1474 | struct fuse_req *req; |
| 1475 | struct fuse_getxattr_in inarg; |
| 1476 | struct fuse_getxattr_out outarg; |
| 1477 | ssize_t ret; |
| 1478 | |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 1479 | if (!fuse_allow_task(fc, current)) |
| 1480 | return -EACCES; |
| 1481 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1482 | if (fc->no_listxattr) |
| 1483 | return -EOPNOTSUPP; |
| 1484 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1485 | req = fuse_get_req(fc); |
| 1486 | if (IS_ERR(req)) |
| 1487 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1488 | |
| 1489 | memset(&inarg, 0, sizeof(inarg)); |
| 1490 | inarg.size = size; |
| 1491 | req->in.h.opcode = FUSE_LISTXATTR; |
| 1492 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1493 | req->in.numargs = 1; |
| 1494 | req->in.args[0].size = sizeof(inarg); |
| 1495 | req->in.args[0].value = &inarg; |
| 1496 | /* This is really two different operations rolled into one */ |
| 1497 | req->out.numargs = 1; |
| 1498 | if (size) { |
| 1499 | req->out.argvar = 1; |
| 1500 | req->out.args[0].size = size; |
| 1501 | req->out.args[0].value = list; |
| 1502 | } else { |
| 1503 | req->out.args[0].size = sizeof(outarg); |
| 1504 | req->out.args[0].value = &outarg; |
| 1505 | } |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1506 | fuse_request_send(fc, req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1507 | ret = req->out.h.error; |
| 1508 | if (!ret) |
| 1509 | ret = size ? req->out.args[0].size : outarg.size; |
| 1510 | else { |
| 1511 | if (ret == -ENOSYS) { |
| 1512 | fc->no_listxattr = 1; |
| 1513 | ret = -EOPNOTSUPP; |
| 1514 | } |
| 1515 | } |
| 1516 | fuse_put_request(fc, req); |
| 1517 | return ret; |
| 1518 | } |
| 1519 | |
| 1520 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 1521 | { |
| 1522 | struct inode *inode = entry->d_inode; |
| 1523 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 1524 | struct fuse_req *req; |
| 1525 | int err; |
| 1526 | |
| 1527 | if (fc->no_removexattr) |
| 1528 | return -EOPNOTSUPP; |
| 1529 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 1530 | req = fuse_get_req(fc); |
| 1531 | if (IS_ERR(req)) |
| 1532 | return PTR_ERR(req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1533 | |
| 1534 | req->in.h.opcode = FUSE_REMOVEXATTR; |
| 1535 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1536 | req->in.numargs = 1; |
| 1537 | req->in.args[0].size = strlen(name) + 1; |
| 1538 | req->in.args[0].value = name; |
Tejun Heo | b93f858 | 2008-11-26 12:03:55 +0100 | [diff] [blame] | 1539 | fuse_request_send(fc, req); |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1540 | err = req->out.h.error; |
| 1541 | fuse_put_request(fc, req); |
| 1542 | if (err == -ENOSYS) { |
| 1543 | fc->no_removexattr = 1; |
| 1544 | err = -EOPNOTSUPP; |
| 1545 | } |
| 1546 | return err; |
| 1547 | } |
| 1548 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1549 | static const struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1550 | .lookup = fuse_lookup, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1551 | .mkdir = fuse_mkdir, |
| 1552 | .symlink = fuse_symlink, |
| 1553 | .unlink = fuse_unlink, |
| 1554 | .rmdir = fuse_rmdir, |
| 1555 | .rename = fuse_rename, |
| 1556 | .link = fuse_link, |
| 1557 | .setattr = fuse_setattr, |
| 1558 | .create = fuse_create, |
| 1559 | .mknod = fuse_mknod, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1560 | .permission = fuse_permission, |
| 1561 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1562 | .setxattr = fuse_setxattr, |
| 1563 | .getxattr = fuse_getxattr, |
| 1564 | .listxattr = fuse_listxattr, |
| 1565 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1566 | }; |
| 1567 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 1568 | static const struct file_operations fuse_dir_operations = { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 1569 | .llseek = generic_file_llseek, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1570 | .read = generic_read_dir, |
| 1571 | .readdir = fuse_readdir, |
| 1572 | .open = fuse_dir_open, |
| 1573 | .release = fuse_dir_release, |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 1574 | .fsync = fuse_dir_fsync, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1575 | }; |
| 1576 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1577 | static const struct inode_operations fuse_common_inode_operations = { |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1578 | .setattr = fuse_setattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1579 | .permission = fuse_permission, |
| 1580 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1581 | .setxattr = fuse_setxattr, |
| 1582 | .getxattr = fuse_getxattr, |
| 1583 | .listxattr = fuse_listxattr, |
| 1584 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1585 | }; |
| 1586 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1587 | static const struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 1588 | .setattr = fuse_setattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1589 | .follow_link = fuse_follow_link, |
| 1590 | .put_link = fuse_put_link, |
| 1591 | .readlink = generic_readlink, |
| 1592 | .getattr = fuse_getattr, |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 1593 | .setxattr = fuse_setxattr, |
| 1594 | .getxattr = fuse_getxattr, |
| 1595 | .listxattr = fuse_listxattr, |
| 1596 | .removexattr = fuse_removexattr, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 1597 | }; |
| 1598 | |
| 1599 | void fuse_init_common(struct inode *inode) |
| 1600 | { |
| 1601 | inode->i_op = &fuse_common_inode_operations; |
| 1602 | } |
| 1603 | |
| 1604 | void fuse_init_dir(struct inode *inode) |
| 1605 | { |
| 1606 | inode->i_op = &fuse_dir_inode_operations; |
| 1607 | inode->i_fop = &fuse_dir_operations; |
| 1608 | } |
| 1609 | |
| 1610 | void fuse_init_symlink(struct inode *inode) |
| 1611 | { |
| 1612 | inode->i_op = &fuse_symlink_inode_operations; |
| 1613 | } |