xref: /freebsd/sys/fs/ext2fs/ext2_extattr.h (revision ac506a8f5ae949e463f22b81911c8b4170aaf5b8)
1*ac506a8fSPedro F. Giffuni /*-
2*ac506a8fSPedro F. Giffuni  * Copyright (c) 2017, Fedor Uporov
3*ac506a8fSPedro F. Giffuni  * All rights reserved.
4*ac506a8fSPedro F. Giffuni  *
5*ac506a8fSPedro F. Giffuni  * Redistribution and use in source and binary forms, with or without
6*ac506a8fSPedro F. Giffuni  * modification, are permitted provided that the following conditions
7*ac506a8fSPedro F. Giffuni  * are met:
8*ac506a8fSPedro F. Giffuni  * 1. Redistributions of source code must retain the above copyright
9*ac506a8fSPedro F. Giffuni  *    notice, this list of conditions and the following disclaimer.
10*ac506a8fSPedro F. Giffuni  * 2. Redistributions in binary form must reproduce the above copyright
11*ac506a8fSPedro F. Giffuni  *    notice, this list of conditions and the following disclaimer in the
12*ac506a8fSPedro F. Giffuni  *    documentation and/or other materials provided with the distribution.
13*ac506a8fSPedro F. Giffuni  *
14*ac506a8fSPedro F. Giffuni  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15*ac506a8fSPedro F. Giffuni  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*ac506a8fSPedro F. Giffuni  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*ac506a8fSPedro F. Giffuni  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18*ac506a8fSPedro F. Giffuni  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*ac506a8fSPedro F. Giffuni  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*ac506a8fSPedro F. Giffuni  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*ac506a8fSPedro F. Giffuni  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*ac506a8fSPedro F. Giffuni  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*ac506a8fSPedro F. Giffuni  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*ac506a8fSPedro F. Giffuni  * SUCH DAMAGE.
25*ac506a8fSPedro F. Giffuni  *
26*ac506a8fSPedro F. Giffuni  * $FreeBSD$
27*ac506a8fSPedro F. Giffuni  */
28*ac506a8fSPedro F. Giffuni 
29*ac506a8fSPedro F. Giffuni #ifndef _FS_EXT2FS_EXT2_EXTARTTR_H_
30*ac506a8fSPedro F. Giffuni #define	_FS_EXT2FS_EXT2_EXTARTTR_H_
31*ac506a8fSPedro F. Giffuni 
32*ac506a8fSPedro F. Giffuni /* Linux xattr name indexes */
33*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_USER				1
34*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_POSIX_ACL_ACCESS	2
35*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT	3
36*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_TRUSTED			4
37*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_LUSTRE				5
38*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_SECURITY			6
39*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_SYSTEM				7
40*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_RICHACL			8
41*ac506a8fSPedro F. Giffuni #define	EXT4_XATTR_INDEX_ENCRYPTION			9
42*ac506a8fSPedro F. Giffuni 
43*ac506a8fSPedro F. Giffuni /* Magic value in attribute blocks */
44*ac506a8fSPedro F. Giffuni #define EXTATTR_MAGIC 0xEA020000
45*ac506a8fSPedro F. Giffuni 
46*ac506a8fSPedro F. Giffuni struct ext2fs_extattr_header {
47*ac506a8fSPedro F. Giffuni 	int32_t	h_magic;	/* magic number for identification */
48*ac506a8fSPedro F. Giffuni 	int32_t	h_refcount;	/* reference count */
49*ac506a8fSPedro F. Giffuni 	int32_t	h_blocks;	/* number of disk blocks used */
50*ac506a8fSPedro F. Giffuni 	int32_t	h_hash;		/* hash value of all attributes */
51*ac506a8fSPedro F. Giffuni 	uint32_t	h_reserved[4];	/* zero right now */
52*ac506a8fSPedro F. Giffuni };
53*ac506a8fSPedro F. Giffuni 
54*ac506a8fSPedro F. Giffuni struct ext2fs_extattr_dinode_header {
55*ac506a8fSPedro F. Giffuni 	int32_t	h_magic;	/* magic number for identification */
56*ac506a8fSPedro F. Giffuni };
57*ac506a8fSPedro F. Giffuni 
58*ac506a8fSPedro F. Giffuni struct ext2fs_extattr_entry {
59*ac506a8fSPedro F. Giffuni 	uint8_t	e_name_len;			/* length of name */
60*ac506a8fSPedro F. Giffuni 	uint8_t	e_name_index;		/* attribute name index */
61*ac506a8fSPedro F. Giffuni 	uint16_t	e_value_offs;	/* offset in disk block of value */
62*ac506a8fSPedro F. Giffuni 	uint32_t	e_value_block;	/* disk block attribute is stored on (n/i) */
63*ac506a8fSPedro F. Giffuni 	uint32_t	e_value_size;	/* size of attribute value */
64*ac506a8fSPedro F. Giffuni 	uint32_t	e_hash;			/* hash value of name and value */
65*ac506a8fSPedro F. Giffuni 	char	e_name[0];			/* attribute name */
66*ac506a8fSPedro F. Giffuni };
67*ac506a8fSPedro F. Giffuni 
68*ac506a8fSPedro F. Giffuni #define EXT2_IHDR(inode, raw_inode) \
69*ac506a8fSPedro F. Giffuni 	((struct ext4_xattr_ibody_header *) \
70*ac506a8fSPedro F. Giffuni 	    ((void *)raw_inode + \
71*ac506a8fSPedro F. Giffuni 	    EXT4_GOOD_OLD_INODE_SIZE + \
72*ac506a8fSPedro F. Giffuni 	    EXT4_I(inode)->i_extra_isize))
73*ac506a8fSPedro F. Giffuni 
74*ac506a8fSPedro F. Giffuni #define EXT2_IFIRST(hdr) ((struct ext2fs_extattr_entry *)((hdr)+1))
75*ac506a8fSPedro F. Giffuni 
76*ac506a8fSPedro F. Giffuni #define EXT2_HDR(bh) ((struct ext2fs_extattr_header *)((bh)->b_data))
77*ac506a8fSPedro F. Giffuni #define EXT2_ENTRY(ptr) ((struct ext2fs_extattr_entry *)(ptr))
78*ac506a8fSPedro F. Giffuni #define EXT2_FIRST_ENTRY(bh) EXT2_ENTRY(EXT2_HDR(bh)+1)
79*ac506a8fSPedro F. Giffuni #define EXT2_IS_LAST_ENTRY(entry) (*(uint32_t *)(entry) == 0)
80*ac506a8fSPedro F. Giffuni 
81*ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD_BITS		2
82*ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD		(1<<EXT2_EXTATTR_PAD_BITS)
83*ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_ROUND		(EXT2_EXTATTR_PAD-1)
84*ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_LEN(name_len) \
85*ac506a8fSPedro F. Giffuni 	(((name_len) + EXT2_EXTATTR_ROUND + \
86*ac506a8fSPedro F. Giffuni 	    sizeof(struct ext2fs_extattr_entry)) & ~EXT2_EXTATTR_ROUND)
87*ac506a8fSPedro F. Giffuni 
88*ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_NEXT(entry) \
89*ac506a8fSPedro F. Giffuni 	( (struct ext2fs_extattr_entry *)( \
90*ac506a8fSPedro F. Giffuni 	    (char *)(entry) + EXT2_EXTATTR_LEN((entry)->e_name_len)) )
91*ac506a8fSPedro F. Giffuni 
92*ac506a8fSPedro F. Giffuni int ext2_extattr_inode_list(struct inode *ip, int attrnamespace,
93*ac506a8fSPedro F. Giffuni     struct uio *uio, size_t *size);
94*ac506a8fSPedro F. Giffuni 
95*ac506a8fSPedro F. Giffuni int ext2_extattr_block_list(struct inode *ip, int attrnamespace,
96*ac506a8fSPedro F. Giffuni     struct uio *uio, size_t *size);
97*ac506a8fSPedro F. Giffuni 
98*ac506a8fSPedro F. Giffuni int ext2_extattr_inode_get(struct inode *ip, int attrnamespace,
99*ac506a8fSPedro F. Giffuni     const char *name, struct uio *uio, size_t *size);
100*ac506a8fSPedro F. Giffuni 
101*ac506a8fSPedro F. Giffuni int ext2_extattr_block_get(struct inode *ip, int attrnamespace,
102*ac506a8fSPedro F. Giffuni     const char *name, struct uio *uio, size_t *size);
103*ac506a8fSPedro F. Giffuni 
104*ac506a8fSPedro F. Giffuni #endif	/* !_FS_EXT2FS_EXT2_EXTARTTR_H_ */
105