blob: 613ff5aef94ea014caa87d52ae8c03d9c88e5bdd [file] [log] [blame]
Al Viroc45ac882012-03-17 00:59:06 -04001#include <linux/reiserfs_xattr.h>
2#include <linux/init.h>
3#include <linux/list.h>
4#include <linux/rwsem.h>
Al Viro79a628d2016-04-10 18:50:48 -04005#include <linux/xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -04006
7struct inode;
8struct dentry;
9struct iattr;
10struct super_block;
Al Viroc45ac882012-03-17 00:59:06 -040011
12int reiserfs_xattr_register_handlers(void) __init;
13void reiserfs_xattr_unregister_handlers(void);
14int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
15int reiserfs_lookup_privroot(struct super_block *sb);
16int reiserfs_delete_xattrs(struct inode *inode);
17int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
18int reiserfs_permission(struct inode *inode, int mask);
19
20#ifdef CONFIG_REISERFS_FS_XATTR
21#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
Al Viroc45ac882012-03-17 00:59:06 -040022ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
Al Viroc45ac882012-03-17 00:59:06 -040023
24int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
25int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
26int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
27 struct inode *, const char *, const void *,
28 size_t, int);
29
30extern const struct xattr_handler reiserfs_xattr_user_handler;
31extern const struct xattr_handler reiserfs_xattr_trusted_handler;
32extern const struct xattr_handler reiserfs_xattr_security_handler;
33#ifdef CONFIG_REISERFS_FS_SECURITY
34int reiserfs_security_init(struct inode *dir, struct inode *inode,
35 const struct qstr *qstr,
36 struct reiserfs_security_handle *sec);
37int reiserfs_security_write(struct reiserfs_transaction_handle *th,
38 struct inode *inode,
39 struct reiserfs_security_handle *sec);
40void reiserfs_security_free(struct reiserfs_security_handle *sec);
41#endif
42
43static inline int reiserfs_xattrs_initialized(struct super_block *sb)
44{
45 return REISERFS_SB(sb)->priv_root != NULL;
46}
47
48#define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
49static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
50{
51 loff_t ret = 0;
52 if (reiserfs_file_data_log(inode)) {
53 ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
54 ret >>= inode->i_sb->s_blocksize_bits;
55 }
56 return ret;
57}
58
Jeff Mahoney098297b2014-04-23 10:00:36 -040059/*
60 * We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
Al Viroc45ac882012-03-17 00:59:06 -040061 * Let's try to be smart about it.
62 * xattr root: We cache it. If it's not cached, we may need to create it.
63 * xattr dir: If anything has been loaded for this inode, we can set a flag
64 * saying so.
65 * xattr file: Since we don't cache xattrs, we can't tell. We always include
66 * blocks for it.
67 *
68 * However, since root and dir can be created between calls - YOU MUST SAVE
69 * THIS VALUE.
70 */
71static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
72{
73 size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
74
75 if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
76 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
David Howells2b0143b2015-03-17 22:25:59 +000077 if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
Al Viroc45ac882012-03-17 00:59:06 -040078 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
79 }
80
81 return nblocks;
82}
83
84static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
85{
86 init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
87}
88
89#else
90
Al Viroc45ac882012-03-17 00:59:06 -040091#define reiserfs_listxattr NULL
Al Viroc45ac882012-03-17 00:59:06 -040092
93static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
94{
95}
96#endif /* CONFIG_REISERFS_FS_XATTR */
97
98#ifndef CONFIG_REISERFS_FS_SECURITY
99static inline int reiserfs_security_init(struct inode *dir,
100 struct inode *inode,
101 const struct qstr *qstr,
102 struct reiserfs_security_handle *sec)
103{
104 return 0;
105}
106static inline int
107reiserfs_security_write(struct reiserfs_transaction_handle *th,
108 struct inode *inode,
109 struct reiserfs_security_handle *sec)
110{
111 return 0;
112}
113static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
114{}
115#endif