xref: /linux/fs/reiserfs/xattr.h (revision f3a8b6645dc2e60d11f20c1c23afd964ff4e55ae)
1 #include <linux/reiserfs_xattr.h>
2 #include <linux/init.h>
3 #include <linux/list.h>
4 #include <linux/rwsem.h>
5 #include <linux/xattr.h>
6 
7 struct inode;
8 struct dentry;
9 struct iattr;
10 struct super_block;
11 
12 int reiserfs_xattr_register_handlers(void) __init;
13 void reiserfs_xattr_unregister_handlers(void);
14 int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
15 int reiserfs_lookup_privroot(struct super_block *sb);
16 int reiserfs_delete_xattrs(struct inode *inode);
17 int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
18 int 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)
22 ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
23 
24 int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
25 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
26 int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
27 			      struct inode *, const char *, const void *,
28 			      size_t, int);
29 
30 extern const struct xattr_handler reiserfs_xattr_user_handler;
31 extern const struct xattr_handler reiserfs_xattr_trusted_handler;
32 extern const struct xattr_handler reiserfs_xattr_security_handler;
33 #ifdef CONFIG_REISERFS_FS_SECURITY
34 int reiserfs_security_init(struct inode *dir, struct inode *inode,
35 			   const struct qstr *qstr,
36 			   struct reiserfs_security_handle *sec);
37 int reiserfs_security_write(struct reiserfs_transaction_handle *th,
38 			    struct inode *inode,
39 			    struct reiserfs_security_handle *sec);
40 void reiserfs_security_free(struct reiserfs_security_handle *sec);
41 #endif
42 
43 static 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))
49 static 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 
59 /*
60  * We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
61  * 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  */
71 static 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);
77 		if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
78 			nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
79 	}
80 
81 	return nblocks;
82 }
83 
84 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
85 {
86 	init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
87 }
88 
89 #else
90 
91 #define reiserfs_listxattr NULL
92 
93 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
94 {
95 }
96 #endif  /*  CONFIG_REISERFS_FS_XATTR  */
97 
98 #ifndef CONFIG_REISERFS_FS_SECURITY
99 static 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 }
106 static inline int
107 reiserfs_security_write(struct reiserfs_transaction_handle *th,
108 			struct inode *inode,
109 			struct reiserfs_security_handle *sec)
110 {
111 	return 0;
112 }
113 static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
114 {}
115 #endif
116