Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2 | FUSE: Filesystem in Userspace |
| 3 | Copyright (C) 2001-2004 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 4 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 11 | #include <linux/pagemap.h> |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 12 | #include <linux/file.h> |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 13 | #ifdef KERNEL_2_6 |
| 14 | #include <linux/gfp.h> |
| 15 | #else |
| 16 | #include <linux/mm.h> |
| 17 | #endif |
| 18 | #include <linux/sched.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 19 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 20 | static struct inode_operations fuse_dir_inode_operations; |
| 21 | static struct inode_operations fuse_file_inode_operations; |
| 22 | static struct inode_operations fuse_symlink_inode_operations; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 23 | static struct file_operations fuse_dir_operations; |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 24 | static struct dentry_operations fuse_dentry_operations; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 25 | |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 26 | #ifndef KERNEL_2_6 |
| 27 | #define new_decode_dev(x) (x) |
| 28 | #define new_encode_dev(x) (x) |
| 29 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 30 | static void change_attributes(struct inode *inode, struct fuse_attr *attr) |
| 31 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 32 | if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 33 | #ifdef KERNEL_2_6 |
| 34 | invalidate_inode_pages(inode->i_mapping); |
| 35 | #else |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 36 | invalidate_inode_pages(inode); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 37 | #endif |
| 38 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 39 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 40 | inode->i_ino = attr->ino; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 41 | inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 42 | inode->i_nlink = attr->nlink; |
| 43 | inode->i_uid = attr->uid; |
| 44 | inode->i_gid = attr->gid; |
Miklos Szeredi | d1199f8 | 2004-02-06 15:29:22 +0000 | [diff] [blame] | 45 | i_size_write(inode, attr->size); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 46 | inode->i_blksize = PAGE_CACHE_SIZE; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 47 | inode->i_blocks = attr->blocks; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 48 | #ifdef KERNEL_2_6 |
| 49 | inode->i_atime.tv_sec = attr->atime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 50 | inode->i_atime.tv_nsec = attr->atimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 51 | inode->i_mtime.tv_sec = attr->mtime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 52 | inode->i_mtime.tv_nsec = attr->mtimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 53 | inode->i_ctime.tv_sec = attr->ctime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 54 | inode->i_ctime.tv_nsec = attr->ctimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 55 | #else |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 56 | inode->i_atime = attr->atime; |
| 57 | inode->i_mtime = attr->mtime; |
| 58 | inode->i_ctime = attr->ctime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 59 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 62 | static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 63 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 64 | inode->i_mode = attr->mode & S_IFMT; |
Miklos Szeredi | d1199f8 | 2004-02-06 15:29:22 +0000 | [diff] [blame] | 65 | i_size_write(inode, attr->size); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 66 | if (S_ISREG(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 67 | inode->i_op = &fuse_file_inode_operations; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 68 | fuse_init_file_inode(inode); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 69 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 70 | else if (S_ISDIR(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 71 | inode->i_op = &fuse_dir_inode_operations; |
| 72 | inode->i_fop = &fuse_dir_operations; |
| 73 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 74 | else if (S_ISLNK(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 75 | inode->i_op = &fuse_symlink_inode_operations; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 76 | } |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 77 | else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 78 | S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 79 | inode->i_op = &fuse_file_inode_operations; |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 80 | init_special_inode(inode, inode->i_mode, |
| 81 | new_decode_dev(attr->rdev)); |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 82 | } else { |
| 83 | /* Don't let user create weird files */ |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 84 | inode->i_mode = S_IFREG; |
| 85 | inode->i_op = &fuse_file_inode_operations; |
| 86 | fuse_init_file_inode(inode); |
| 87 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 90 | #ifdef KERNEL_2_6 |
| 91 | static int fuse_inode_eq(struct inode *inode, void *_nodeidp) |
| 92 | { |
| 93 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 94 | if (get_node_id(inode) == nodeid) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 95 | return 1; |
| 96 | else |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int fuse_inode_set(struct inode *inode, void *_nodeidp) |
| 101 | { |
| 102 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 103 | get_fuse_inode(inode)->nodeid = nodeid; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
| 108 | int generation, struct fuse_attr *attr, int version) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 109 | { |
| 110 | struct inode *inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 111 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 112 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 113 | inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid); |
| 114 | if (!inode) |
| 115 | return NULL; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 116 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 117 | if ((inode->i_state & I_NEW)) { |
| 118 | inode->i_generation = generation; |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 119 | inode->i_data.backing_dev_info = &fc->bdi; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 120 | fuse_init_inode(inode, attr); |
| 121 | unlock_new_inode(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 122 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 123 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 124 | change_attributes(inode, attr); |
| 125 | inode->i_version = version; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 126 | return inode; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 129 | struct inode *fuse_ilookup(struct super_block *sb, unsigned long nodeid) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 130 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 131 | return ilookup5(sb, nodeid, fuse_inode_eq, &nodeid); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 132 | } |
| 133 | #else |
| 134 | static int fuse_inode_eq(struct inode *inode, unsigned long ino, void *_nodeidp){ |
| 135 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 136 | if (inode->u.generic_ip && get_node_id(inode) == nodeid) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 137 | return 1; |
| 138 | else |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
| 143 | int generation, struct fuse_attr *attr, int version) |
| 144 | { |
| 145 | struct inode *inode; |
| 146 | |
| 147 | inode = iget4(sb, attr->ino, fuse_inode_eq, &nodeid); |
| 148 | if (!inode) |
| 149 | return NULL; |
| 150 | |
| 151 | if (!inode->u.generic_ip) { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 152 | get_fuse_inode(inode)->nodeid = nodeid; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 153 | inode->u.generic_ip = inode; |
| 154 | inode->i_generation = generation; |
| 155 | fuse_init_inode(inode, attr); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 156 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 157 | |
| 158 | change_attributes(inode, attr); |
| 159 | inode->i_version = version; |
| 160 | return inode; |
| 161 | } |
| 162 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 163 | struct inode *fuse_ilookup(struct super_block *sb, ino_t ino, unsigned long nodeid) |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 164 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 165 | struct inode *inode = iget4(sb, ino, fuse_inode_eq, &nodeid); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 166 | if (inode && !inode->u.generic_ip) { |
| 167 | iput(inode); |
| 168 | inode = NULL; |
| 169 | } |
| 170 | return inode; |
| 171 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 172 | #endif |
| 173 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 174 | static void fuse_lookup_init(struct fuse_req *req, struct inode *dir, |
| 175 | struct dentry *entry, |
| 176 | struct fuse_entry_out *outarg) |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 177 | { |
| 178 | req->in.h.opcode = FUSE_LOOKUP; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 179 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 180 | req->in.numargs = 1; |
| 181 | req->in.args[0].size = entry->d_name.len + 1; |
| 182 | req->in.args[0].value = entry->d_name.name; |
| 183 | req->out.numargs = 1; |
| 184 | req->out.args[0].size = sizeof(struct fuse_entry_out); |
| 185 | req->out.args[0].value = outarg; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 188 | static inline unsigned long time_to_jiffies(unsigned long sec, |
| 189 | unsigned long nsec) |
| 190 | { |
| 191 | /* prevent wrapping of jiffies */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 192 | if (sec + 1 >= LONG_MAX / HZ) |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 193 | return 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 194 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 195 | return jiffies + sec * HZ + nsec / (1000000000 / HZ); |
| 196 | } |
| 197 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 198 | static int fuse_lookup_iget(struct inode *dir, struct dentry *entry, |
| 199 | struct inode **inodep) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 200 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 201 | int err; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 202 | int version; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 203 | struct fuse_entry_out outarg; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 204 | struct inode *inode = NULL; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 205 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 206 | struct fuse_req *req; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 207 | |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 208 | if (entry->d_name.len > FUSE_NAME_MAX) |
| 209 | return -ENAMETOOLONG; |
| 210 | req = fuse_get_request(fc); |
| 211 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 212 | return -ERESTARTNOINTR; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 213 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 214 | fuse_lookup_init(req, dir, entry, &outarg); |
| 215 | request_send(fc, req); |
| 216 | version = req->out.h.unique; |
| 217 | err = req->out.h.error; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 218 | if (!err) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 219 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 220 | &outarg.attr, version); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 221 | if (!inode) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 222 | fuse_send_forget(fc, req, outarg.nodeid, version); |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 223 | return -ENOMEM; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 224 | } |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 225 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 226 | fuse_put_request(fc, req); |
| 227 | if (err && err != -ENOENT) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 228 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 229 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 230 | if (inode) { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 231 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 232 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 233 | outarg.entry_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 234 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 235 | outarg.attr_valid_nsec); |
| 236 | } |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 237 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 238 | entry->d_op = &fuse_dentry_operations; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 239 | *inodep = inode; |
| 240 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 243 | void fuse_invalidate_attr(struct inode *inode) |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 244 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 245 | get_fuse_inode(inode)->i_time = jiffies - 1; |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 248 | static void fuse_invalidate_entry(struct dentry *entry) |
| 249 | { |
| 250 | d_invalidate(entry); |
| 251 | entry->d_time = jiffies - 1; |
| 252 | } |
| 253 | |
| 254 | static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 255 | struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 256 | int mode) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 257 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 258 | struct fuse_entry_out outarg; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 259 | struct inode *inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 260 | struct fuse_inode *fi; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 261 | int version; |
| 262 | int err; |
| 263 | |
| 264 | req->in.h.nodeid = get_node_id(dir); |
| 265 | req->out.numargs = 1; |
| 266 | req->out.args[0].size = sizeof(outarg); |
| 267 | req->out.args[0].value = &outarg; |
| 268 | request_send(fc, req); |
| 269 | version = req->out.h.unique; |
| 270 | err = req->out.h.error; |
| 271 | if (err) { |
| 272 | fuse_put_request(fc, req); |
| 273 | return err; |
| 274 | } |
| 275 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
| 276 | &outarg.attr, version); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 277 | if (!inode) { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 278 | fuse_send_forget(fc, req, outarg.nodeid, version); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 279 | return -ENOMEM; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 280 | } |
| 281 | fuse_put_request(fc, req); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 282 | |
| 283 | /* Don't allow userspace to do really stupid things... */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 284 | if ((inode->i_mode ^ mode) & S_IFMT) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 285 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 286 | return -EIO; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 289 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 290 | outarg.entry_valid_nsec); |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 291 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 292 | fi = get_fuse_inode(inode); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 293 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 294 | outarg.attr_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 295 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 296 | d_instantiate(entry, inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 297 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 301 | static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 302 | dev_t rdev) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 303 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 304 | struct fuse_mknod_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 305 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 306 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 307 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 308 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 309 | |
| 310 | memset(&inarg, 0, sizeof(inarg)); |
| 311 | inarg.mode = mode; |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 312 | inarg.rdev = new_encode_dev(rdev); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 313 | req->in.h.opcode = FUSE_MKNOD; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 314 | req->in.numargs = 2; |
| 315 | req->in.args[0].size = sizeof(inarg); |
| 316 | req->in.args[0].value = &inarg; |
| 317 | req->in.args[1].size = entry->d_name.len + 1; |
| 318 | req->in.args[1].value = entry->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 319 | return create_new_entry(fc, req, dir, entry, mode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 322 | static int fuse_create(struct inode *dir, struct dentry *entry, int mode, |
| 323 | struct nameidata *nd) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 324 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 325 | return fuse_mknod(dir, entry, mode, 0); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 328 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) |
| 329 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 330 | struct fuse_mkdir_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 331 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 332 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 333 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 334 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 335 | |
| 336 | memset(&inarg, 0, sizeof(inarg)); |
| 337 | inarg.mode = mode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 338 | req->in.h.opcode = FUSE_MKDIR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 339 | req->in.numargs = 2; |
| 340 | req->in.args[0].size = sizeof(inarg); |
| 341 | req->in.args[0].value = &inarg; |
| 342 | req->in.args[1].size = entry->d_name.len + 1; |
| 343 | req->in.args[1].value = entry->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 344 | return create_new_entry(fc, req, dir, entry, S_IFDIR); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
| 348 | const char *link) |
| 349 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 350 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 351 | unsigned len = strlen(link) + 1; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 352 | struct fuse_req *req; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 353 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 354 | if (len > FUSE_SYMLINK_MAX) |
| 355 | return -ENAMETOOLONG; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 356 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 357 | req = fuse_get_request(fc); |
| 358 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 359 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 360 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 361 | req->in.h.opcode = FUSE_SYMLINK; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 362 | req->in.numargs = 2; |
| 363 | req->in.args[0].size = entry->d_name.len + 1; |
| 364 | req->in.args[0].value = entry->d_name.name; |
| 365 | req->in.args[1].size = len; |
| 366 | req->in.args[1].value = link; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 367 | return create_new_entry(fc, req, dir, entry, S_IFLNK); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 370 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 371 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 372 | int err; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 373 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 374 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 375 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 376 | return -ERESTARTNOINTR; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 377 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 378 | req->in.h.opcode = FUSE_UNLINK; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 379 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 380 | req->in.numargs = 1; |
| 381 | req->in.args[0].size = entry->d_name.len + 1; |
| 382 | req->in.args[0].value = entry->d_name.name; |
| 383 | request_send(fc, req); |
| 384 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 385 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 386 | if (!err) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 387 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 388 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 389 | /* Set nlink to zero so the inode can be cleared, if |
| 390 | the inode does have more links this will be |
| 391 | discovered at the next lookup/getattr */ |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 392 | inode->i_nlink = 0; |
| 393 | fuse_invalidate_attr(inode); |
| 394 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 395 | } else if (err == -EINTR) |
| 396 | fuse_invalidate_entry(entry); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 397 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
| 401 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 402 | int err; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 403 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 404 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 405 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 406 | return -ERESTARTNOINTR; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 407 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 408 | req->in.h.opcode = FUSE_RMDIR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 409 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 410 | req->in.numargs = 1; |
| 411 | req->in.args[0].size = entry->d_name.len + 1; |
| 412 | req->in.args[0].value = entry->d_name.name; |
| 413 | request_send(fc, req); |
| 414 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 415 | fuse_put_request(fc, req); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 416 | if (!err) { |
Miklos Szeredi | f4f8b89 | 2004-01-27 17:04:59 +0000 | [diff] [blame] | 417 | entry->d_inode->i_nlink = 0; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 418 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 419 | } else if (err == -EINTR) |
| 420 | fuse_invalidate_entry(entry); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 421 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static int fuse_rename(struct inode *olddir, struct dentry *oldent, |
| 425 | struct inode *newdir, struct dentry *newent) |
| 426 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 427 | int err; |
| 428 | struct fuse_rename_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 429 | struct fuse_conn *fc = get_fuse_conn(olddir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 430 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 431 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 432 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 433 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 434 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 435 | inarg.newdir = get_node_id(newdir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 436 | req->in.h.opcode = FUSE_RENAME; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 437 | req->in.h.nodeid = get_node_id(olddir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 438 | req->in.numargs = 3; |
| 439 | req->in.args[0].size = sizeof(inarg); |
| 440 | req->in.args[0].value = &inarg; |
| 441 | req->in.args[1].size = oldent->d_name.len + 1; |
| 442 | req->in.args[1].value = oldent->d_name.name; |
| 443 | req->in.args[2].size = newent->d_name.len + 1; |
| 444 | req->in.args[2].value = newent->d_name.name; |
| 445 | request_send(fc, req); |
| 446 | err = req->out.h.error; |
| 447 | fuse_put_request(fc, req); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 448 | if (!err) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 449 | fuse_invalidate_attr(olddir); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 450 | if (olddir != newdir) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 451 | fuse_invalidate_attr(newdir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 452 | } else if (err == -EINTR) { |
| 453 | /* If request was interrupted, DEITY only knows if the |
| 454 | rename actually took place. If the invalidation |
| 455 | fails (e.g. some process has CWD under the renamed |
| 456 | directory), then there can be inconsistency between |
| 457 | the dcache and the real filesystem. But not a lot |
| 458 | can be done about that */ |
| 459 | fuse_invalidate_entry(oldent); |
| 460 | if (newent->d_inode) |
| 461 | fuse_invalidate_entry(newent); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 462 | } |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 463 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 464 | return err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static int fuse_link(struct dentry *entry, struct inode *newdir, |
| 468 | struct dentry *newent) |
| 469 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 470 | int err; |
| 471 | struct fuse_link_in inarg; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 472 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 473 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 474 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 475 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 476 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 477 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 478 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 479 | inarg.newdir = get_node_id(newdir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 480 | req->in.h.opcode = FUSE_LINK; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 481 | req->in.numargs = 2; |
| 482 | req->in.args[0].size = sizeof(inarg); |
| 483 | req->in.args[0].value = &inarg; |
| 484 | req->in.args[1].size = newent->d_name.len + 1; |
| 485 | req->in.args[1].value = newent->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 486 | err = create_new_entry(fc, req, newdir, newent, inode->i_mode); |
| 487 | /* Contrary to "normal" filesystems it can happen that link |
| 488 | makes two "logical" inodes point to the same "physical" |
| 489 | inode. We invalidate the attributes of the old one, so it |
| 490 | will reflect changes in the backing inode (link count, |
| 491 | etc.) |
| 492 | */ |
| 493 | if (!err || err == -EINTR) |
| 494 | fuse_invalidate_attr(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 495 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 498 | int fuse_do_getattr(struct inode *inode) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 499 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 500 | int err; |
| 501 | struct fuse_attr_out arg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 502 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 503 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 504 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 505 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 506 | |
| 507 | req->in.h.opcode = FUSE_GETATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 508 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 509 | req->out.numargs = 1; |
| 510 | req->out.args[0].size = sizeof(arg); |
| 511 | req->out.args[0].value = &arg; |
| 512 | request_send(fc, req); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 513 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 514 | fuse_put_request(fc, req); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 515 | if (!err) { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 516 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 517 | change_attributes(inode, &arg.attr); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 518 | fi->i_time = time_to_jiffies(arg.attr_valid, |
| 519 | arg.attr_valid_nsec); |
| 520 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 521 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 524 | static int fuse_revalidate(struct dentry *entry) |
| 525 | { |
| 526 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 527 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 528 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 529 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 530 | if (get_node_id(inode) == FUSE_ROOT_ID) { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 531 | if (!(fc->flags & FUSE_ALLOW_OTHER) && |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 532 | current->fsuid != fc->uid && |
| 533 | (!(fc->flags & FUSE_ALLOW_ROOT) || |
| 534 | current->fsuid != 0)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 535 | return -EACCES; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 536 | } else if (!fi->i_time || time_before_eq(jiffies, fi->i_time)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 537 | return 0; |
| 538 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 539 | return fuse_do_getattr(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 542 | static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 543 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 544 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 545 | |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 546 | if (!(fc->flags & FUSE_ALLOW_OTHER) && current->fsuid != fc->uid && |
| 547 | (!(fc->flags & FUSE_ALLOW_ROOT) || current->fsuid != 0)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 548 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 549 | else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 550 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 551 | int err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 552 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 553 | int err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 554 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 555 | |
| 556 | /* If permission is denied, try to refresh file |
| 557 | attributes. This is also needed, because the root |
| 558 | node will at first have no permissions */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 559 | if (err == -EACCES) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 560 | err = fuse_do_getattr(inode); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 561 | if (!err) |
| 562 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 563 | err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 564 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 565 | err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 566 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* FIXME: Need some mechanism to revoke permissions: |
| 570 | currently if the filesystem suddenly changes the |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 571 | file mode, we will not be informed about it, and |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 572 | continue to allow access to the file/directory. |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 573 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 574 | This is actually not so grave, since the user can |
| 575 | simply keep access to the file/directory anyway by |
| 576 | keeping it open... */ |
| 577 | |
| 578 | return err; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 579 | } else { |
| 580 | int mode = inode->i_mode; |
| 581 | if ((mask & MAY_WRITE) && IS_RDONLY(inode) && |
| 582 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) |
| 583 | return -EROFS; |
| 584 | if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO)) |
| 585 | return -EACCES; |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 586 | return 0; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 587 | } |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 590 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 591 | void *dstbuf, filldir_t filldir) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 592 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 593 | while (nbytes >= FUSE_NAME_OFFSET) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 594 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 595 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 596 | int over; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 597 | if (dirent->namelen > NAME_MAX) |
| 598 | return -EIO; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 599 | if (reclen > nbytes) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 600 | break; |
| 601 | |
| 602 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 603 | file->f_pos, dirent->ino, dirent->type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 604 | if (over) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 605 | break; |
| 606 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 607 | buf += reclen; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 608 | file->f_pos += reclen; |
| 609 | nbytes -= reclen; |
| 610 | } |
| 611 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 612 | return 0; |
| 613 | } |
| 614 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 615 | static int fuse_checkdir(struct file *cfile, struct file *file) |
| 616 | { |
| 617 | struct inode *inode; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 618 | if (!cfile) |
| 619 | return -EIO; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 620 | inode = cfile->f_dentry->d_inode; |
| 621 | if (!S_ISREG(inode->i_mode)) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 622 | fput(cfile); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 623 | return -EIO; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 624 | } |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 625 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 626 | file->private_data = cfile; |
| 627 | return 0; |
| 628 | } |
| 629 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 630 | static int fuse_getdir(struct file *file) |
| 631 | { |
| 632 | struct inode *inode = file->f_dentry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 633 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 634 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 635 | struct fuse_getdir_out_i outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 636 | int err; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 637 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 638 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 639 | return -ERESTARTNOINTR; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 640 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 641 | req->in.h.opcode = FUSE_GETDIR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 642 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 643 | req->out.numargs = 1; |
| 644 | req->out.args[0].size = sizeof(struct fuse_getdir_out); |
| 645 | req->out.args[0].value = &outarg; |
| 646 | request_send(fc, req); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 647 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 648 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 649 | if (!err) |
| 650 | err = fuse_checkdir(outarg.file, file); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 651 | return err; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 654 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 655 | { |
| 656 | struct file *cfile = file->private_data; |
| 657 | char *buf; |
| 658 | int ret; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 659 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 660 | if (!cfile) { |
| 661 | ret = fuse_getdir(file); |
| 662 | if (ret) |
| 663 | return ret; |
| 664 | |
| 665 | cfile = file->private_data; |
| 666 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 667 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 668 | buf = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 669 | if (!buf) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 670 | return -ENOMEM; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 671 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 672 | ret = kernel_read(cfile, file->f_pos, buf, PAGE_SIZE); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 673 | if (ret > 0) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 674 | ret = parse_dirfile(buf, ret, file, dstbuf, filldir); |
| 675 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 676 | free_page((unsigned long) buf); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 677 | return ret; |
| 678 | } |
| 679 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 680 | static char *read_link(struct dentry *dentry) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 681 | { |
| 682 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 683 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 684 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 685 | char *link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 686 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 687 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 688 | return ERR_PTR(-ERESTARTNOINTR); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 689 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 690 | link = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 691 | if (!link) { |
| 692 | link = ERR_PTR(-ENOMEM); |
| 693 | goto out; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 694 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 695 | req->in.h.opcode = FUSE_READLINK; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 696 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 697 | req->out.argvar = 1; |
| 698 | req->out.numargs = 1; |
| 699 | req->out.args[0].size = PAGE_SIZE - 1; |
| 700 | req->out.args[0].value = link; |
| 701 | request_send(fc, req); |
| 702 | if (req->out.h.error) { |
| 703 | free_page((unsigned long) link); |
| 704 | link = ERR_PTR(req->out.h.error); |
| 705 | } else |
| 706 | link[req->out.args[0].size] = '\0'; |
| 707 | out: |
| 708 | fuse_put_request(fc, req); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 709 | return link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void free_link(char *link) |
| 713 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 714 | if (!IS_ERR(link)) |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 715 | free_page((unsigned long) link); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 718 | static int fuse_readlink(struct dentry *dentry, char __user *buffer, |
| 719 | int buflen) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 720 | { |
| 721 | int ret; |
| 722 | char *link; |
| 723 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 724 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 725 | ret = vfs_readlink(dentry, buffer, buflen, link); |
| 726 | free_link(link); |
| 727 | return ret; |
| 728 | } |
| 729 | |
| 730 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 731 | { |
| 732 | int ret; |
| 733 | char *link; |
| 734 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 735 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 736 | ret = vfs_follow_link(nd, link); |
| 737 | free_link(link); |
| 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 742 | { |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 743 | file->private_data = NULL; |
| 744 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 748 | { |
| 749 | struct file *cfile = file->private_data; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 750 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 751 | if (cfile) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 752 | fput(cfile); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 757 | static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 758 | { |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 759 | unsigned ivalid = iattr->ia_valid; |
| 760 | unsigned fvalid = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 761 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 762 | memset(fattr, 0, sizeof(*fattr)); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 763 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 764 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 765 | fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 766 | if (ivalid & ATTR_UID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 767 | fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 768 | if (ivalid & ATTR_GID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 769 | fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 770 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 771 | fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size; |
| 772 | /* You can only _set_ these together (they may change by themselves) */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 773 | if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 774 | fvalid |= FATTR_ATIME | FATTR_MTIME; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 775 | #ifdef KERNEL_2_6 |
| 776 | fattr->atime = iattr->ia_atime.tv_sec; |
| 777 | fattr->mtime = iattr->ia_mtime.tv_sec; |
| 778 | #else |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 779 | fattr->atime = iattr->ia_atime; |
| 780 | fattr->mtime = iattr->ia_mtime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 781 | #endif |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | return fvalid; |
| 785 | } |
| 786 | |
| 787 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 788 | { |
| 789 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 790 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 791 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 792 | struct fuse_req *req; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 793 | struct fuse_setattr_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 794 | struct fuse_attr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 795 | int err; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 796 | int is_truncate = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 797 | |
Miklos Szeredi | 94ed76a | 2004-07-26 19:38:45 +0000 | [diff] [blame] | 798 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
| 799 | err = inode_change_ok(inode, attr); |
| 800 | if (err) |
| 801 | return err; |
| 802 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 803 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 804 | if (attr->ia_valid & ATTR_SIZE) { |
| 805 | unsigned long limit; |
| 806 | is_truncate = 1; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 807 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 808 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 809 | #else |
| 810 | limit = current->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 811 | #endif |
| 812 | if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 813 | send_sig(SIGXFSZ, current, 0); |
| 814 | return -EFBIG; |
| 815 | } |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 816 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 817 | |
| 818 | req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 819 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 820 | return -ERESTARTNOINTR; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 821 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 822 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 823 | inarg.valid = iattr_to_fattr(attr, &inarg.attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 824 | req->in.h.opcode = FUSE_SETATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 825 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 826 | req->in.numargs = 1; |
| 827 | req->in.args[0].size = sizeof(inarg); |
| 828 | req->in.args[0].value = &inarg; |
| 829 | req->out.numargs = 1; |
| 830 | req->out.args[0].size = sizeof(outarg); |
| 831 | req->out.args[0].value = &outarg; |
| 832 | request_send(fc, req); |
| 833 | err = req->out.h.error; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 834 | fuse_put_request(fc, req); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 835 | if (!err) { |
| 836 | if (is_truncate) { |
| 837 | loff_t origsize = i_size_read(inode); |
| 838 | i_size_write(inode, outarg.attr.size); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 839 | if (origsize > outarg.attr.size) |
| 840 | vmtruncate(inode, outarg.attr.size); |
| 841 | } |
| 842 | change_attributes(inode, &outarg.attr); |
| 843 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 844 | outarg.attr_valid_nsec); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 845 | } else if (err == -EINTR) |
| 846 | fuse_invalidate_attr(inode); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 847 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 848 | return err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 851 | static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 852 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 853 | if (!entry->d_inode) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 854 | return 0; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 855 | else if (entry->d_time && time_after(jiffies, entry->d_time)) { |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 856 | int err; |
| 857 | int version; |
| 858 | struct fuse_entry_out outarg; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 859 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 860 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 861 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 862 | struct fuse_req *req = fuse_get_request_nonint(fc); |
| 863 | if (!req) |
| 864 | return 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 865 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 866 | fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg); |
| 867 | request_send_nonint(fc, req, 0); |
| 868 | version = req->out.h.unique; |
| 869 | err = req->out.h.error; |
| 870 | fuse_put_request(fc, req); |
| 871 | if (err) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 872 | return 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 873 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 874 | if (outarg.nodeid != get_node_id(inode)) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 875 | return 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 876 | |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 877 | change_attributes(inode, &outarg.attr); |
| 878 | inode->i_version = version; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 879 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 880 | outarg.entry_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 881 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 882 | outarg.attr_valid_nsec); |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 883 | } |
| 884 | return 1; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 887 | #ifdef KERNEL_2_6 |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 888 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 889 | struct kstat *stat) |
| 890 | { |
| 891 | struct inode *inode = entry->d_inode; |
| 892 | int err = fuse_revalidate(entry); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 893 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 894 | generic_fillattr(inode, stat); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 895 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 896 | return err; |
| 897 | } |
| 898 | |
| 899 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 900 | struct nameidata *nd) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 901 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 902 | struct inode *inode; |
| 903 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 904 | if (err) |
| 905 | return ERR_PTR(err); |
| 906 | return d_splice_alias(inode, entry); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 907 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 908 | #else /* KERNEL_2_6 */ |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 909 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry) |
| 910 | { |
| 911 | struct inode *inode; |
| 912 | struct dentry *alias; |
| 913 | |
| 914 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 915 | if (err) |
| 916 | return ERR_PTR(err); |
| 917 | |
| 918 | if (inode && S_ISDIR(inode->i_mode) && |
| 919 | (alias = d_find_alias(inode)) != NULL) { |
| 920 | dput(alias); |
| 921 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 922 | return ERR_PTR(-EIO); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | d_add(entry, inode); |
| 926 | return NULL; |
| 927 | } |
| 928 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 929 | static int fuse_mknod_2_4(struct inode *dir, struct dentry *entry, int mode, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 930 | int rdev) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 931 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 932 | return fuse_mknod(dir, entry, mode, rdev); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 935 | static int fuse_dentry_revalidate_2_4(struct dentry *entry, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 936 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 937 | return fuse_dentry_revalidate(entry, NULL); |
| 938 | } |
| 939 | |
| 940 | static int fuse_create_2_4(struct inode *dir, struct dentry *entry, int mode) |
| 941 | { |
| 942 | return fuse_create(dir, entry, mode, NULL); |
| 943 | } |
| 944 | |
| 945 | static int fuse_permission_2_4(struct inode *inode, int mask) |
| 946 | { |
| 947 | return fuse_permission(inode, mask, NULL); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 948 | } |
| 949 | #endif /* KERNEL_2_6 */ |
| 950 | |
| 951 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 952 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 953 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 954 | const void *value, size_t size, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 955 | #else |
| 956 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 957 | void *value, size_t size, int flags) |
| 958 | #endif |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 959 | { |
| 960 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 961 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 962 | struct fuse_req *req; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 963 | struct fuse_setxattr_in inarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 964 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 965 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 966 | if (size > FUSE_XATTR_SIZE_MAX) |
| 967 | return -E2BIG; |
| 968 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 969 | if (fc->no_setxattr) |
| 970 | return -EOPNOTSUPP; |
| 971 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 972 | req = fuse_get_request(fc); |
| 973 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 974 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 975 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 976 | memset(&inarg, 0, sizeof(inarg)); |
| 977 | inarg.size = size; |
| 978 | inarg.flags = flags; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 979 | req->in.h.opcode = FUSE_SETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 980 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 981 | req->in.numargs = 3; |
| 982 | req->in.args[0].size = sizeof(inarg); |
| 983 | req->in.args[0].value = &inarg; |
| 984 | req->in.args[1].size = strlen(name) + 1; |
| 985 | req->in.args[1].value = name; |
| 986 | req->in.args[2].size = size; |
| 987 | req->in.args[2].value = value; |
| 988 | request_send(fc, req); |
| 989 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 990 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 991 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 992 | fc->no_setxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 993 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 994 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 995 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 999 | void *value, size_t size) |
| 1000 | { |
| 1001 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1002 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1003 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1004 | struct fuse_getxattr_in inarg; |
| 1005 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1006 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1007 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1008 | if (fc->no_getxattr) |
| 1009 | return -EOPNOTSUPP; |
| 1010 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1011 | req = fuse_get_request(fc); |
| 1012 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1013 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1014 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1015 | memset(&inarg, 0, sizeof(inarg)); |
| 1016 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1017 | req->in.h.opcode = FUSE_GETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1018 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1019 | req->in.numargs = 2; |
| 1020 | req->in.args[0].size = sizeof(inarg); |
| 1021 | req->in.args[0].value = &inarg; |
| 1022 | req->in.args[1].size = strlen(name) + 1; |
| 1023 | req->in.args[1].value = name; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1024 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1025 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 1026 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1027 | req->out.argvar = 1; |
| 1028 | req->out.args[0].size = size; |
| 1029 | req->out.args[0].value = value; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1030 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1031 | req->out.args[0].size = sizeof(outarg); |
| 1032 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1033 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1034 | request_send(fc, req); |
| 1035 | ret = req->out.h.error; |
| 1036 | if (!ret) |
| 1037 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1038 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1039 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1040 | fc->no_getxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1041 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1042 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1043 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1044 | fuse_put_request(fc, req); |
| 1045 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 1049 | { |
| 1050 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1051 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1052 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1053 | struct fuse_getxattr_in inarg; |
| 1054 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1055 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1056 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1057 | if (fc->no_listxattr) |
| 1058 | return -EOPNOTSUPP; |
| 1059 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1060 | req = fuse_get_request(fc); |
| 1061 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1062 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1063 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1064 | memset(&inarg, 0, sizeof(inarg)); |
| 1065 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1066 | req->in.h.opcode = FUSE_LISTXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1067 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1068 | req->in.numargs = 1; |
| 1069 | req->in.args[0].size = sizeof(inarg); |
| 1070 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1071 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1072 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 1073 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1074 | req->out.argvar = 1; |
| 1075 | req->out.args[0].size = size; |
| 1076 | req->out.args[0].value = list; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1077 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1078 | req->out.args[0].size = sizeof(outarg); |
| 1079 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 1080 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1081 | request_send(fc, req); |
| 1082 | ret = req->out.h.error; |
| 1083 | if (!ret) |
| 1084 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1085 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1086 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1087 | fc->no_listxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1088 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1089 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1090 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1091 | fuse_put_request(fc, req); |
| 1092 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 1096 | { |
| 1097 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1098 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1099 | struct fuse_req *req; |
| 1100 | int err; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 1101 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1102 | if (fc->no_removexattr) |
| 1103 | return -EOPNOTSUPP; |
| 1104 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1105 | req = fuse_get_request(fc); |
| 1106 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1107 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1108 | |
| 1109 | req->in.h.opcode = FUSE_REMOVEXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1110 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1111 | req->in.numargs = 1; |
| 1112 | req->in.args[0].size = strlen(name) + 1; |
| 1113 | req->in.args[0].value = name; |
| 1114 | request_send(fc, req); |
| 1115 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame^] | 1116 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1117 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1118 | fc->no_removexattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1119 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1120 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1121 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1122 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1123 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1124 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1125 | static struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1126 | .lookup = fuse_lookup, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1127 | .mkdir = fuse_mkdir, |
| 1128 | .symlink = fuse_symlink, |
| 1129 | .unlink = fuse_unlink, |
| 1130 | .rmdir = fuse_rmdir, |
| 1131 | .rename = fuse_rename, |
| 1132 | .link = fuse_link, |
| 1133 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1134 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1135 | .create = fuse_create, |
| 1136 | .mknod = fuse_mknod, |
| 1137 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1138 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1139 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1140 | .create = fuse_create_2_4, |
| 1141 | .mknod = fuse_mknod_2_4, |
| 1142 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1143 | .revalidate = fuse_revalidate, |
| 1144 | #endif |
| 1145 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1146 | .setxattr = fuse_setxattr, |
| 1147 | .getxattr = fuse_getxattr, |
| 1148 | .listxattr = fuse_listxattr, |
| 1149 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1150 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1151 | }; |
| 1152 | |
| 1153 | static struct file_operations fuse_dir_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1154 | .read = generic_read_dir, |
| 1155 | .readdir = fuse_readdir, |
| 1156 | .open = fuse_dir_open, |
| 1157 | .release = fuse_dir_release, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1158 | }; |
| 1159 | |
| 1160 | static struct inode_operations fuse_file_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1161 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1162 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1163 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1164 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1165 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1166 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1167 | .revalidate = fuse_revalidate, |
| 1168 | #endif |
| 1169 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1170 | .setxattr = fuse_setxattr, |
| 1171 | .getxattr = fuse_getxattr, |
| 1172 | .listxattr = fuse_listxattr, |
| 1173 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1174 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1175 | }; |
| 1176 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1177 | static struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1178 | .setattr = fuse_setattr, |
| 1179 | .readlink = fuse_readlink, |
| 1180 | .follow_link = fuse_follow_link, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1181 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1182 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1183 | #else |
| 1184 | .revalidate = fuse_revalidate, |
| 1185 | #endif |
| 1186 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1187 | .setxattr = fuse_setxattr, |
| 1188 | .getxattr = fuse_getxattr, |
| 1189 | .listxattr = fuse_listxattr, |
| 1190 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1191 | #endif |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1192 | }; |
| 1193 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 1194 | static struct dentry_operations fuse_dentry_operations = { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1195 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1196 | .d_revalidate = fuse_dentry_revalidate, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1197 | #else |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 1198 | .d_revalidate = fuse_dentry_revalidate_2_4, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1199 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1200 | }; |