1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun File: linux/ext2_xattr.h
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun On-disk format of extended attributes for the ext2 filesystem.
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <linux/init.h>
11*4882a593Smuzhiyun #include <linux/xattr.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun /* Magic value in attribute blocks */
14*4882a593Smuzhiyun #define EXT2_XATTR_MAGIC 0xEA020000
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /* Maximum number of references to one attribute block */
17*4882a593Smuzhiyun #define EXT2_XATTR_REFCOUNT_MAX 1024
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /* Name indexes */
20*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_USER 1
21*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
22*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
23*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_TRUSTED 4
24*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_LUSTRE 5
25*4882a593Smuzhiyun #define EXT2_XATTR_INDEX_SECURITY 6
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun struct ext2_xattr_header {
28*4882a593Smuzhiyun __le32 h_magic; /* magic number for identification */
29*4882a593Smuzhiyun __le32 h_refcount; /* reference count */
30*4882a593Smuzhiyun __le32 h_blocks; /* number of disk blocks used */
31*4882a593Smuzhiyun __le32 h_hash; /* hash value of all attributes */
32*4882a593Smuzhiyun __u32 h_reserved[4]; /* zero right now */
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun struct ext2_xattr_entry {
36*4882a593Smuzhiyun __u8 e_name_len; /* length of name */
37*4882a593Smuzhiyun __u8 e_name_index; /* attribute name index */
38*4882a593Smuzhiyun __le16 e_value_offs; /* offset in disk block of value */
39*4882a593Smuzhiyun __le32 e_value_block; /* disk block attribute is stored on (n/i) */
40*4882a593Smuzhiyun __le32 e_value_size; /* size of attribute value */
41*4882a593Smuzhiyun __le32 e_hash; /* hash value of name and value */
42*4882a593Smuzhiyun char e_name[]; /* attribute name */
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #define EXT2_XATTR_PAD_BITS 2
46*4882a593Smuzhiyun #define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
47*4882a593Smuzhiyun #define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
48*4882a593Smuzhiyun #define EXT2_XATTR_LEN(name_len) \
49*4882a593Smuzhiyun (((name_len) + EXT2_XATTR_ROUND + \
50*4882a593Smuzhiyun sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
51*4882a593Smuzhiyun #define EXT2_XATTR_NEXT(entry) \
52*4882a593Smuzhiyun ( (struct ext2_xattr_entry *)( \
53*4882a593Smuzhiyun (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
54*4882a593Smuzhiyun #define EXT2_XATTR_SIZE(size) \
55*4882a593Smuzhiyun (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun struct mb_cache;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun # ifdef CONFIG_EXT2_FS_XATTR
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun extern const struct xattr_handler ext2_xattr_user_handler;
62*4882a593Smuzhiyun extern const struct xattr_handler ext2_xattr_trusted_handler;
63*4882a593Smuzhiyun extern const struct xattr_handler ext2_xattr_security_handler;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
68*4882a593Smuzhiyun extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun extern void ext2_xattr_delete_inode(struct inode *);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun extern struct mb_cache *ext2_xattr_create_cache(void);
73*4882a593Smuzhiyun extern void ext2_xattr_destroy_cache(struct mb_cache *cache);
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun extern const struct xattr_handler *ext2_xattr_handlers[];
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun # else /* CONFIG_EXT2_FS_XATTR */
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun static inline int
ext2_xattr_get(struct inode * inode,int name_index,const char * name,void * buffer,size_t size)80*4882a593Smuzhiyun ext2_xattr_get(struct inode *inode, int name_index,
81*4882a593Smuzhiyun const char *name, void *buffer, size_t size)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun return -EOPNOTSUPP;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun static inline int
ext2_xattr_set(struct inode * inode,int name_index,const char * name,const void * value,size_t size,int flags)87*4882a593Smuzhiyun ext2_xattr_set(struct inode *inode, int name_index, const char *name,
88*4882a593Smuzhiyun const void *value, size_t size, int flags)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun return -EOPNOTSUPP;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun static inline void
ext2_xattr_delete_inode(struct inode * inode)94*4882a593Smuzhiyun ext2_xattr_delete_inode(struct inode *inode)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
ext2_xattr_destroy_cache(struct mb_cache * cache)98*4882a593Smuzhiyun static inline void ext2_xattr_destroy_cache(struct mb_cache *cache)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #define ext2_xattr_handlers NULL
103*4882a593Smuzhiyun #define ext2_listxattr NULL
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun # endif /* CONFIG_EXT2_FS_XATTR */
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun #ifdef CONFIG_EXT2_FS_SECURITY
108*4882a593Smuzhiyun extern int ext2_init_security(struct inode *inode, struct inode *dir,
109*4882a593Smuzhiyun const struct qstr *qstr);
110*4882a593Smuzhiyun #else
ext2_init_security(struct inode * inode,struct inode * dir,const struct qstr * qstr)111*4882a593Smuzhiyun static inline int ext2_init_security(struct inode *inode, struct inode *dir,
112*4882a593Smuzhiyun const struct qstr *qstr)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun return 0;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun #endif
117