0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/xattr.h>
0011
0012
0013 #define EXT4_XATTR_MAGIC 0xEA020000
0014
0015
0016 #define EXT4_XATTR_REFCOUNT_MAX 1024
0017
0018
0019 #define EXT4_XATTR_INDEX_USER 1
0020 #define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2
0021 #define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3
0022 #define EXT4_XATTR_INDEX_TRUSTED 4
0023 #define EXT4_XATTR_INDEX_LUSTRE 5
0024 #define EXT4_XATTR_INDEX_SECURITY 6
0025 #define EXT4_XATTR_INDEX_SYSTEM 7
0026 #define EXT4_XATTR_INDEX_RICHACL 8
0027 #define EXT4_XATTR_INDEX_ENCRYPTION 9
0028 #define EXT4_XATTR_INDEX_HURD 10
0029
0030 struct ext4_xattr_header {
0031 __le32 h_magic;
0032 __le32 h_refcount;
0033 __le32 h_blocks;
0034 __le32 h_hash;
0035 __le32 h_checksum;
0036
0037 __u32 h_reserved[3];
0038 };
0039
0040 struct ext4_xattr_ibody_header {
0041 __le32 h_magic;
0042 };
0043
0044 struct ext4_xattr_entry {
0045 __u8 e_name_len;
0046 __u8 e_name_index;
0047 __le16 e_value_offs;
0048 __le32 e_value_inum;
0049 __le32 e_value_size;
0050 __le32 e_hash;
0051 char e_name[];
0052 };
0053
0054 #define EXT4_XATTR_PAD_BITS 2
0055 #define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
0056 #define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
0057 #define EXT4_XATTR_LEN(name_len) \
0058 (((name_len) + EXT4_XATTR_ROUND + \
0059 sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
0060 #define EXT4_XATTR_NEXT(entry) \
0061 ((struct ext4_xattr_entry *)( \
0062 (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
0063 #define EXT4_XATTR_SIZE(size) \
0064 (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
0065
0066 #define IHDR(inode, raw_inode) \
0067 ((struct ext4_xattr_ibody_header *) \
0068 ((void *)raw_inode + \
0069 EXT4_GOOD_OLD_INODE_SIZE + \
0070 EXT4_I(inode)->i_extra_isize))
0071 #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 #define EXT4_XATTR_SIZE_MAX (1 << 24)
0083
0084
0085
0086
0087
0088 #define EXT4_XATTR_MIN_LARGE_EA_SIZE(b) \
0089 ((b) - EXT4_XATTR_LEN(3) - sizeof(struct ext4_xattr_header) - 4)
0090
0091 #define BHDR(bh) ((struct ext4_xattr_header *)((bh)->b_data))
0092 #define ENTRY(ptr) ((struct ext4_xattr_entry *)(ptr))
0093 #define BFIRST(bh) ENTRY(BHDR(bh)+1)
0094 #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
0095
0096 #define EXT4_ZERO_XATTR_VALUE ((void *)-1)
0097
0098
0099
0100
0101
0102
0103
0104
0105 #define EXT4_INODE_HAS_XATTR_SPACE(inode) \
0106 ((EXT4_I(inode)->i_extra_isize != 0) && \
0107 (EXT4_GOOD_OLD_INODE_SIZE + EXT4_I(inode)->i_extra_isize + \
0108 sizeof(struct ext4_xattr_ibody_header) + EXT4_XATTR_PAD <= \
0109 EXT4_INODE_SIZE((inode)->i_sb)))
0110
0111 struct ext4_xattr_info {
0112 const char *name;
0113 const void *value;
0114 size_t value_len;
0115 int name_index;
0116 int in_inode;
0117 };
0118
0119 struct ext4_xattr_search {
0120 struct ext4_xattr_entry *first;
0121 void *base;
0122 void *end;
0123 struct ext4_xattr_entry *here;
0124 int not_found;
0125 };
0126
0127 struct ext4_xattr_ibody_find {
0128 struct ext4_xattr_search s;
0129 struct ext4_iloc iloc;
0130 };
0131
0132 struct ext4_xattr_inode_array {
0133 unsigned int count;
0134 struct inode *inodes[];
0135 };
0136
0137 extern const struct xattr_handler ext4_xattr_user_handler;
0138 extern const struct xattr_handler ext4_xattr_trusted_handler;
0139 extern const struct xattr_handler ext4_xattr_security_handler;
0140 extern const struct xattr_handler ext4_xattr_hurd_handler;
0141
0142 #define EXT4_XATTR_NAME_ENCRYPTION_CONTEXT "c"
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 static inline void ext4_write_lock_xattr(struct inode *inode, int *save)
0154 {
0155 down_write(&EXT4_I(inode)->xattr_sem);
0156 *save = ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND);
0157 ext4_set_inode_state(inode, EXT4_STATE_NO_EXPAND);
0158 }
0159
0160 static inline int ext4_write_trylock_xattr(struct inode *inode, int *save)
0161 {
0162 if (down_write_trylock(&EXT4_I(inode)->xattr_sem) == 0)
0163 return 0;
0164 *save = ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND);
0165 ext4_set_inode_state(inode, EXT4_STATE_NO_EXPAND);
0166 return 1;
0167 }
0168
0169 static inline void ext4_write_unlock_xattr(struct inode *inode, int *save)
0170 {
0171 if (*save == 0)
0172 ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
0173 up_write(&EXT4_I(inode)->xattr_sem);
0174 }
0175
0176 extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
0177
0178 extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
0179 extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
0180 extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
0181 extern int ext4_xattr_set_credits(struct inode *inode, size_t value_len,
0182 bool is_create, int *credits);
0183 extern int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
0184 struct buffer_head *block_bh, size_t value_len,
0185 bool is_create);
0186
0187 extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
0188 struct ext4_xattr_inode_array **array,
0189 int extra_credits);
0190 extern void ext4_xattr_inode_array_free(struct ext4_xattr_inode_array *array);
0191
0192 extern int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
0193 struct ext4_inode *raw_inode, handle_t *handle);
0194 extern void ext4_evict_ea_inode(struct inode *inode);
0195
0196 extern const struct xattr_handler *ext4_xattr_handlers[];
0197
0198 extern int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
0199 struct ext4_xattr_ibody_find *is);
0200 extern int ext4_xattr_ibody_get(struct inode *inode, int name_index,
0201 const char *name,
0202 void *buffer, size_t buffer_size);
0203 extern int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
0204 struct ext4_xattr_info *i,
0205 struct ext4_xattr_ibody_find *is);
0206
0207 extern struct mb_cache *ext4_xattr_create_cache(void);
0208 extern void ext4_xattr_destroy_cache(struct mb_cache *);
0209
0210 #ifdef CONFIG_EXT4_FS_SECURITY
0211 extern int ext4_init_security(handle_t *handle, struct inode *inode,
0212 struct inode *dir, const struct qstr *qstr);
0213 #else
0214 static inline int ext4_init_security(handle_t *handle, struct inode *inode,
0215 struct inode *dir, const struct qstr *qstr)
0216 {
0217 return 0;
0218 }
0219 #endif
0220
0221 #ifdef CONFIG_LOCKDEP
0222 extern void ext4_xattr_inode_set_class(struct inode *ea_inode);
0223 #else
0224 static inline void ext4_xattr_inode_set_class(struct inode *ea_inode) { }
0225 #endif
0226
0227 extern int ext4_get_inode_usage(struct inode *inode, qsize_t *usage);