Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/reiserfs/xattr.c |
| 3 | * |
| 4 | * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * In order to implement EA/ACLs in a clean, backwards compatible manner, |
| 10 | * they are implemented as files in a "private" directory. |
| 11 | * Each EA is in it's own file, with the directory layout like so (/ is assumed |
| 12 | * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory, |
| 13 | * directories named using the capital-hex form of the objectid and |
| 14 | * generation number are used. Inside each directory are individual files |
| 15 | * named with the name of the extended attribute. |
| 16 | * |
| 17 | * So, for objectid 12648430, we could have: |
| 18 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access |
| 19 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default |
| 20 | * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type |
| 21 | * .. or similar. |
| 22 | * |
| 23 | * The file contents are the text of the EA. The size is known based on the |
| 24 | * stat data describing the file. |
| 25 | * |
| 26 | * In the case of system.posix_acl_access and system.posix_acl_default, since |
| 27 | * these are special cases for filesystem ACLs, they are interpreted by the |
| 28 | * kernel, in addition, they are negatively and positively cached and attached |
| 29 | * to the inode so that unnecessary lookups are avoided. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/reiserfs_fs.h> |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 33 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/dcache.h> |
| 35 | #include <linux/namei.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/fs.h> |
| 38 | #include <linux/file.h> |
| 39 | #include <linux/pagemap.h> |
| 40 | #include <linux/xattr.h> |
| 41 | #include <linux/reiserfs_xattr.h> |
| 42 | #include <linux/reiserfs_acl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/uaccess.h> |
Al Viro | 3277c39 | 2006-11-14 21:13:53 -0800 | [diff] [blame] | 44 | #include <net/checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/smp_lock.h> |
| 46 | #include <linux/stat.h> |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 47 | #include <linux/quotaops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define PRIVROOT_NAME ".reiserfs_priv" |
| 50 | #define XAROOT_NAME "xattrs" |
| 51 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 52 | /* Helpers for inode ops. We do this so that we don't have all the VFS |
| 53 | * overhead and also for proper i_mutex annotation. |
| 54 | * dir->i_mutex must be held for all of them. */ |
| 55 | static int xattr_create(struct inode *dir, struct dentry *dentry, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 57 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
| 58 | DQUOT_INIT(dir); |
| 59 | return dir->i_op->create(dir, dentry, mode, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 62 | static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 63 | { |
| 64 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
| 65 | DQUOT_INIT(dir); |
| 66 | return dir->i_op->mkdir(dir, dentry, mode); |
| 67 | } |
| 68 | |
| 69 | /* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr |
| 70 | * mutation ops aren't called during rename or splace, which are the |
| 71 | * only other users of I_MUTEX_CHILD. It violates the ordering, but that's |
| 72 | * better than allocating another subclass just for this code. */ |
| 73 | static int xattr_unlink(struct inode *dir, struct dentry *dentry) |
| 74 | { |
| 75 | int error; |
| 76 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
| 77 | DQUOT_INIT(dir); |
| 78 | |
| 79 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); |
| 80 | error = dir->i_op->unlink(dir, dentry); |
| 81 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 82 | |
| 83 | if (!error) |
| 84 | d_delete(dentry); |
| 85 | return error; |
| 86 | } |
| 87 | |
| 88 | static int xattr_rmdir(struct inode *dir, struct dentry *dentry) |
| 89 | { |
| 90 | int error; |
| 91 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
| 92 | DQUOT_INIT(dir); |
| 93 | |
| 94 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); |
| 95 | dentry_unhash(dentry); |
| 96 | error = dir->i_op->rmdir(dir, dentry); |
| 97 | if (!error) |
| 98 | dentry->d_inode->i_flags |= S_DEAD; |
| 99 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 100 | if (!error) |
| 101 | d_delete(dentry); |
| 102 | dput(dentry); |
| 103 | |
| 104 | return error; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | #define xattr_may_create(flags) (!flags || flags & XATTR_CREATE) |
| 109 | |
| 110 | /* Returns and possibly creates the xattr dir. */ |
| 111 | static struct dentry *lookup_or_create_dir(struct dentry *parent, |
| 112 | const char *name, int flags) |
| 113 | { |
| 114 | struct dentry *dentry; |
| 115 | BUG_ON(!parent); |
| 116 | |
| 117 | dentry = lookup_one_len(name, parent, strlen(name)); |
| 118 | if (IS_ERR(dentry)) |
| 119 | return dentry; |
| 120 | else if (!dentry->d_inode) { |
| 121 | int err = -ENODATA; |
| 122 | |
| 123 | if (xattr_may_create(flags)) { |
| 124 | mutex_lock_nested(&parent->d_inode->i_mutex, |
| 125 | I_MUTEX_XATTR); |
| 126 | err = xattr_mkdir(parent->d_inode, dentry, 0700); |
| 127 | mutex_unlock(&parent->d_inode->i_mutex); |
| 128 | } |
| 129 | |
| 130 | if (err) { |
| 131 | dput(dentry); |
| 132 | dentry = ERR_PTR(err); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return dentry; |
| 137 | } |
| 138 | |
| 139 | static struct dentry *open_xa_root(struct super_block *sb, int flags) |
| 140 | { |
| 141 | struct dentry *privroot = REISERFS_SB(sb)->priv_root; |
| 142 | if (!privroot) |
| 143 | return ERR_PTR(-ENODATA); |
| 144 | return lookup_or_create_dir(privroot, XAROOT_NAME, flags); |
| 145 | } |
| 146 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 147 | static struct dentry *open_xa_dir(const struct inode *inode, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 149 | struct dentry *xaroot, *xadir; |
| 150 | char namebuf[17]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 152 | xaroot = open_xa_root(inode->i_sb, flags); |
Jeff Mahoney | 9b7f375 | 2007-04-23 14:41:17 -0700 | [diff] [blame] | 153 | if (IS_ERR(xaroot)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 154 | return xaroot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 156 | snprintf(namebuf, sizeof(namebuf), "%X.%X", |
| 157 | le32_to_cpu(INODE_PKEY(inode)->k_objectid), |
| 158 | inode->i_generation); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 160 | xadir = lookup_or_create_dir(xaroot, namebuf, flags); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 161 | dput(xaroot); |
| 162 | return xadir; |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* |
| 167 | * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but |
| 168 | * we need to drop the path before calling the filldir struct. That |
| 169 | * would be a big performance hit to the non-xattr case, so I've copied |
| 170 | * the whole thing for now. --clm |
| 171 | * |
| 172 | * the big difference is that I go backwards through the directory, |
| 173 | * and don't mess with f->f_pos, but the idea is the same. Do some |
| 174 | * action on each and every entry in the directory. |
| 175 | * |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 176 | * we're called with i_mutex held, so there are no worries about the directory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | * changing underneath us. |
| 178 | */ |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 179 | static int __xattr_readdir(struct inode *inode, void *dirent, filldir_t filldir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 181 | struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ |
| 182 | INITIALIZE_PATH(path_to_entry); |
| 183 | struct buffer_head *bh; |
| 184 | int entry_num; |
| 185 | struct item_head *ih, tmp_ih; |
| 186 | int search_res; |
| 187 | char *local_buf; |
| 188 | loff_t next_pos; |
| 189 | char small_buf[32]; /* avoid kmalloc if we can */ |
| 190 | struct reiserfs_de_head *deh; |
| 191 | int d_reclen; |
| 192 | char *d_name; |
| 193 | off_t d_off; |
| 194 | ino_t d_ino; |
| 195 | struct reiserfs_dir_entry de; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 197 | /* form key for search the next directory entry using f_pos field of |
| 198 | file structure */ |
| 199 | next_pos = max_reiserfs_offset(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 201 | while (1) { |
| 202 | research: |
| 203 | if (next_pos <= DOT_DOT_OFFSET) |
| 204 | break; |
| 205 | make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 207 | search_res = |
| 208 | search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry, |
| 209 | &de); |
| 210 | if (search_res == IO_ERROR) { |
| 211 | // FIXME: we could just skip part of directory which could |
| 212 | // not be read |
| 213 | pathrelse(&path_to_entry); |
| 214 | return -EIO; |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 217 | if (search_res == NAME_NOT_FOUND) |
| 218 | de.de_entry_num--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 220 | set_de_name_and_namelen(&de); |
| 221 | entry_num = de.de_entry_num; |
| 222 | deh = &(de.de_deh[entry_num]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 224 | bh = de.de_bh; |
| 225 | ih = de.de_ih; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 227 | if (!is_direntry_le_ih(ih)) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 228 | reiserfs_error(inode->i_sb, "jdm-20000", |
| 229 | "not direntry %h", ih); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | copy_item_head(&tmp_ih, ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 234 | /* we must have found item, that is item of this directory, */ |
| 235 | RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key), |
| 236 | "vs-9000: found item %h does not match to dir we readdir %K", |
| 237 | ih, &pos_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 239 | if (deh_offset(deh) <= DOT_DOT_OFFSET) { |
| 240 | break; |
| 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 243 | /* look for the previous entry in the directory */ |
| 244 | next_pos = deh_offset(deh) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 246 | if (!de_visible(deh)) |
| 247 | /* it is hidden entry */ |
| 248 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 250 | d_reclen = entry_length(bh, ih, entry_num); |
| 251 | d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh); |
| 252 | d_off = deh_offset(deh); |
| 253 | d_ino = deh_objectid(deh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 255 | if (!d_name[d_reclen - 1]) |
| 256 | d_reclen = strlen(d_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 258 | if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) { |
| 259 | /* too big to send back to VFS */ |
| 260 | continue; |
| 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 263 | /* Ignore the .reiserfs_priv entry */ |
| 264 | if (reiserfs_xattrs(inode->i_sb) && |
| 265 | !old_format_only(inode->i_sb) && |
| 266 | deh_objectid(deh) == |
| 267 | le32_to_cpu(INODE_PKEY |
| 268 | (REISERFS_SB(inode->i_sb)->priv_root->d_inode)-> |
| 269 | k_objectid)) |
| 270 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 272 | if (d_reclen <= 32) { |
| 273 | local_buf = small_buf; |
| 274 | } else { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 275 | local_buf = kmalloc(d_reclen, GFP_NOFS); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 276 | if (!local_buf) { |
| 277 | pathrelse(&path_to_entry); |
| 278 | return -ENOMEM; |
| 279 | } |
| 280 | if (item_moved(&tmp_ih, &path_to_entry)) { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 281 | kfree(local_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 283 | /* sigh, must retry. Do this same offset again */ |
| 284 | next_pos = d_off; |
| 285 | goto research; |
| 286 | } |
| 287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 289 | // Note, that we copy name to user space via temporary |
| 290 | // buffer (local_buf) because filldir will block if |
| 291 | // user space buffer is swapped out. At that time |
| 292 | // entry can move to somewhere else |
| 293 | memcpy(local_buf, d_name, d_reclen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 295 | /* the filldir function might need to start transactions, |
| 296 | * or do who knows what. Release the path now that we've |
| 297 | * copied all the important stuff out of the deh |
| 298 | */ |
| 299 | pathrelse(&path_to_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 301 | if (filldir(dirent, local_buf, d_reclen, d_off, d_ino, |
| 302 | DT_UNKNOWN) < 0) { |
| 303 | if (local_buf != small_buf) { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 304 | kfree(local_buf); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 305 | } |
| 306 | goto end; |
| 307 | } |
| 308 | if (local_buf != small_buf) { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 309 | kfree(local_buf); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 310 | } |
| 311 | } /* while */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 313 | end: |
| 314 | pathrelse(&path_to_entry); |
| 315 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* |
| 319 | * this could be done with dedicated readdir ops for the xattr files, |
| 320 | * but I want to get something working asap |
| 321 | * this is stolen from vfs_readdir |
| 322 | * |
| 323 | */ |
| 324 | static |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 325 | int xattr_readdir(struct inode *inode, filldir_t filler, void *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 327 | int res = -ENOENT; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 328 | if (!IS_DEADDIR(inode)) { |
| 329 | lock_kernel(); |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 330 | res = __xattr_readdir(inode, buf, filler); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 331 | unlock_kernel(); |
| 332 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 333 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 336 | static int |
| 337 | __reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen) |
| 338 | { |
| 339 | struct dentry *dentry; |
| 340 | struct inode *dir = xadir->d_inode; |
| 341 | int err = 0; |
| 342 | |
| 343 | dentry = lookup_one_len(name, xadir, namelen); |
| 344 | if (IS_ERR(dentry)) { |
| 345 | err = PTR_ERR(dentry); |
| 346 | goto out; |
| 347 | } else if (!dentry->d_inode) { |
| 348 | err = -ENODATA; |
| 349 | goto out_file; |
| 350 | } |
| 351 | |
| 352 | /* Skip directories.. */ |
| 353 | if (S_ISDIR(dentry->d_inode->i_mode)) |
| 354 | goto out_file; |
| 355 | |
| 356 | if (!IS_PRIVATE(dentry->d_inode)) { |
| 357 | reiserfs_error(dir->i_sb, "jdm-20003", |
| 358 | "OID %08x [%.*s/%.*s] doesn't have " |
| 359 | "priv flag set [parent is %sset].", |
| 360 | le32_to_cpu(INODE_PKEY(dentry->d_inode)-> |
| 361 | k_objectid), xadir->d_name.len, |
| 362 | xadir->d_name.name, namelen, name, |
| 363 | IS_PRIVATE(xadir->d_inode) ? "" : |
| 364 | "not "); |
| 365 | dput(dentry); |
| 366 | return -EIO; |
| 367 | } |
| 368 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 369 | err = xattr_unlink(dir, dentry); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 370 | |
| 371 | out_file: |
| 372 | dput(dentry); |
| 373 | |
| 374 | out: |
| 375 | return err; |
| 376 | } |
| 377 | |
| 378 | /* The following are side effects of other operations that aren't explicitly |
| 379 | * modifying extended attributes. This includes operations such as permissions |
| 380 | * or ownership changes, object deletions, etc. */ |
| 381 | |
| 382 | static int |
| 383 | reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen, |
| 384 | loff_t offset, u64 ino, unsigned int d_type) |
| 385 | { |
| 386 | struct dentry *xadir = (struct dentry *)buf; |
| 387 | |
| 388 | return __reiserfs_xattr_del(xadir, name, namelen); |
| 389 | |
| 390 | } |
| 391 | |
| 392 | /* This is called w/ inode->i_mutex downed */ |
| 393 | int reiserfs_delete_xattrs(struct inode *inode) |
| 394 | { |
| 395 | struct dentry *dir, *root; |
| 396 | int err = 0; |
| 397 | |
| 398 | /* Skip out, an xattr has no xattrs associated with it */ |
| 399 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) |
| 400 | return 0; |
| 401 | |
| 402 | reiserfs_read_lock_xattrs(inode->i_sb); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 403 | dir = open_xa_dir(inode, XATTR_REPLACE); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 404 | reiserfs_read_unlock_xattrs(inode->i_sb); |
| 405 | if (IS_ERR(dir)) { |
| 406 | err = PTR_ERR(dir); |
| 407 | goto out; |
| 408 | } else if (!dir->d_inode) { |
| 409 | dput(dir); |
| 410 | return 0; |
| 411 | } |
| 412 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 413 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 414 | err = xattr_readdir(dir->d_inode, reiserfs_delete_xattrs_filler, dir); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 415 | mutex_unlock(&dir->d_inode->i_mutex); |
| 416 | if (err) |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 417 | goto out_dir; |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 418 | |
| 419 | /* Leftovers besides . and .. -- that's not good. */ |
| 420 | if (dir->d_inode->i_nlink <= 2) { |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 421 | root = open_xa_root(inode->i_sb, XATTR_REPLACE); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 422 | reiserfs_write_lock_xattrs(inode->i_sb); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 423 | mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR); |
| 424 | err = xattr_rmdir(root->d_inode, dir); |
| 425 | mutex_unlock(&root->d_inode->i_mutex); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 426 | reiserfs_write_unlock_xattrs(inode->i_sb); |
| 427 | dput(root); |
| 428 | } else { |
| 429 | reiserfs_warning(inode->i_sb, "jdm-20006", |
| 430 | "Couldn't remove all entries in directory"); |
| 431 | } |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 432 | |
| 433 | out_dir: |
| 434 | dput(dir); |
| 435 | |
| 436 | out: |
| 437 | if (!err) |
| 438 | REISERFS_I(inode)->i_flags = |
| 439 | REISERFS_I(inode)->i_flags & ~i_has_xattr_dir; |
| 440 | return err; |
| 441 | } |
| 442 | |
| 443 | struct reiserfs_chown_buf { |
| 444 | struct inode *inode; |
| 445 | struct dentry *xadir; |
| 446 | struct iattr *attrs; |
| 447 | }; |
| 448 | |
| 449 | /* XXX: If there is a better way to do this, I'd love to hear about it */ |
| 450 | static int |
| 451 | reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen, |
| 452 | loff_t offset, u64 ino, unsigned int d_type) |
| 453 | { |
| 454 | struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf; |
| 455 | struct dentry *xafile, *xadir = chown_buf->xadir; |
| 456 | struct iattr *attrs = chown_buf->attrs; |
| 457 | int err = 0; |
| 458 | |
| 459 | xafile = lookup_one_len(name, xadir, namelen); |
| 460 | if (IS_ERR(xafile)) |
| 461 | return PTR_ERR(xafile); |
| 462 | else if (!xafile->d_inode) { |
| 463 | dput(xafile); |
| 464 | return -ENODATA; |
| 465 | } |
| 466 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 467 | if (!S_ISDIR(xafile->d_inode->i_mode)) { |
| 468 | mutex_lock_nested(&xafile->d_inode->i_mutex, I_MUTEX_CHILD); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 469 | err = notify_change(xafile, attrs); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 470 | mutex_unlock(&xafile->d_inode->i_mutex); |
| 471 | } |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 472 | dput(xafile); |
| 473 | |
| 474 | return err; |
| 475 | } |
| 476 | |
| 477 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) |
| 478 | { |
| 479 | struct dentry *dir; |
| 480 | int err = 0; |
| 481 | struct reiserfs_chown_buf buf; |
| 482 | unsigned int ia_valid = attrs->ia_valid; |
| 483 | |
| 484 | /* Skip out, an xattr has no xattrs associated with it */ |
| 485 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) |
| 486 | return 0; |
| 487 | |
| 488 | reiserfs_read_lock_xattrs(inode->i_sb); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 489 | dir = open_xa_dir(inode, XATTR_REPLACE); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 490 | reiserfs_read_unlock_xattrs(inode->i_sb); |
| 491 | if (IS_ERR(dir)) { |
| 492 | if (PTR_ERR(dir) != -ENODATA) |
| 493 | err = PTR_ERR(dir); |
| 494 | goto out; |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 495 | } else if (!dir->d_inode) |
| 496 | goto out_dir; |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 497 | |
| 498 | attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME); |
| 499 | buf.xadir = dir; |
| 500 | buf.attrs = attrs; |
| 501 | buf.inode = inode; |
| 502 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 503 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 504 | err = xattr_readdir(dir->d_inode, reiserfs_chown_xattrs_filler, &buf); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 505 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 506 | if (!err) |
| 507 | err = notify_change(dir, attrs); |
| 508 | mutex_unlock(&dir->d_inode->i_mutex); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 509 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 510 | attrs->ia_valid = ia_valid; |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 511 | out_dir: |
| 512 | dput(dir); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 513 | out: |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 514 | return err; |
| 515 | } |
| 516 | |
| 517 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 518 | static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char |
| 519 | *prefix); |
| 520 | |
| 521 | /* Returns a dentry corresponding to a specific extended attribute file |
| 522 | * for the inode. If flags allow, the file is created. Otherwise, a |
| 523 | * valid or negative dentry, or an error is returned. */ |
| 524 | static struct dentry *get_xa_file_dentry(const struct inode *inode, |
| 525 | const char *name, int flags) |
| 526 | { |
| 527 | struct dentry *xadir, *xafile; |
| 528 | int err = 0; |
| 529 | |
| 530 | xadir = open_xa_dir(inode, flags); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 531 | if (IS_ERR(xadir)) |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 532 | return ERR_CAST(xadir); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 533 | |
| 534 | xafile = lookup_one_len(name, xadir, strlen(name)); |
| 535 | if (IS_ERR(xafile)) { |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 536 | err = PTR_ERR(xafile); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 537 | goto out; |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 538 | } |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 539 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 540 | if (xafile->d_inode && (flags & XATTR_CREATE)) |
| 541 | err = -EEXIST; |
| 542 | |
| 543 | if (!xafile->d_inode) { |
| 544 | err = -ENODATA; |
| 545 | if (xattr_may_create(flags)) { |
| 546 | mutex_lock_nested(&xadir->d_inode->i_mutex, |
| 547 | I_MUTEX_XATTR); |
| 548 | err = xattr_create(xadir->d_inode, xafile, |
| 549 | 0700|S_IFREG); |
| 550 | mutex_unlock(&xadir->d_inode->i_mutex); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 554 | if (err) |
| 555 | dput(xafile); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 556 | out: |
| 557 | dput(xadir); |
| 558 | if (err) |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 559 | return ERR_PTR(err); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 560 | return xafile; |
| 561 | } |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* Internal operations on file data */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 564 | static inline void reiserfs_put_page(struct page *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 566 | kunmap(page); |
| 567 | page_cache_release(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Jeff Mahoney | ec6ea56 | 2009-03-30 14:02:30 -0400 | [diff] [blame] | 570 | static struct page *reiserfs_get_page(struct inode *dir, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 572 | struct address_space *mapping = dir->i_mapping; |
| 573 | struct page *page; |
| 574 | /* We can deadlock if we try to free dentries, |
| 575 | and an unlink/rmdir has just occured - GFP_NOFS avoids this */ |
Al Viro | c4cdd03 | 2005-10-21 03:22:39 -0400 | [diff] [blame] | 576 | mapping_set_gfp_mask(mapping, GFP_NOFS); |
Jeff Mahoney | ec6ea56 | 2009-03-30 14:02:30 -0400 | [diff] [blame] | 577 | page = read_mapping_page(mapping, n >> PAGE_CACHE_SHIFT, NULL); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 578 | if (!IS_ERR(page)) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 579 | kmap(page); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 580 | if (PageError(page)) |
| 581 | goto fail; |
| 582 | } |
| 583 | return page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 585 | fail: |
| 586 | reiserfs_put_page(page); |
| 587 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 590 | static inline __u32 xattr_hash(const char *msg, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 592 | return csum_partial(msg, len, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Vladimir Saveliev | ba9d8ce | 2007-10-16 01:25:14 -0700 | [diff] [blame] | 595 | int reiserfs_commit_write(struct file *f, struct page *page, |
| 596 | unsigned from, unsigned to); |
| 597 | int reiserfs_prepare_write(struct file *f, struct page *page, |
| 598 | unsigned from, unsigned to); |
| 599 | |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | /* Generic extended attribute operations that can be used by xa plugins */ |
| 602 | |
| 603 | /* |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 604 | * inode->i_mutex: down |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | */ |
| 606 | int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 607 | reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer, |
| 608 | size_t buffer_size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 610 | int err = 0; |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 611 | struct dentry *dentry; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 612 | struct page *page; |
| 613 | char *data; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 614 | size_t file_pos = 0; |
| 615 | size_t buffer_pos = 0; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 616 | struct iattr newattrs; |
| 617 | __u32 xahash = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 619 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
| 620 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 622 | /* Empty xattrs are ok, they're just empty files, no hash */ |
| 623 | if (buffer && buffer_size) |
| 624 | xahash = xattr_hash(buffer, buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 626 | dentry = get_xa_file_dentry(inode, name, flags); |
| 627 | if (IS_ERR(dentry)) { |
| 628 | err = PTR_ERR(dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 629 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 632 | REISERFS_I(inode)->i_flags |= i_has_xattr_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 634 | /* Resize it so we're ok to write there */ |
| 635 | newattrs.ia_size = buffer_size; |
| 636 | newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; |
Jeff Mahoney | f437c52 | 2009-03-30 14:02:29 -0400 | [diff] [blame] | 637 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 638 | err = notify_change(dentry, &newattrs); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 639 | mutex_unlock(&dentry->d_inode->i_mutex); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 640 | if (err) |
| 641 | goto out_filp; |
| 642 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 643 | while (buffer_pos < buffer_size || buffer_pos == 0) { |
| 644 | size_t chunk; |
| 645 | size_t skip = 0; |
| 646 | size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1)); |
| 647 | if (buffer_size - buffer_pos > PAGE_CACHE_SIZE) |
| 648 | chunk = PAGE_CACHE_SIZE; |
| 649 | else |
| 650 | chunk = buffer_size - buffer_pos; |
| 651 | |
Jeff Mahoney | ec6ea56 | 2009-03-30 14:02:30 -0400 | [diff] [blame] | 652 | page = reiserfs_get_page(dentry->d_inode, file_pos); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 653 | if (IS_ERR(page)) { |
| 654 | err = PTR_ERR(page); |
| 655 | goto out_filp; |
| 656 | } |
| 657 | |
| 658 | lock_page(page); |
| 659 | data = page_address(page); |
| 660 | |
| 661 | if (file_pos == 0) { |
| 662 | struct reiserfs_xattr_header *rxh; |
| 663 | skip = file_pos = sizeof(struct reiserfs_xattr_header); |
| 664 | if (chunk + skip > PAGE_CACHE_SIZE) |
| 665 | chunk = PAGE_CACHE_SIZE - skip; |
| 666 | rxh = (struct reiserfs_xattr_header *)data; |
| 667 | rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC); |
| 668 | rxh->h_hash = cpu_to_le32(xahash); |
| 669 | } |
| 670 | |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 671 | err = reiserfs_prepare_write(NULL, page, page_offset, |
Vladimir Saveliev | ba9d8ce | 2007-10-16 01:25:14 -0700 | [diff] [blame] | 672 | page_offset + chunk + skip); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 673 | if (!err) { |
| 674 | if (buffer) |
| 675 | memcpy(data + skip, buffer + buffer_pos, chunk); |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 676 | err = reiserfs_commit_write(NULL, page, page_offset, |
| 677 | page_offset + chunk + |
| 678 | skip); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 679 | } |
| 680 | unlock_page(page); |
| 681 | reiserfs_put_page(page); |
| 682 | buffer_pos += chunk; |
| 683 | file_pos += chunk; |
| 684 | skip = 0; |
| 685 | if (err || buffer_size == 0 || !buffer) |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | /* We can't mark the inode dirty if it's not hashed. This is the case |
| 690 | * when we're inheriting the default ACL. If we dirty it, the inode |
| 691 | * gets marked dirty, but won't (ever) make it onto the dirty list until |
| 692 | * it's synced explicitly to clear I_DIRTY. This is bad. */ |
| 693 | if (!hlist_unhashed(&inode->i_hash)) { |
| 694 | inode->i_ctime = CURRENT_TIME_SEC; |
| 695 | mark_inode_dirty(inode); |
| 696 | } |
| 697 | |
| 698 | out_filp: |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 699 | dput(dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 700 | |
| 701 | out: |
| 702 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /* |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 706 | * inode->i_mutex: down |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | */ |
| 708 | int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 709 | reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer, |
| 710 | size_t buffer_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 712 | ssize_t err = 0; |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 713 | struct dentry *dentry; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 714 | size_t isize; |
| 715 | size_t file_pos = 0; |
| 716 | size_t buffer_pos = 0; |
| 717 | struct page *page; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 718 | __u32 hash = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 720 | if (name == NULL) |
| 721 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 723 | /* We can't have xattrs attached to v1 items since they don't have |
| 724 | * generation numbers */ |
| 725 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
| 726 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 728 | dentry = get_xa_file_dentry(inode, name, XATTR_REPLACE); |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 729 | if (IS_ERR(dentry)) { |
| 730 | err = PTR_ERR(dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 731 | goto out; |
| 732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Jeff Mahoney | f437c52 | 2009-03-30 14:02:29 -0400 | [diff] [blame] | 734 | isize = i_size_read(dentry->d_inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 735 | REISERFS_I(inode)->i_flags |= i_has_xattr_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 737 | /* Just return the size needed */ |
| 738 | if (buffer == NULL) { |
| 739 | err = isize - sizeof(struct reiserfs_xattr_header); |
| 740 | goto out_dput; |
| 741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 743 | if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) { |
| 744 | err = -ERANGE; |
| 745 | goto out_dput; |
| 746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 748 | while (file_pos < isize) { |
| 749 | size_t chunk; |
| 750 | char *data; |
| 751 | size_t skip = 0; |
| 752 | if (isize - file_pos > PAGE_CACHE_SIZE) |
| 753 | chunk = PAGE_CACHE_SIZE; |
| 754 | else |
| 755 | chunk = isize - file_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Jeff Mahoney | ec6ea56 | 2009-03-30 14:02:30 -0400 | [diff] [blame] | 757 | page = reiserfs_get_page(dentry->d_inode, file_pos); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 758 | if (IS_ERR(page)) { |
| 759 | err = PTR_ERR(page); |
| 760 | goto out_dput; |
| 761 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 763 | lock_page(page); |
| 764 | data = page_address(page); |
| 765 | if (file_pos == 0) { |
| 766 | struct reiserfs_xattr_header *rxh = |
| 767 | (struct reiserfs_xattr_header *)data; |
| 768 | skip = file_pos = sizeof(struct reiserfs_xattr_header); |
| 769 | chunk -= skip; |
| 770 | /* Magic doesn't match up.. */ |
| 771 | if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) { |
| 772 | unlock_page(page); |
| 773 | reiserfs_put_page(page); |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 774 | reiserfs_warning(inode->i_sb, "jdm-20001", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 775 | "Invalid magic for xattr (%s) " |
| 776 | "associated with %k", name, |
| 777 | INODE_PKEY(inode)); |
| 778 | err = -EIO; |
| 779 | goto out_dput; |
| 780 | } |
| 781 | hash = le32_to_cpu(rxh->h_hash); |
| 782 | } |
| 783 | memcpy(buffer + buffer_pos, data + skip, chunk); |
| 784 | unlock_page(page); |
| 785 | reiserfs_put_page(page); |
| 786 | file_pos += chunk; |
| 787 | buffer_pos += chunk; |
| 788 | skip = 0; |
| 789 | } |
| 790 | err = isize - sizeof(struct reiserfs_xattr_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 792 | if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) != |
| 793 | hash) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 794 | reiserfs_warning(inode->i_sb, "jdm-20002", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 795 | "Invalid hash for xattr (%s) associated " |
| 796 | "with %k", name, INODE_PKEY(inode)); |
| 797 | err = -EIO; |
| 798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 800 | out_dput: |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 801 | dput(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 803 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 804 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 807 | int reiserfs_xattr_del(struct inode *inode, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 809 | struct dentry *dir; |
| 810 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 812 | dir = open_xa_dir(inode, XATTR_REPLACE); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 813 | if (IS_ERR(dir)) { |
| 814 | err = PTR_ERR(dir); |
| 815 | goto out; |
| 816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 818 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 819 | err = __reiserfs_xattr_del(dir, name, strlen(name)); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 820 | mutex_unlock(&dir->d_inode->i_mutex); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 821 | dput(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 823 | if (!err) { |
| 824 | inode->i_ctime = CURRENT_TIME_SEC; |
| 825 | mark_inode_dirty(inode); |
| 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 828 | out: |
| 829 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | /* Actual operations that are exported to VFS-land */ |
| 833 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 834 | static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | /* |
| 836 | * Inode operation getxattr() |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 837 | * Preliminary locking: we down dentry->d_inode->i_mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | */ |
| 839 | ssize_t |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 840 | reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, |
| 841 | size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 843 | struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); |
| 844 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 846 | if (!xah || !reiserfs_xattrs(dentry->d_sb) || |
| 847 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) |
| 848 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 850 | reiserfs_read_lock_xattr_i(dentry->d_inode); |
| 851 | reiserfs_read_lock_xattrs(dentry->d_sb); |
| 852 | err = xah->get(dentry->d_inode, name, buffer, size); |
| 853 | reiserfs_read_unlock_xattrs(dentry->d_sb); |
| 854 | reiserfs_read_unlock_xattr_i(dentry->d_inode); |
| 855 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | /* |
| 859 | * Inode operation setxattr() |
| 860 | * |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 861 | * dentry->d_inode->i_mutex down |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | */ |
| 863 | int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 864 | reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
| 865 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 867 | struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); |
| 868 | int err; |
| 869 | int lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 871 | if (!xah || !reiserfs_xattrs(dentry->d_sb) || |
| 872 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) |
| 873 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 875 | reiserfs_write_lock_xattr_i(dentry->d_inode); |
| 876 | lock = !has_xattr_dir(dentry->d_inode); |
| 877 | if (lock) |
| 878 | reiserfs_write_lock_xattrs(dentry->d_sb); |
| 879 | else |
| 880 | reiserfs_read_lock_xattrs(dentry->d_sb); |
| 881 | err = xah->set(dentry->d_inode, name, value, size, flags); |
| 882 | if (lock) |
| 883 | reiserfs_write_unlock_xattrs(dentry->d_sb); |
| 884 | else |
| 885 | reiserfs_read_unlock_xattrs(dentry->d_sb); |
| 886 | reiserfs_write_unlock_xattr_i(dentry->d_inode); |
| 887 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | /* |
| 891 | * Inode operation removexattr() |
| 892 | * |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 893 | * dentry->d_inode->i_mutex down |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 895 | int reiserfs_removexattr(struct dentry *dentry, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 897 | int err; |
| 898 | struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 900 | if (!xah || !reiserfs_xattrs(dentry->d_sb) || |
| 901 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) |
| 902 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 904 | reiserfs_write_lock_xattr_i(dentry->d_inode); |
| 905 | reiserfs_read_lock_xattrs(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 907 | /* Deletion pre-operation */ |
| 908 | if (xah->del) { |
| 909 | err = xah->del(dentry->d_inode, name); |
| 910 | if (err) |
| 911 | goto out; |
| 912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 914 | err = reiserfs_xattr_del(dentry->d_inode, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 916 | dentry->d_inode->i_ctime = CURRENT_TIME_SEC; |
| 917 | mark_inode_dirty(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 919 | out: |
| 920 | reiserfs_read_unlock_xattrs(dentry->d_sb); |
| 921 | reiserfs_write_unlock_xattr_i(dentry->d_inode); |
| 922 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | /* This is what filldir will use: |
| 926 | * r_pos will always contain the amount of space required for the entire |
| 927 | * list. If r_pos becomes larger than r_size, we need more space and we |
| 928 | * return an error indicating this. If r_pos is less than r_size, then we've |
| 929 | * filled the buffer successfully and we return success */ |
| 930 | struct reiserfs_listxattr_buf { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 931 | int r_pos; |
| 932 | int r_size; |
| 933 | char *r_buf; |
| 934 | struct inode *r_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | }; |
| 936 | |
| 937 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 938 | reiserfs_listxattr_filler(void *buf, const char *name, int namelen, |
David Howells | afefdbb | 2006-10-03 01:13:46 -0700 | [diff] [blame] | 939 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 941 | struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf; |
| 942 | int len = 0; |
| 943 | if (name[0] != '.' |
| 944 | || (namelen != 1 && (name[1] != '.' || namelen != 2))) { |
| 945 | struct reiserfs_xattr_handler *xah = |
| 946 | find_xattr_handler_prefix(name); |
| 947 | if (!xah) |
| 948 | return 0; /* Unsupported xattr name, skip it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 950 | /* We call ->list() twice because the operation isn't required to just |
| 951 | * return the name back - we want to make sure we have enough space */ |
| 952 | len += xah->list(b->r_inode, name, namelen, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 954 | if (len) { |
| 955 | if (b->r_pos + len + 1 <= b->r_size) { |
| 956 | char *p = b->r_buf + b->r_pos; |
| 957 | p += xah->list(b->r_inode, name, namelen, p); |
| 958 | *p++ = '\0'; |
| 959 | } |
| 960 | b->r_pos += len + 1; |
| 961 | } |
| 962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 964 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | /* |
| 968 | * Inode operation listxattr() |
| 969 | * |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 970 | * Preliminary locking: we down dentry->d_inode->i_mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 972 | ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 974 | struct dentry *dir; |
| 975 | int err = 0; |
| 976 | struct reiserfs_listxattr_buf buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 978 | if (!dentry->d_inode) |
| 979 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 981 | if (!reiserfs_xattrs(dentry->d_sb) || |
| 982 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) |
| 983 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 985 | reiserfs_read_lock_xattr_i(dentry->d_inode); |
| 986 | reiserfs_read_lock_xattrs(dentry->d_sb); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 987 | dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 988 | reiserfs_read_unlock_xattrs(dentry->d_sb); |
| 989 | if (IS_ERR(dir)) { |
| 990 | err = PTR_ERR(dir); |
| 991 | if (err == -ENODATA) |
| 992 | err = 0; /* Not an error if there aren't any xattrs */ |
| 993 | goto out; |
| 994 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 996 | buf.r_buf = buffer; |
| 997 | buf.r_size = buffer ? size : 0; |
| 998 | buf.r_pos = 0; |
| 999 | buf.r_inode = dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1001 | REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 1003 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 1004 | err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 1005 | mutex_unlock(&dir->d_inode->i_mutex); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1006 | if (err) |
| 1007 | goto out_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1009 | if (buf.r_pos > buf.r_size && buffer != NULL) |
| 1010 | err = -ERANGE; |
| 1011 | else |
| 1012 | err = buf.r_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1014 | out_dir: |
Jeff Mahoney | 3227e14 | 2008-02-15 14:37:22 -0800 | [diff] [blame] | 1015 | dput(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1017 | out: |
| 1018 | reiserfs_read_unlock_xattr_i(dentry->d_inode); |
| 1019 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /* This is the implementation for the xattr plugin infrastructure */ |
Denis Cheng | bcf11cb | 2008-02-06 01:37:40 -0800 | [diff] [blame] | 1023 | static LIST_HEAD(xattr_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | static DEFINE_RWLOCK(handler_lock); |
| 1025 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1026 | static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char |
| 1027 | *prefix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1029 | struct reiserfs_xattr_handler *xah = NULL; |
| 1030 | struct list_head *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1032 | read_lock(&handler_lock); |
| 1033 | list_for_each(p, &xattr_handlers) { |
| 1034 | xah = list_entry(p, struct reiserfs_xattr_handler, handlers); |
| 1035 | if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0) |
| 1036 | break; |
| 1037 | xah = NULL; |
| 1038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1040 | read_unlock(&handler_lock); |
| 1041 | return xah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1044 | static void __unregister_handlers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1046 | struct reiserfs_xattr_handler *xah; |
| 1047 | struct list_head *p, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1049 | list_for_each_safe(p, tmp, &xattr_handlers) { |
| 1050 | xah = list_entry(p, struct reiserfs_xattr_handler, handlers); |
| 1051 | if (xah->exit) |
| 1052 | xah->exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1054 | list_del_init(p); |
| 1055 | } |
| 1056 | INIT_LIST_HEAD(&xattr_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1059 | int __init reiserfs_xattr_register_handlers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1061 | int err = 0; |
| 1062 | struct reiserfs_xattr_handler *xah; |
| 1063 | struct list_head *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1065 | write_lock(&handler_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1067 | /* If we're already initialized, nothing to do */ |
| 1068 | if (!list_empty(&xattr_handlers)) { |
| 1069 | write_unlock(&handler_lock); |
| 1070 | return 0; |
| 1071 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1073 | /* Add the handlers */ |
| 1074 | list_add_tail(&user_handler.handlers, &xattr_handlers); |
| 1075 | list_add_tail(&trusted_handler.handlers, &xattr_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | #ifdef CONFIG_REISERFS_FS_SECURITY |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1077 | list_add_tail(&security_handler.handlers, &xattr_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | #endif |
| 1079 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1080 | list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers); |
| 1081 | list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | #endif |
| 1083 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1084 | /* Run initializers, if available */ |
| 1085 | list_for_each(p, &xattr_handlers) { |
| 1086 | xah = list_entry(p, struct reiserfs_xattr_handler, handlers); |
| 1087 | if (xah->init) { |
| 1088 | err = xah->init(); |
| 1089 | if (err) { |
| 1090 | list_del_init(p); |
| 1091 | break; |
| 1092 | } |
| 1093 | } |
| 1094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1096 | /* Clean up other handlers, if any failed */ |
| 1097 | if (err) |
| 1098 | __unregister_handlers(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1100 | write_unlock(&handler_lock); |
| 1101 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1104 | void reiserfs_xattr_unregister_handlers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1106 | write_lock(&handler_lock); |
| 1107 | __unregister_handlers(); |
| 1108 | write_unlock(&handler_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1111 | static int reiserfs_check_acl(struct inode *inode, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | { |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1113 | struct posix_acl *acl; |
| 1114 | int error = -EAGAIN; /* do regular unix permission checks by default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1116 | reiserfs_read_lock_xattr_i(inode); |
| 1117 | reiserfs_read_lock_xattrs(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1119 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); |
| 1120 | |
| 1121 | reiserfs_read_unlock_xattrs(inode->i_sb); |
| 1122 | reiserfs_read_unlock_xattr_i(inode); |
| 1123 | |
| 1124 | if (acl) { |
| 1125 | if (!IS_ERR(acl)) { |
| 1126 | error = posix_acl_permission(inode, acl, mask); |
| 1127 | posix_acl_release(acl); |
| 1128 | } else if (PTR_ERR(acl) != -ENODATA) |
| 1129 | error = PTR_ERR(acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1132 | return error; |
| 1133 | } |
| 1134 | |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 1135 | int reiserfs_permission(struct inode *inode, int mask) |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1136 | { |
| 1137 | /* |
| 1138 | * We don't do permission checks on the internal objects. |
| 1139 | * Permissions are determined by the "owning" object. |
| 1140 | */ |
Jeff Mahoney | 6dfede69 | 2009-03-30 14:02:32 -0400 | [diff] [blame] | 1141 | if (IS_PRIVATE(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | /* |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1144 | * Stat data v1 doesn't support ACLs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | */ |
Christoph Hellwig | ec19157 | 2006-02-01 03:06:46 -0800 | [diff] [blame] | 1146 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
| 1147 | return generic_permission(inode, mask, NULL); |
| 1148 | else |
| 1149 | return generic_permission(inode, mask, reiserfs_check_acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 1151 | |
| 1152 | static int create_privroot(struct dentry *dentry) |
| 1153 | { |
| 1154 | int err; |
| 1155 | struct inode *inode = dentry->d_parent->d_inode; |
| 1156 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR); |
Jeff Mahoney | 6c17675 | 2009-03-30 14:02:34 -0400 | [diff] [blame^] | 1157 | err = xattr_mkdir(inode, dentry, 0700); |
Jeff Mahoney | a72bdb1 | 2009-03-30 14:02:33 -0400 | [diff] [blame] | 1158 | mutex_unlock(&inode->i_mutex); |
| 1159 | if (err) { |
| 1160 | dput(dentry); |
| 1161 | dentry = NULL; |
| 1162 | } |
| 1163 | |
| 1164 | if (dentry && dentry->d_inode) |
| 1165 | reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr " |
| 1166 | "storage.\n", PRIVROOT_NAME); |
| 1167 | |
| 1168 | return err; |
| 1169 | } |
| 1170 | |
| 1171 | static int xattr_mount_check(struct super_block *s) |
| 1172 | { |
| 1173 | /* We need generation numbers to ensure that the oid mapping is correct |
| 1174 | * v3.5 filesystems don't have them. */ |
| 1175 | if (!old_format_only(s)) { |
| 1176 | set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); |
| 1177 | } else if (reiserfs_xattrs_optional(s)) { |
| 1178 | /* Old format filesystem, but optional xattrs have been enabled |
| 1179 | * at mount time. Error out. */ |
| 1180 | reiserfs_warning(s, "jdm-20005", |
| 1181 | "xattrs/ACLs not supported on pre v3.6 " |
| 1182 | "format filesystem. Failing mount."); |
| 1183 | return -EOPNOTSUPP; |
| 1184 | } else { |
| 1185 | /* Old format filesystem, but no optional xattrs have |
| 1186 | * been enabled. This means we silently disable xattrs |
| 1187 | * on the filesystem. */ |
| 1188 | clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); |
| 1189 | } |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | #else |
| 1195 | int __init reiserfs_xattr_register_handlers(void) { return 0; } |
| 1196 | void reiserfs_xattr_unregister_handlers(void) {} |
| 1197 | #endif |
| 1198 | |
| 1199 | /* This will catch lookups from the fs root to .reiserfs_priv */ |
| 1200 | static int |
| 1201 | xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name) |
| 1202 | { |
| 1203 | struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root; |
| 1204 | if (name->len == priv_root->d_name.len && |
| 1205 | name->hash == priv_root->d_name.hash && |
| 1206 | !memcmp(name->name, priv_root->d_name.name, name->len)) { |
| 1207 | return -ENOENT; |
| 1208 | } else if (q1->len == name->len && |
| 1209 | !memcmp(q1->name, name->name, name->len)) |
| 1210 | return 0; |
| 1211 | return 1; |
| 1212 | } |
| 1213 | |
| 1214 | static struct dentry_operations xattr_lookup_poison_ops = { |
| 1215 | .d_compare = xattr_lookup_poison, |
| 1216 | }; |
| 1217 | |
| 1218 | /* We need to take a copy of the mount flags since things like |
| 1219 | * MS_RDONLY don't get set until *after* we're called. |
| 1220 | * mount_flags != mount_options */ |
| 1221 | int reiserfs_xattr_init(struct super_block *s, int mount_flags) |
| 1222 | { |
| 1223 | int err = 0; |
| 1224 | |
| 1225 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 1226 | err = xattr_mount_check(s); |
| 1227 | if (err) |
| 1228 | goto error; |
| 1229 | #endif |
| 1230 | |
| 1231 | /* If we don't have the privroot located yet - go find it */ |
| 1232 | if (!REISERFS_SB(s)->priv_root) { |
| 1233 | struct dentry *dentry; |
| 1234 | dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, |
| 1235 | strlen(PRIVROOT_NAME)); |
| 1236 | if (!IS_ERR(dentry)) { |
| 1237 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 1238 | if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) |
| 1239 | err = create_privroot(dentry); |
| 1240 | #endif |
| 1241 | if (!dentry->d_inode) { |
| 1242 | dput(dentry); |
| 1243 | dentry = NULL; |
| 1244 | } |
| 1245 | } else |
| 1246 | err = PTR_ERR(dentry); |
| 1247 | |
| 1248 | if (!err && dentry) { |
| 1249 | s->s_root->d_op = &xattr_lookup_poison_ops; |
| 1250 | dentry->d_inode->i_flags |= S_PRIVATE; |
| 1251 | REISERFS_SB(s)->priv_root = dentry; |
| 1252 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 1253 | /* xattrs are unavailable */ |
| 1254 | } else if (!(mount_flags & MS_RDONLY)) { |
| 1255 | /* If we're read-only it just means that the dir |
| 1256 | * hasn't been created. Not an error -- just no |
| 1257 | * xattrs on the fs. We'll check again if we |
| 1258 | * go read-write */ |
| 1259 | reiserfs_warning(s, "jdm-20006", |
| 1260 | "xattrs/ACLs enabled and couldn't " |
| 1261 | "find/create .reiserfs_priv. " |
| 1262 | "Failing mount."); |
| 1263 | err = -EOPNOTSUPP; |
| 1264 | #endif |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 1269 | error: |
| 1270 | if (err) { |
| 1271 | clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); |
| 1272 | clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt)); |
| 1273 | clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt)); |
| 1274 | } |
| 1275 | #endif |
| 1276 | |
| 1277 | /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */ |
| 1278 | s->s_flags = s->s_flags & ~MS_POSIXACL; |
| 1279 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
| 1280 | if (reiserfs_posixacl(s)) |
| 1281 | s->s_flags |= MS_POSIXACL; |
| 1282 | #endif |
| 1283 | |
| 1284 | return err; |
| 1285 | } |