Blame view
fs/reiserfs/xattr.c
25.4 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* * linux/fs/reiserfs/xattr.c * * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com> * */ /* * In order to implement EA/ACLs in a clean, backwards compatible manner, * they are implemented as files in a "private" directory. * Each EA is in it's own file, with the directory layout like so (/ is assumed * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory, * directories named using the capital-hex form of the objectid and * generation number are used. Inside each directory are individual files * named with the name of the extended attribute. * * So, for objectid 12648430, we could have: * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type * .. or similar. * * The file contents are the text of the EA. The size is known based on the * stat data describing the file. * * In the case of system.posix_acl_access and system.posix_acl_default, since * these are special cases for filesystem ACLs, they are interpreted by the * kernel, in addition, they are negatively and positively cached and attached * to the inode so that unnecessary lookups are avoided. |
d984561b3
|
30 31 |
* * Locking works like so: |
8b6dd72a4
|
32 33 |
* Directory components (xattr root, xattr dir) are protectd by their i_mutex. * The xattrs themselves are protected by the xattr_sem. |
1da177e4c
|
34 |
*/ |
f466c6fdb
|
35 |
#include "reiserfs.h" |
16f7e0fe2
|
36 |
#include <linux/capability.h> |
1da177e4c
|
37 38 39 |
#include <linux/dcache.h> #include <linux/namei.h> #include <linux/errno.h> |
5a0e3ad6a
|
40 |
#include <linux/gfp.h> |
1da177e4c
|
41 42 43 44 |
#include <linux/fs.h> #include <linux/file.h> #include <linux/pagemap.h> #include <linux/xattr.h> |
c45ac8887
|
45 |
#include "xattr.h" |
a3063ab88
|
46 |
#include "acl.h" |
17093991a
|
47 |
#include <linux/uaccess.h> |
3277c39f8
|
48 |
#include <net/checksum.h> |
1da177e4c
|
49 |
#include <linux/stat.h> |
6c17675e1
|
50 |
#include <linux/quotaops.h> |
431547b3c
|
51 |
#include <linux/security.h> |
47f70d08f
|
52 |
#include <linux/posix_acl_xattr.h> |
1da177e4c
|
53 |
|
1da177e4c
|
54 55 |
#define PRIVROOT_NAME ".reiserfs_priv" #define XAROOT_NAME "xattrs" |
1da177e4c
|
56 |
|
098297b27
|
57 58 |
/* * Helpers for inode ops. We do this so that we don't have all the VFS |
6c17675e1
|
59 |
* overhead and also for proper i_mutex annotation. |
098297b27
|
60 61 |
* dir->i_mutex must be held for all of them. */ |
3a355cc61
|
62 |
#ifdef CONFIG_REISERFS_FS_XATTR |
6c17675e1
|
63 |
static int xattr_create(struct inode *dir, struct dentry *dentry, int mode) |
1da177e4c
|
64 |
{ |
5955102c9
|
65 |
BUG_ON(!inode_is_locked(dir)); |
ebfc3b49a
|
66 |
return dir->i_op->create(dir, dentry, mode, true); |
6c17675e1
|
67 |
} |
3a355cc61
|
68 |
#endif |
bd4c625c0
|
69 |
|
18bb1db3e
|
70 |
static int xattr_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
6c17675e1
|
71 |
{ |
5955102c9
|
72 |
BUG_ON(!inode_is_locked(dir)); |
6c17675e1
|
73 74 |
return dir->i_op->mkdir(dir, dentry, mode); } |
bd4c625c0
|
75 |
|
098297b27
|
76 77 |
/* * We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr |
6c17675e1
|
78 79 |
* mutation ops aren't called during rename or splace, which are the * only other users of I_MUTEX_CHILD. It violates the ordering, but that's |
098297b27
|
80 81 |
* better than allocating another subclass just for this code. */ |
6c17675e1
|
82 83 84 |
static int xattr_unlink(struct inode *dir, struct dentry *dentry) { int error; |
f3fb9e273
|
85 |
|
5955102c9
|
86 |
BUG_ON(!inode_is_locked(dir)); |
bd4c625c0
|
87 |
|
5955102c9
|
88 |
inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD); |
6c17675e1
|
89 |
error = dir->i_op->unlink(dir, dentry); |
5955102c9
|
90 |
inode_unlock(d_inode(dentry)); |
6c17675e1
|
91 92 93 94 95 96 97 98 99 |
if (!error) d_delete(dentry); return error; } static int xattr_rmdir(struct inode *dir, struct dentry *dentry) { int error; |
f3fb9e273
|
100 |
|
5955102c9
|
101 |
BUG_ON(!inode_is_locked(dir)); |
6c17675e1
|
102 |
|
5955102c9
|
103 |
inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD); |
6c17675e1
|
104 105 |
error = dir->i_op->rmdir(dir, dentry); if (!error) |
2b0143b5c
|
106 |
d_inode(dentry)->i_flags |= S_DEAD; |
5955102c9
|
107 |
inode_unlock(d_inode(dentry)); |
6c17675e1
|
108 109 |
if (!error) d_delete(dentry); |
6c17675e1
|
110 111 112 |
return error; } |
6c17675e1
|
113 |
#define xattr_may_create(flags) (!flags || flags & XATTR_CREATE) |
ab17c4f02
|
114 |
static struct dentry *open_xa_root(struct super_block *sb, int flags) |
6c17675e1
|
115 |
{ |
ab17c4f02
|
116 117 |
struct dentry *privroot = REISERFS_SB(sb)->priv_root; struct dentry *xaroot; |
f3fb9e273
|
118 |
|
2b0143b5c
|
119 |
if (d_really_is_negative(privroot)) |
ab17c4f02
|
120 |
return ERR_PTR(-ENODATA); |
6c17675e1
|
121 |
|
5955102c9
|
122 |
inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR); |
6c17675e1
|
123 |
|
ab17c4f02
|
124 |
xaroot = dget(REISERFS_SB(sb)->xattr_root); |
ceb5edc45
|
125 126 |
if (!xaroot) xaroot = ERR_PTR(-ENODATA); |
2b0143b5c
|
127 |
else if (d_really_is_negative(xaroot)) { |
ab17c4f02
|
128 |
int err = -ENODATA; |
f3fb9e273
|
129 |
|
5a6059c35
|
130 |
if (xattr_may_create(flags)) |
2b0143b5c
|
131 |
err = xattr_mkdir(d_inode(privroot), xaroot, 0700); |
9b7f37550
|
132 |
if (err) { |
ab17c4f02
|
133 134 |
dput(xaroot); xaroot = ERR_PTR(err); |
9b7f37550
|
135 |
} |
bd4c625c0
|
136 |
} |
6c17675e1
|
137 |
|
5955102c9
|
138 |
inode_unlock(d_inode(privroot)); |
ab17c4f02
|
139 |
return xaroot; |
1da177e4c
|
140 |
} |
bd4c625c0
|
141 |
static struct dentry *open_xa_dir(const struct inode *inode, int flags) |
1da177e4c
|
142 |
{ |
bd4c625c0
|
143 144 |
struct dentry *xaroot, *xadir; char namebuf[17]; |
6c17675e1
|
145 |
xaroot = open_xa_root(inode->i_sb, flags); |
9b7f37550
|
146 |
if (IS_ERR(xaroot)) |
bd4c625c0
|
147 |
return xaroot; |
bd4c625c0
|
148 |
|
bd4c625c0
|
149 150 151 |
snprintf(namebuf, sizeof(namebuf), "%X.%X", le32_to_cpu(INODE_PKEY(inode)->k_objectid), inode->i_generation); |
bd4c625c0
|
152 |
|
5955102c9
|
153 |
inode_lock_nested(d_inode(xaroot), I_MUTEX_XATTR); |
ab17c4f02
|
154 155 |
xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf)); |
2b0143b5c
|
156 |
if (!IS_ERR(xadir) && d_really_is_negative(xadir)) { |
ab17c4f02
|
157 |
int err = -ENODATA; |
f3fb9e273
|
158 |
|
ab17c4f02
|
159 |
if (xattr_may_create(flags)) |
2b0143b5c
|
160 |
err = xattr_mkdir(d_inode(xaroot), xadir, 0700); |
ab17c4f02
|
161 162 163 164 165 |
if (err) { dput(xadir); xadir = ERR_PTR(err); } } |
5955102c9
|
166 |
inode_unlock(d_inode(xaroot)); |
bd4c625c0
|
167 168 |
dput(xaroot); return xadir; |
1da177e4c
|
169 |
} |
098297b27
|
170 171 |
/* * The following are side effects of other operations that aren't explicitly |
48b32a355
|
172 |
* modifying extended attributes. This includes operations such as permissions |
098297b27
|
173 174 |
* or ownership changes, object deletions, etc. */ |
a41f1a471
|
175 |
struct reiserfs_dentry_buf { |
4acf381e1
|
176 |
struct dir_context ctx; |
a41f1a471
|
177 178 179 180 |
struct dentry *xadir; int count; struct dentry *dentries[8]; }; |
bd4c625c0
|
181 |
|
a72bdb1cd
|
182 |
static int |
ac7576f4b
|
183 184 |
fill_with_dentries(struct dir_context *ctx, const char *name, int namelen, loff_t offset, u64 ino, unsigned int d_type) |
a72bdb1cd
|
185 |
{ |
ac7576f4b
|
186 187 |
struct reiserfs_dentry_buf *dbuf = container_of(ctx, struct reiserfs_dentry_buf, ctx); |
a72bdb1cd
|
188 |
struct dentry *dentry; |
f3fb9e273
|
189 |
|
5955102c9
|
190 |
WARN_ON_ONCE(!inode_is_locked(d_inode(dbuf->xadir))); |
bd4c625c0
|
191 |
|
a41f1a471
|
192 193 |
if (dbuf->count == ARRAY_SIZE(dbuf->dentries)) return -ENOSPC; |
bd4c625c0
|
194 |
|
35e5cbc0a
|
195 196 |
if (name[0] == '.' && (namelen < 2 || (namelen == 2 && name[1] == '.'))) |
a41f1a471
|
197 |
return 0; |
bd4c625c0
|
198 |
|
a41f1a471
|
199 |
dentry = lookup_one_len(name, dbuf->xadir, namelen); |
a72bdb1cd
|
200 |
if (IS_ERR(dentry)) { |
a41f1a471
|
201 |
return PTR_ERR(dentry); |
2b0143b5c
|
202 |
} else if (d_really_is_negative(dentry)) { |
a41f1a471
|
203 204 |
/* A directory entry exists, but no file? */ reiserfs_error(dentry->d_sb, "xattr-20003", |
a455589f1
|
205 206 207 208 |
"Corrupted directory: xattr %pd listed but " "not found for file %pd. ", dentry, dbuf->xadir); |
a41f1a471
|
209 210 |
dput(dentry); return -EIO; |
bd4c625c0
|
211 |
} |
1da177e4c
|
212 |
|
a41f1a471
|
213 214 |
dbuf->dentries[dbuf->count++] = dentry; return 0; |
1da177e4c
|
215 |
} |
a41f1a471
|
216 217 |
static void cleanup_dentry_buf(struct reiserfs_dentry_buf *buf) |
1da177e4c
|
218 |
{ |
a41f1a471
|
219 |
int i; |
f3fb9e273
|
220 |
|
a41f1a471
|
221 222 223 |
for (i = 0; i < buf->count; i++) if (buf->dentries[i]) dput(buf->dentries[i]); |
a72bdb1cd
|
224 |
} |
a41f1a471
|
225 226 227 |
static int reiserfs_for_each_xattr(struct inode *inode, int (*action)(struct dentry *, void *), void *data) |
a72bdb1cd
|
228 |
{ |
a41f1a471
|
229 230 |
struct dentry *dir; int i, err = 0; |
a41f1a471
|
231 |
struct reiserfs_dentry_buf buf = { |
4acf381e1
|
232 |
.ctx.actor = fill_with_dentries, |
a41f1a471
|
233 |
}; |
1da177e4c
|
234 |
|
a72bdb1cd
|
235 236 237 |
/* Skip out, an xattr has no xattrs associated with it */ if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) return 0; |
1da177e4c
|
238 |
|
6c17675e1
|
239 |
dir = open_xa_dir(inode, XATTR_REPLACE); |
a72bdb1cd
|
240 241 242 |
if (IS_ERR(dir)) { err = PTR_ERR(dir); goto out; |
2b0143b5c
|
243 |
} else if (d_really_is_negative(dir)) { |
a41f1a471
|
244 245 |
err = 0; goto out_dir; |
a72bdb1cd
|
246 |
} |
1da177e4c
|
247 |
|
5955102c9
|
248 |
inode_lock_nested(d_inode(dir), I_MUTEX_XATTR); |
27026a05b
|
249 |
|
a41f1a471
|
250 |
buf.xadir = dir; |
cd62cdae0
|
251 |
while (1) { |
2b0143b5c
|
252 |
err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx); |
cd62cdae0
|
253 254 255 256 257 |
if (err) break; if (!buf.count) break; for (i = 0; !err && i < buf.count && buf.dentries[i]; i++) { |
a41f1a471
|
258 |
struct dentry *dentry = buf.dentries[i]; |
1da177e4c
|
259 |
|
e36cb0b89
|
260 |
if (!d_is_dir(dentry)) |
cd62cdae0
|
261 |
err = action(dentry, data); |
1da177e4c
|
262 |
|
a41f1a471
|
263 264 |
dput(dentry); buf.dentries[i] = NULL; |
bd4c625c0
|
265 |
} |
cd62cdae0
|
266 267 |
if (err) break; |
a41f1a471
|
268 |
buf.count = 0; |
8b6dd72a4
|
269 |
} |
5955102c9
|
270 |
inode_unlock(d_inode(dir)); |
1da177e4c
|
271 |
|
a41f1a471
|
272 |
cleanup_dentry_buf(&buf); |
1da177e4c
|
273 |
|
d984561b3
|
274 |
if (!err) { |
098297b27
|
275 276 |
/* * We start a transaction here to avoid a ABBA situation |
a41f1a471
|
277 278 279 |
* between the xattr root's i_mutex and the journal lock. * This doesn't incur much additional overhead since the * new transaction will just nest inside the |
098297b27
|
280 281 |
* outer transaction. */ |
a41f1a471
|
282 283 284 |
int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 + 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb); struct reiserfs_transaction_handle th; |
f3fb9e273
|
285 |
|
4c05141df
|
286 |
reiserfs_write_lock(inode->i_sb); |
a41f1a471
|
287 |
err = journal_begin(&th, inode->i_sb, blocks); |
4c05141df
|
288 |
reiserfs_write_unlock(inode->i_sb); |
a41f1a471
|
289 290 |
if (!err) { int jerror; |
f3fb9e273
|
291 |
|
5955102c9
|
292 |
inode_lock_nested(d_inode(dir->d_parent), |
4c05141df
|
293 |
I_MUTEX_XATTR); |
a41f1a471
|
294 |
err = action(dir, data); |
4c05141df
|
295 |
reiserfs_write_lock(inode->i_sb); |
58d854265
|
296 |
jerror = journal_end(&th); |
4c05141df
|
297 |
reiserfs_write_unlock(inode->i_sb); |
5955102c9
|
298 |
inode_unlock(d_inode(dir->d_parent)); |
a41f1a471
|
299 300 |
err = jerror ?: err; } |
a72bdb1cd
|
301 |
} |
a41f1a471
|
302 303 |
out_dir: dput(dir); |
a72bdb1cd
|
304 |
out: |
a41f1a471
|
305 306 307 |
/* -ENODATA isn't an error */ if (err == -ENODATA) err = 0; |
a72bdb1cd
|
308 309 |
return err; } |
1da177e4c
|
310 |
|
a41f1a471
|
311 |
static int delete_one_xattr(struct dentry *dentry, void *data) |
a72bdb1cd
|
312 |
{ |
2b0143b5c
|
313 |
struct inode *dir = d_inode(dentry->d_parent); |
1da177e4c
|
314 |
|
a41f1a471
|
315 |
/* This is the xattr dir, handle specially. */ |
e36cb0b89
|
316 |
if (d_is_dir(dentry)) |
a41f1a471
|
317 |
return xattr_rmdir(dir, dentry); |
1da177e4c
|
318 |
|
a41f1a471
|
319 320 |
return xattr_unlink(dir, dentry); } |
bd4c625c0
|
321 |
|
a41f1a471
|
322 323 324 |
static int chown_one_xattr(struct dentry *dentry, void *data) { struct iattr *attrs = data; |
4a8570112
|
325 326 327 328 329 330 331 332 333 334 335 336 337 |
int ia_valid = attrs->ia_valid; int err; /* * We only want the ownership bits. Otherwise, we'll do * things like change a directory to a regular file if * ATTR_MODE is set. */ attrs->ia_valid &= (ATTR_UID|ATTR_GID); err = reiserfs_setattr(dentry, attrs); attrs->ia_valid = ia_valid; return err; |
a41f1a471
|
338 |
} |
1da177e4c
|
339 |
|
a41f1a471
|
340 341 342 343 |
/* No i_mutex, but the inode is unconnected. */ int reiserfs_delete_xattrs(struct inode *inode) { int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL); |
f3fb9e273
|
344 |
|
a41f1a471
|
345 346 347 348 |
if (err) reiserfs_warning(inode->i_sb, "jdm-20004", "Couldn't delete all xattrs (%d) ", err); |
a72bdb1cd
|
349 350 |
return err; } |
1da177e4c
|
351 |
|
a41f1a471
|
352 |
/* inode->i_mutex: down */ |
a72bdb1cd
|
353 354 |
int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) { |
a41f1a471
|
355 |
int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs); |
f3fb9e273
|
356 |
|
8b6dd72a4
|
357 358 359 360 |
if (err) reiserfs_warning(inode->i_sb, "jdm-20007", "Couldn't chown all xattrs (%d) ", err); |
a72bdb1cd
|
361 |
return err; |
1da177e4c
|
362 |
} |
a72bdb1cd
|
363 |
#ifdef CONFIG_REISERFS_FS_XATTR |
098297b27
|
364 365 |
/* * Returns a dentry corresponding to a specific extended attribute file |
a72bdb1cd
|
366 |
* for the inode. If flags allow, the file is created. Otherwise, a |
098297b27
|
367 368 |
* valid or negative dentry, or an error is returned. */ |
48b32a355
|
369 370 |
static struct dentry *xattr_lookup(struct inode *inode, const char *name, int flags) |
1da177e4c
|
371 |
{ |
a72bdb1cd
|
372 373 374 375 |
struct dentry *xadir, *xafile; int err = 0; xadir = open_xa_dir(inode, flags); |
6c17675e1
|
376 |
if (IS_ERR(xadir)) |
a72bdb1cd
|
377 |
return ERR_CAST(xadir); |
a72bdb1cd
|
378 |
|
5955102c9
|
379 |
inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR); |
a72bdb1cd
|
380 381 |
xafile = lookup_one_len(name, xadir, strlen(name)); if (IS_ERR(xafile)) { |
6c17675e1
|
382 383 |
err = PTR_ERR(xafile); goto out; |
bd4c625c0
|
384 |
} |
a72bdb1cd
|
385 |
|
2b0143b5c
|
386 |
if (d_really_is_positive(xafile) && (flags & XATTR_CREATE)) |
6c17675e1
|
387 |
err = -EEXIST; |
a72bdb1cd
|
388 |
|
2b0143b5c
|
389 |
if (d_really_is_negative(xafile)) { |
6c17675e1
|
390 |
err = -ENODATA; |
5a6059c35
|
391 |
if (xattr_may_create(flags)) |
2b0143b5c
|
392 |
err = xattr_create(d_inode(xadir), xafile, |
6c17675e1
|
393 |
0700|S_IFREG); |
a72bdb1cd
|
394 |
} |
6c17675e1
|
395 396 |
if (err) dput(xafile); |
a72bdb1cd
|
397 |
out: |
5955102c9
|
398 |
inode_unlock(d_inode(xadir)); |
a72bdb1cd
|
399 400 |
dput(xadir); if (err) |
6c17675e1
|
401 |
return ERR_PTR(err); |
a72bdb1cd
|
402 |
return xafile; |
1da177e4c
|
403 |
} |
1da177e4c
|
404 |
/* Internal operations on file data */ |
bd4c625c0
|
405 |
static inline void reiserfs_put_page(struct page *page) |
1da177e4c
|
406 |
{ |
bd4c625c0
|
407 |
kunmap(page); |
09cbfeaf1
|
408 |
put_page(page); |
1da177e4c
|
409 |
} |
ec6ea56b2
|
410 |
static struct page *reiserfs_get_page(struct inode *dir, size_t n) |
1da177e4c
|
411 |
{ |
bd4c625c0
|
412 413 |
struct address_space *mapping = dir->i_mapping; struct page *page; |
098297b27
|
414 415 416 417 |
/* * We can deadlock if we try to free dentries, * and an unlink/rmdir has just occurred - GFP_NOFS avoids this */ |
c4cdd0383
|
418 |
mapping_set_gfp_mask(mapping, GFP_NOFS); |
09cbfeaf1
|
419 |
page = read_mapping_page(mapping, n >> PAGE_SHIFT, NULL); |
bd4c625c0
|
420 |
if (!IS_ERR(page)) { |
bd4c625c0
|
421 |
kmap(page); |
bd4c625c0
|
422 423 424 425 |
if (PageError(page)) goto fail; } return page; |
cf776a7a4
|
426 |
fail: |
bd4c625c0
|
427 428 |
reiserfs_put_page(page); return ERR_PTR(-EIO); |
1da177e4c
|
429 |
} |
bd4c625c0
|
430 |
static inline __u32 xattr_hash(const char *msg, int len) |
1da177e4c
|
431 |
{ |
bd4c625c0
|
432 |
return csum_partial(msg, len, 0); |
1da177e4c
|
433 |
} |
ba9d8cec6
|
434 435 |
int reiserfs_commit_write(struct file *f, struct page *page, unsigned from, unsigned to); |
ba9d8cec6
|
436 |
|
48b32a355
|
437 438 439 |
static void update_ctime(struct inode *inode) { struct timespec now = current_fs_time(inode->i_sb); |
f3fb9e273
|
440 |
|
1d3382cbf
|
441 |
if (inode_unhashed(inode) || !inode->i_nlink || |
48b32a355
|
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
timespec_equal(&inode->i_ctime, &now)) return; inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); } static int lookup_and_delete_xattr(struct inode *inode, const char *name) { int err = 0; struct dentry *dentry, *xadir; xadir = open_xa_dir(inode, XATTR_REPLACE); if (IS_ERR(xadir)) return PTR_ERR(xadir); |
5955102c9
|
457 |
inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR); |
48b32a355
|
458 459 460 461 462 |
dentry = lookup_one_len(name, xadir, strlen(name)); if (IS_ERR(dentry)) { err = PTR_ERR(dentry); goto out_dput; } |
2b0143b5c
|
463 464 |
if (d_really_is_positive(dentry)) { err = xattr_unlink(d_inode(xadir), dentry); |
48b32a355
|
465 466 467 468 469 |
update_ctime(inode); } dput(dentry); out_dput: |
5955102c9
|
470 |
inode_unlock(d_inode(xadir)); |
48b32a355
|
471 472 473 |
dput(xadir); return err; } |
ba9d8cec6
|
474 |
|
1da177e4c
|
475 476 477 |
/* Generic extended attribute operations that can be used by xa plugins */ /* |
1b1dcc1b5
|
478 |
* inode->i_mutex: down |
1da177e4c
|
479 480 |
*/ int |
0ab2621eb
|
481 482 483 |
reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th, struct inode *inode, const char *name, const void *buffer, size_t buffer_size, int flags) |
1da177e4c
|
484 |
{ |
bd4c625c0
|
485 |
int err = 0; |
3227e14c3
|
486 |
struct dentry *dentry; |
bd4c625c0
|
487 488 |
struct page *page; char *data; |
bd4c625c0
|
489 490 |
size_t file_pos = 0; size_t buffer_pos = 0; |
48b32a355
|
491 |
size_t new_size; |
bd4c625c0
|
492 |
__u32 xahash = 0; |
bd4c625c0
|
493 494 |
if (get_inode_sd_version(inode) == STAT_DATA_V1) return -EOPNOTSUPP; |
4f3be1b5a
|
495 496 |
if (!buffer) { err = lookup_and_delete_xattr(inode, name); |
4f3be1b5a
|
497 498 |
return err; } |
48b32a355
|
499 |
dentry = xattr_lookup(inode, name, flags); |
4c05141df
|
500 |
if (IS_ERR(dentry)) |
48b32a355
|
501 |
return PTR_ERR(dentry); |
3f14fea6b
|
502 |
|
f3e22f48f
|
503 |
down_write(&REISERFS_I(inode)->i_xattr_sem); |
bd4c625c0
|
504 |
|
8b6dd72a4
|
505 |
xahash = xattr_hash(buffer, buffer_size); |
bd4c625c0
|
506 507 508 |
while (buffer_pos < buffer_size || buffer_pos == 0) { size_t chunk; size_t skip = 0; |
09cbfeaf1
|
509 |
size_t page_offset = (file_pos & (PAGE_SIZE - 1)); |
f3fb9e273
|
510 |
|
09cbfeaf1
|
511 512 |
if (buffer_size - buffer_pos > PAGE_SIZE) chunk = PAGE_SIZE; |
bd4c625c0
|
513 514 |
else chunk = buffer_size - buffer_pos; |
2b0143b5c
|
515 |
page = reiserfs_get_page(d_inode(dentry), file_pos); |
bd4c625c0
|
516 517 |
if (IS_ERR(page)) { err = PTR_ERR(page); |
48b32a355
|
518 |
goto out_unlock; |
bd4c625c0
|
519 520 521 522 523 524 525 |
} lock_page(page); data = page_address(page); if (file_pos == 0) { struct reiserfs_xattr_header *rxh; |
f3fb9e273
|
526 |
|
bd4c625c0
|
527 |
skip = file_pos = sizeof(struct reiserfs_xattr_header); |
09cbfeaf1
|
528 529 |
if (chunk + skip > PAGE_SIZE) chunk = PAGE_SIZE - skip; |
bd4c625c0
|
530 531 532 533 |
rxh = (struct reiserfs_xattr_header *)data; rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC); rxh->h_hash = cpu_to_le32(xahash); } |
4c05141df
|
534 |
reiserfs_write_lock(inode->i_sb); |
ebdec241d
|
535 |
err = __reiserfs_write_begin(page, page_offset, chunk + skip); |
bd4c625c0
|
536 537 538 |
if (!err) { if (buffer) memcpy(data + skip, buffer + buffer_pos, chunk); |
3227e14c3
|
539 540 541 |
err = reiserfs_commit_write(NULL, page, page_offset, page_offset + chunk + skip); |
bd4c625c0
|
542 |
} |
4c05141df
|
543 |
reiserfs_write_unlock(inode->i_sb); |
bd4c625c0
|
544 545 546 547 548 549 550 551 |
unlock_page(page); reiserfs_put_page(page); buffer_pos += chunk; file_pos += chunk; skip = 0; if (err || buffer_size == 0 || !buffer) break; } |
48b32a355
|
552 |
new_size = buffer_size + sizeof(struct reiserfs_xattr_header); |
2b0143b5c
|
553 |
if (!err && new_size < i_size_read(d_inode(dentry))) { |
48b32a355
|
554 555 |
struct iattr newattrs = { .ia_ctime = current_fs_time(inode->i_sb), |
fb2162df7
|
556 |
.ia_size = new_size, |
48b32a355
|
557 558 |
.ia_valid = ATTR_SIZE | ATTR_CTIME, }; |
31370f62b
|
559 |
|
5955102c9
|
560 |
inode_lock_nested(d_inode(dentry), I_MUTEX_XATTR); |
2b0143b5c
|
561 |
inode_dio_wait(d_inode(dentry)); |
31370f62b
|
562 |
|
48b32a355
|
563 |
err = reiserfs_setattr(dentry, &newattrs); |
5955102c9
|
564 |
inode_unlock(d_inode(dentry)); |
48b32a355
|
565 566 567 |
} else update_ctime(inode); out_unlock: |
8b6dd72a4
|
568 |
up_write(&REISERFS_I(inode)->i_xattr_sem); |
3227e14c3
|
569 |
dput(dentry); |
48b32a355
|
570 571 |
return err; } |
bd4c625c0
|
572 |
|
0ab2621eb
|
573 574 575 |
/* We need to start a transaction to maintain lock ordering */ int reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer, size_t buffer_size, int flags) |
48b32a355
|
576 |
{ |
0ab2621eb
|
577 578 579 580 581 582 583 584 585 586 |
struct reiserfs_transaction_handle th; int error, error2; size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size); if (!(flags & XATTR_REPLACE)) jbegin_count += reiserfs_xattr_jcreate_nblocks(inode); reiserfs_write_lock(inode->i_sb); error = journal_begin(&th, inode->i_sb, jbegin_count); |
4c05141df
|
587 |
reiserfs_write_unlock(inode->i_sb); |
0ab2621eb
|
588 |
if (error) { |
0ab2621eb
|
589 |
return error; |
1da177e4c
|
590 |
} |
bd4c625c0
|
591 |
|
0ab2621eb
|
592 593 |
error = reiserfs_xattr_set_handle(&th, inode, name, buffer, buffer_size, flags); |
bd4c625c0
|
594 |
|
4c05141df
|
595 |
reiserfs_write_lock(inode->i_sb); |
58d854265
|
596 |
error2 = journal_end(&th); |
4c05141df
|
597 |
reiserfs_write_unlock(inode->i_sb); |
0ab2621eb
|
598 599 |
if (error == 0) error = error2; |
0ab2621eb
|
600 601 |
return error; |
1da177e4c
|
602 603 604 |
} /* |
1b1dcc1b5
|
605 |
* inode->i_mutex: down |
1da177e4c
|
606 607 |
*/ int |
48b32a355
|
608 |
reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer, |
bd4c625c0
|
609 |
size_t buffer_size) |
1da177e4c
|
610 |
{ |
bd4c625c0
|
611 |
ssize_t err = 0; |
3227e14c3
|
612 |
struct dentry *dentry; |
bd4c625c0
|
613 614 615 616 |
size_t isize; size_t file_pos = 0; size_t buffer_pos = 0; struct page *page; |
bd4c625c0
|
617 618 619 620 |
__u32 hash = 0; if (name == NULL) return -EINVAL; |
098297b27
|
621 622 623 624 |
/* * We can't have xattrs attached to v1 items since they don't have * generation numbers */ |
bd4c625c0
|
625 626 |
if (get_inode_sd_version(inode) == STAT_DATA_V1) return -EOPNOTSUPP; |
48b32a355
|
627 |
dentry = xattr_lookup(inode, name, XATTR_REPLACE); |
3227e14c3
|
628 629 |
if (IS_ERR(dentry)) { err = PTR_ERR(dentry); |
bd4c625c0
|
630 631 |
goto out; } |
8b6dd72a4
|
632 |
down_read(&REISERFS_I(inode)->i_xattr_sem); |
d984561b3
|
633 |
|
2b0143b5c
|
634 |
isize = i_size_read(d_inode(dentry)); |
bd4c625c0
|
635 636 637 638 |
/* Just return the size needed */ if (buffer == NULL) { err = isize - sizeof(struct reiserfs_xattr_header); |
8b6dd72a4
|
639 |
goto out_unlock; |
bd4c625c0
|
640 641 642 643 |
} if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) { err = -ERANGE; |
8b6dd72a4
|
644 |
goto out_unlock; |
bd4c625c0
|
645 646 647 648 649 650 |
} while (file_pos < isize) { size_t chunk; char *data; size_t skip = 0; |
f3fb9e273
|
651 |
|
09cbfeaf1
|
652 653 |
if (isize - file_pos > PAGE_SIZE) chunk = PAGE_SIZE; |
bd4c625c0
|
654 655 |
else chunk = isize - file_pos; |
2b0143b5c
|
656 |
page = reiserfs_get_page(d_inode(dentry), file_pos); |
bd4c625c0
|
657 658 |
if (IS_ERR(page)) { err = PTR_ERR(page); |
8b6dd72a4
|
659 |
goto out_unlock; |
bd4c625c0
|
660 661 662 663 664 665 666 667 668 669 670 671 672 |
} lock_page(page); data = page_address(page); if (file_pos == 0) { struct reiserfs_xattr_header *rxh = (struct reiserfs_xattr_header *)data; skip = file_pos = sizeof(struct reiserfs_xattr_header); chunk -= skip; /* Magic doesn't match up.. */ if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) { unlock_page(page); reiserfs_put_page(page); |
a72bdb1cd
|
673 |
reiserfs_warning(inode->i_sb, "jdm-20001", |
bd4c625c0
|
674 675 676 677 |
"Invalid magic for xattr (%s) " "associated with %k", name, INODE_PKEY(inode)); err = -EIO; |
8b6dd72a4
|
678 |
goto out_unlock; |
bd4c625c0
|
679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
} hash = le32_to_cpu(rxh->h_hash); } memcpy(buffer + buffer_pos, data + skip, chunk); unlock_page(page); reiserfs_put_page(page); file_pos += chunk; buffer_pos += chunk; skip = 0; } err = isize - sizeof(struct reiserfs_xattr_header); if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) != hash) { |
a72bdb1cd
|
693 |
reiserfs_warning(inode->i_sb, "jdm-20002", |
bd4c625c0
|
694 695 696 697 |
"Invalid hash for xattr (%s) associated " "with %k", name, INODE_PKEY(inode)); err = -EIO; } |
8b6dd72a4
|
698 699 |
out_unlock: up_read(&REISERFS_I(inode)->i_xattr_sem); |
3227e14c3
|
700 |
dput(dentry); |
bd4c625c0
|
701 |
|
a72bdb1cd
|
702 |
out: |
bd4c625c0
|
703 |
return err; |
1da177e4c
|
704 |
} |
48b32a355
|
705 706 707 708 709 710 711 712 713 714 715 716 717 |
/* * In order to implement different sets of xattr operations for each xattr * prefix with the generic xattr API, a filesystem should create a * null-terminated array of struct xattr_handler (one for each prefix) and * hang a pointer to it off of the s_xattr field of the superblock. * * The generic_fooxattr() functions will use this list to dispatch xattr * operations to the correct xattr_handler. */ #define for_each_xattr_handler(handlers, handler) \ for ((handler) = *(handlers)++; \ (handler) != NULL; \ (handler) = *(handlers)++) |
1da177e4c
|
718 |
|
48b32a355
|
719 |
/* This is the implementation for the xattr plugin infrastructure */ |
94d09a98c
|
720 721 |
static inline const struct xattr_handler * find_xattr_handler_prefix(const struct xattr_handler **handlers, |
48b32a355
|
722 |
const char *name) |
1da177e4c
|
723 |
{ |
94d09a98c
|
724 |
const struct xattr_handler *xah; |
bd4c625c0
|
725 |
|
48b32a355
|
726 727 |
if (!handlers) return NULL; |
bd4c625c0
|
728 |
|
48b32a355
|
729 |
for_each_xattr_handler(handlers, xah) { |
98e9cb571
|
730 731 |
const char *prefix = xattr_prefix(xah); if (strncmp(prefix, name, strlen(prefix)) == 0) |
48b32a355
|
732 |
break; |
bd4c625c0
|
733 |
} |
48b32a355
|
734 |
return xah; |
bd4c625c0
|
735 |
} |
1da177e4c
|
736 |
|
1da177e4c
|
737 738 739 |
/* * Inode operation getxattr() |
1da177e4c
|
740 741 |
*/ ssize_t |
bd4c625c0
|
742 743 |
reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, size_t size) |
1da177e4c
|
744 |
{ |
94d09a98c
|
745 |
const struct xattr_handler *handler; |
bd4c625c0
|
746 |
|
431547b3c
|
747 |
handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); |
48b32a355
|
748 |
|
2b0143b5c
|
749 |
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) |
bd4c625c0
|
750 |
return -EOPNOTSUPP; |
d9a82a040
|
751 |
return handler->get(handler, dentry, name, buffer, size); |
1da177e4c
|
752 |
} |
1da177e4c
|
753 754 755 |
/* * Inode operation setxattr() * |
2b0143b5c
|
756 |
* d_inode(dentry)->i_mutex down |
1da177e4c
|
757 758 |
*/ int |
bd4c625c0
|
759 760 |
reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) |
1da177e4c
|
761 |
{ |
94d09a98c
|
762 |
const struct xattr_handler *handler; |
bd4c625c0
|
763 |
|
431547b3c
|
764 |
handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); |
48b32a355
|
765 |
|
2b0143b5c
|
766 |
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) |
bd4c625c0
|
767 |
return -EOPNOTSUPP; |
d9a82a040
|
768 |
return handler->set(handler, dentry, name, value, size, flags); |
1da177e4c
|
769 770 771 772 773 |
} /* * Inode operation removexattr() * |
2b0143b5c
|
774 |
* d_inode(dentry)->i_mutex down |
1da177e4c
|
775 |
*/ |
bd4c625c0
|
776 |
int reiserfs_removexattr(struct dentry *dentry, const char *name) |
1da177e4c
|
777 |
{ |
94d09a98c
|
778 |
const struct xattr_handler *handler; |
f3fb9e273
|
779 |
|
431547b3c
|
780 |
handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); |
1da177e4c
|
781 |
|
2b0143b5c
|
782 |
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) |
bd4c625c0
|
783 |
return -EOPNOTSUPP; |
1da177e4c
|
784 |
|
d9a82a040
|
785 |
return handler->set(handler, dentry, name, NULL, 0, XATTR_REPLACE); |
1da177e4c
|
786 |
} |
48b32a355
|
787 |
struct listxattr_buf { |
4acf381e1
|
788 |
struct dir_context ctx; |
48b32a355
|
789 790 791 |
size_t size; size_t pos; char *buf; |
431547b3c
|
792 |
struct dentry *dentry; |
1da177e4c
|
793 |
}; |
ac7576f4b
|
794 795 796 |
static int listxattr_filler(struct dir_context *ctx, const char *name, int namelen, loff_t offset, u64 ino, unsigned int d_type) |
1da177e4c
|
797 |
{ |
ac7576f4b
|
798 799 |
struct listxattr_buf *b = container_of(ctx, struct listxattr_buf, ctx); |
48b32a355
|
800 |
size_t size; |
f3fb9e273
|
801 |
|
48b32a355
|
802 803 |
if (name[0] != '.' || (namelen != 1 && (name[1] != '.' || namelen != 2))) { |
94d09a98c
|
804 |
const struct xattr_handler *handler; |
f3fb9e273
|
805 |
|
431547b3c
|
806 |
handler = find_xattr_handler_prefix(b->dentry->d_sb->s_xattr, |
48b32a355
|
807 |
name); |
764a5c6b1
|
808 809 |
if (!handler /* Unsupported xattr name */ || (handler->list && !handler->list(b->dentry))) |
48b32a355
|
810 |
return 0; |
764a5c6b1
|
811 |
size = namelen + 1; |
48b32a355
|
812 |
if (b->buf) { |
48b32a355
|
813 814 |
if (size > b->size) return -ERANGE; |
764a5c6b1
|
815 816 |
memcpy(b->buf + b->pos, name, namelen); b->buf[b->pos + namelen] = 0; |
bd4c625c0
|
817 |
} |
48b32a355
|
818 819 |
b->pos += size; } |
bd4c625c0
|
820 |
return 0; |
1da177e4c
|
821 |
} |
bd4c625c0
|
822 |
|
1da177e4c
|
823 824 825 |
/* * Inode operation listxattr() * |
48b32a355
|
826 827 828 |
* We totally ignore the generic listxattr here because it would be stupid * not to. Since the xattrs are organized in a directory, we can just * readdir to find them. |
1da177e4c
|
829 |
*/ |
bd4c625c0
|
830 |
ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) |
1da177e4c
|
831 |
{ |
bd4c625c0
|
832 833 |
struct dentry *dir; int err = 0; |
48b32a355
|
834 |
struct listxattr_buf buf = { |
4acf381e1
|
835 |
.ctx.actor = listxattr_filler, |
431547b3c
|
836 |
.dentry = dentry, |
48b32a355
|
837 838 839 |
.buf = buffer, .size = buffer ? size : 0, }; |
bd4c625c0
|
840 |
|
2b0143b5c
|
841 |
if (d_really_is_negative(dentry)) |
bd4c625c0
|
842 |
return -EINVAL; |
677c9b2e3
|
843 |
if (!dentry->d_sb->s_xattr || |
2b0143b5c
|
844 |
get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) |
bd4c625c0
|
845 |
return -EOPNOTSUPP; |
2b0143b5c
|
846 |
dir = open_xa_dir(d_inode(dentry), XATTR_REPLACE); |
bd4c625c0
|
847 848 849 |
if (IS_ERR(dir)) { err = PTR_ERR(dir); if (err == -ENODATA) |
48b32a355
|
850 |
err = 0; /* Not an error if there aren't any xattrs */ |
bd4c625c0
|
851 852 |
goto out; } |
5955102c9
|
853 |
inode_lock_nested(d_inode(dir), I_MUTEX_XATTR); |
2b0143b5c
|
854 |
err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx); |
5955102c9
|
855 |
inode_unlock(d_inode(dir)); |
bd4c625c0
|
856 |
|
48b32a355
|
857 858 |
if (!err) err = buf.pos; |
bd4c625c0
|
859 |
|
3227e14c3
|
860 |
dput(dir); |
8b6dd72a4
|
861 |
out: |
bd4c625c0
|
862 |
return err; |
1da177e4c
|
863 |
} |
a72bdb1cd
|
864 |
static int create_privroot(struct dentry *dentry) |
1da177e4c
|
865 |
{ |
a72bdb1cd
|
866 |
int err; |
2b0143b5c
|
867 |
struct inode *inode = d_inode(dentry->d_parent); |
f3fb9e273
|
868 |
|
5955102c9
|
869 |
WARN_ON_ONCE(!inode_is_locked(inode)); |
5a6059c35
|
870 |
|
6c17675e1
|
871 |
err = xattr_mkdir(inode, dentry, 0700); |
2b0143b5c
|
872 |
if (err || d_really_is_negative(dentry)) { |
edcc37a04
|
873 874 875 876 877 |
reiserfs_warning(dentry->d_sb, "jdm-20006", "xattrs/ACLs enabled and couldn't " "find/create .reiserfs_priv. " "Failing mount."); return -EOPNOTSUPP; |
bd4c625c0
|
878 |
} |
2b0143b5c
|
879 |
d_inode(dentry)->i_flags |= S_PRIVATE; |
edcc37a04
|
880 881 882 |
reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr " "storage. ", PRIVROOT_NAME); |
bd4c625c0
|
883 |
|
edcc37a04
|
884 |
return 0; |
1da177e4c
|
885 |
} |
12abb35a0
|
886 887 888 889 890 891 892 |
#else int __init reiserfs_xattr_register_handlers(void) { return 0; } void reiserfs_xattr_unregister_handlers(void) {} static int create_privroot(struct dentry *dentry) { return 0; } #endif /* Actual operations that are exported to VFS-land */ |
da02eb72f
|
893 |
static const struct xattr_handler *reiserfs_xattr_handlers[] = { |
12abb35a0
|
894 895 896 897 898 899 900 901 |
#ifdef CONFIG_REISERFS_FS_XATTR &reiserfs_xattr_user_handler, &reiserfs_xattr_trusted_handler, #endif #ifdef CONFIG_REISERFS_FS_SECURITY &reiserfs_xattr_security_handler, #endif #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
47f70d08f
|
902 903 |
&posix_acl_access_xattr_handler, &posix_acl_default_xattr_handler, |
12abb35a0
|
904 905 906 |
#endif NULL }; |
a72bdb1cd
|
907 |
static int xattr_mount_check(struct super_block *s) |
1da177e4c
|
908 |
{ |
098297b27
|
909 910 911 912 |
/* * We need generation numbers to ensure that the oid mapping is correct * v3.5 filesystems don't have them. */ |
48b32a355
|
913 914 |
if (old_format_only(s)) { if (reiserfs_xattrs_optional(s)) { |
098297b27
|
915 916 917 918 |
/* * Old format filesystem, but optional xattrs have * been enabled. Error out. */ |
48b32a355
|
919 920 921 922 923 924 |
reiserfs_warning(s, "jdm-2005", "xattrs/ACLs not supported " "on pre-v3.6 format filesystems. " "Failing mount."); return -EOPNOTSUPP; } |
a72bdb1cd
|
925 926 927 |
} return 0; |
1da177e4c
|
928 |
} |
10556cb21
|
929 |
int reiserfs_permission(struct inode *inode, int mask) |
b83674c0d
|
930 931 932 933 934 935 936 |
{ /* * We don't do permission checks on the internal objects. * Permissions are determined by the "owning" object. */ if (IS_PRIVATE(inode)) return 0; |
2830ba7f3
|
937 |
return generic_permission(inode, mask); |
b83674c0d
|
938 |
} |
0b728e191
|
939 |
static int xattr_hide_revalidate(struct dentry *dentry, unsigned int flags) |
1da177e4c
|
940 |
{ |
cac36f707
|
941 |
return -EPERM; |
1da177e4c
|
942 |
} |
e16404ed0
|
943 |
static const struct dentry_operations xattr_lookup_poison_ops = { |
cac36f707
|
944 |
.d_revalidate = xattr_hide_revalidate, |
1da177e4c
|
945 |
}; |
edcc37a04
|
946 947 948 949 950 951 |
int reiserfs_lookup_privroot(struct super_block *s) { struct dentry *dentry; int err = 0; /* If we don't have the privroot located yet - go find it */ |
5955102c9
|
952 |
inode_lock(d_inode(s->s_root)); |
edcc37a04
|
953 954 955 956 |
dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, strlen(PRIVROOT_NAME)); if (!IS_ERR(dentry)) { REISERFS_SB(s)->priv_root = dentry; |
fb045adb9
|
957 |
d_set_d_op(dentry, &xattr_lookup_poison_ops); |
2b0143b5c
|
958 959 |
if (d_really_is_positive(dentry)) d_inode(dentry)->i_flags |= S_PRIVATE; |
edcc37a04
|
960 961 |
} else err = PTR_ERR(dentry); |
5955102c9
|
962 |
inode_unlock(d_inode(s->s_root)); |
edcc37a04
|
963 964 965 |
return err; } |
098297b27
|
966 967 |
/* * We need to take a copy of the mount flags since things like |
1da177e4c
|
968 |
* MS_RDONLY don't get set until *after* we're called. |
098297b27
|
969 970 |
* mount_flags != mount_options */ |
bd4c625c0
|
971 |
int reiserfs_xattr_init(struct super_block *s, int mount_flags) |
1da177e4c
|
972 |
{ |
bd4c625c0
|
973 |
int err = 0; |
ab17c4f02
|
974 |
struct dentry *privroot = REISERFS_SB(s)->priv_root; |
bd4c625c0
|
975 |
|
a72bdb1cd
|
976 977 |
err = xattr_mount_check(s); if (err) |
bd4c625c0
|
978 |
goto error; |
bd4c625c0
|
979 |
|
2b0143b5c
|
980 |
if (d_really_is_negative(privroot) && !(mount_flags & MS_RDONLY)) { |
5955102c9
|
981 |
inode_lock(d_inode(s->s_root)); |
edcc37a04
|
982 |
err = create_privroot(REISERFS_SB(s)->priv_root); |
5955102c9
|
983 |
inode_unlock(d_inode(s->s_root)); |
bd4c625c0
|
984 |
} |
ab17c4f02
|
985 |
|
2b0143b5c
|
986 |
if (d_really_is_positive(privroot)) { |
48b32a355
|
987 |
s->s_xattr = reiserfs_xattr_handlers; |
5955102c9
|
988 |
inode_lock(d_inode(privroot)); |
ab17c4f02
|
989 990 |
if (!REISERFS_SB(s)->xattr_root) { struct dentry *dentry; |
f3fb9e273
|
991 |
|
ab17c4f02
|
992 993 994 995 996 997 998 |
dentry = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME)); if (!IS_ERR(dentry)) REISERFS_SB(s)->xattr_root = dentry; else err = PTR_ERR(dentry); } |
5955102c9
|
999 |
inode_unlock(d_inode(privroot)); |
ab17c4f02
|
1000 |
} |
48b32a355
|
1001 |
|
a72bdb1cd
|
1002 |
error: |
bd4c625c0
|
1003 |
if (err) { |
a228bf8f0
|
1004 1005 |
clear_bit(REISERFS_XATTRS_USER, &REISERFS_SB(s)->s_mount_opt); clear_bit(REISERFS_POSIXACL, &REISERFS_SB(s)->s_mount_opt); |
bd4c625c0
|
1006 1007 1008 |
} /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */ |
bd4c625c0
|
1009 1010 |
if (reiserfs_posixacl(s)) s->s_flags |= MS_POSIXACL; |
ab17c4f02
|
1011 |
else |
ab17c4f02
|
1012 |
s->s_flags &= ~MS_POSIXACL; |
bd4c625c0
|
1013 1014 |
return err; |
1da177e4c
|
1015 |
} |