1 /*
2   File: linux/reiserfs_xattr.h
3 */
4 
5 #ifndef _LINUX_REISERFS_XATTR_H
6 #define _LINUX_REISERFS_XATTR_H
7 
8 #include <linux/types.h>
9 
10 /* Magic value in header */
11 #define REISERFS_XATTR_MAGIC 0x52465841	/* "RFXA" */
12 
13 struct reiserfs_xattr_header {
14 	__le32 h_magic;		/* magic number for identification */
15 	__le32 h_hash;		/* hash of the value */
16 };
17 
18 struct reiserfs_security_handle {
19 	char *name;
20 	void *value;
21 	size_t length;
22 };
23 
24 #ifdef __KERNEL__
25 
26 #include <linux/init.h>
27 #include <linux/list.h>
28 #include <linux/rwsem.h>
29 #include <linux/reiserfs_fs_i.h>
30 #include <linux/reiserfs_fs.h>
31 
32 struct inode;
33 struct dentry;
34 struct iattr;
35 struct super_block;
36 struct nameidata;
37 
38 int reiserfs_xattr_register_handlers(void) __init;
39 void reiserfs_xattr_unregister_handlers(void);
40 int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
41 int reiserfs_lookup_privroot(struct super_block *sb);
42 int reiserfs_delete_xattrs(struct inode *inode);
43 int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
44 int reiserfs_permission(struct inode *inode, int mask);
45 
46 #ifdef CONFIG_REISERFS_FS_XATTR
47 #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
48 ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name,
49 			  void *buffer, size_t size);
50 int reiserfs_setxattr(struct dentry *dentry, const char *name,
51 		      const void *value, size_t size, int flags);
52 ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
53 int reiserfs_removexattr(struct dentry *dentry, const char *name);
54 
55 int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
56 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
57 int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
58 			      struct inode *, const char *, const void *,
59 			      size_t, int);
60 
61 extern const struct xattr_handler reiserfs_xattr_user_handler;
62 extern const struct xattr_handler reiserfs_xattr_trusted_handler;
63 extern const struct xattr_handler reiserfs_xattr_security_handler;
64 #ifdef CONFIG_REISERFS_FS_SECURITY
65 int reiserfs_security_init(struct inode *dir, struct inode *inode,
66 			   const struct qstr *qstr,
67 			   struct reiserfs_security_handle *sec);
68 int reiserfs_security_write(struct reiserfs_transaction_handle *th,
69 			    struct inode *inode,
70 			    struct reiserfs_security_handle *sec);
71 void reiserfs_security_free(struct reiserfs_security_handle *sec);
72 #endif
73 
reiserfs_xattrs_initialized(struct super_block * sb)74 static inline int reiserfs_xattrs_initialized(struct super_block *sb)
75 {
76 	return REISERFS_SB(sb)->priv_root != NULL;
77 }
78 
79 #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
reiserfs_xattr_nblocks(struct inode * inode,loff_t size)80 static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
81 {
82 	loff_t ret = 0;
83 	if (reiserfs_file_data_log(inode)) {
84 		ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
85 		ret >>= inode->i_sb->s_blocksize_bits;
86 	}
87 	return ret;
88 }
89 
90 /* We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
91  * Let's try to be smart about it.
92  * xattr root: We cache it. If it's not cached, we may need to create it.
93  * xattr dir: If anything has been loaded for this inode, we can set a flag
94  *            saying so.
95  * xattr file: Since we don't cache xattrs, we can't tell. We always include
96  *             blocks for it.
97  *
98  * However, since root and dir can be created between calls - YOU MUST SAVE
99  * THIS VALUE.
100  */
reiserfs_xattr_jcreate_nblocks(struct inode * inode)101 static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
102 {
103 	size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
104 
105 	if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
106 		nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
107 		if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode)
108 			nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
109 	}
110 
111 	return nblocks;
112 }
113 
reiserfs_init_xattr_rwsem(struct inode * inode)114 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
115 {
116 	init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
117 }
118 
119 #else
120 
121 #define reiserfs_getxattr NULL
122 #define reiserfs_setxattr NULL
123 #define reiserfs_listxattr NULL
124 #define reiserfs_removexattr NULL
125 
reiserfs_init_xattr_rwsem(struct inode * inode)126 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
127 {
128 }
129 #endif  /*  CONFIG_REISERFS_FS_XATTR  */
130 
131 #ifndef CONFIG_REISERFS_FS_SECURITY
reiserfs_security_init(struct inode * dir,struct inode * inode,const struct qstr * qstr,struct reiserfs_security_handle * sec)132 static inline int reiserfs_security_init(struct inode *dir,
133 					 struct inode *inode,
134 					 const struct qstr *qstr,
135 					 struct reiserfs_security_handle *sec)
136 {
137 	return 0;
138 }
139 static inline int
reiserfs_security_write(struct reiserfs_transaction_handle * th,struct inode * inode,struct reiserfs_security_handle * sec)140 reiserfs_security_write(struct reiserfs_transaction_handle *th,
141 			struct inode *inode,
142 			struct reiserfs_security_handle *sec)
143 {
144 	return 0;
145 }
reiserfs_security_free(struct reiserfs_security_handle * sec)146 static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
147 {}
148 #endif
149 
150 #endif  /*  __KERNEL__  */
151 
152 #endif  /*  _LINUX_REISERFS_XATTR_H  */
153