1ac506a8fSPedro F. Giffuni /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 37abc09cdSPedro F. Giffuni * 4ac506a8fSPedro F. Giffuni * Copyright (c) 2017, Fedor Uporov 5ac506a8fSPedro F. Giffuni * All rights reserved. 6ac506a8fSPedro F. Giffuni * 7ac506a8fSPedro F. Giffuni * Redistribution and use in source and binary forms, with or without 8ac506a8fSPedro F. Giffuni * modification, are permitted provided that the following conditions 9ac506a8fSPedro F. Giffuni * are met: 10ac506a8fSPedro F. Giffuni * 1. Redistributions of source code must retain the above copyright 11ac506a8fSPedro F. Giffuni * notice, this list of conditions and the following disclaimer. 12ac506a8fSPedro F. Giffuni * 2. Redistributions in binary form must reproduce the above copyright 13ac506a8fSPedro F. Giffuni * notice, this list of conditions and the following disclaimer in the 14ac506a8fSPedro F. Giffuni * documentation and/or other materials provided with the distribution. 15ac506a8fSPedro F. Giffuni * 16ac506a8fSPedro F. Giffuni * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17ac506a8fSPedro F. Giffuni * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18ac506a8fSPedro F. Giffuni * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19ac506a8fSPedro F. Giffuni * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20ac506a8fSPedro F. Giffuni * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21ac506a8fSPedro F. Giffuni * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22ac506a8fSPedro F. Giffuni * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23ac506a8fSPedro F. Giffuni * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24ac506a8fSPedro F. Giffuni * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25ac506a8fSPedro F. Giffuni * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26ac506a8fSPedro F. Giffuni * SUCH DAMAGE. 27ac506a8fSPedro F. Giffuni */ 28ac506a8fSPedro F. Giffuni 29ac506a8fSPedro F. Giffuni #ifndef _FS_EXT2FS_EXT2_EXTARTTR_H_ 30ac506a8fSPedro F. Giffuni #define _FS_EXT2FS_EXT2_EXTARTTR_H_ 31ac506a8fSPedro F. Giffuni 32ac506a8fSPedro F. Giffuni /* Linux xattr name indexes */ 33ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_USER 1 34ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2 35ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3 36ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_TRUSTED 4 37ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_LUSTRE 5 38ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_SECURITY 6 39ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_SYSTEM 7 40ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_RICHACL 8 41ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_ENCRYPTION 9 42ac506a8fSPedro F. Giffuni 43ac506a8fSPedro F. Giffuni /* Magic value in attribute blocks */ 44ac506a8fSPedro F. Giffuni #define EXTATTR_MAGIC 0xEA020000 45ac506a8fSPedro F. Giffuni 4634f43888SPedro F. Giffuni /* Max EA name length */ 4734f43888SPedro F. Giffuni #define EXT2_EXTATTR_NAMELEN_MAX 255 4834f43888SPedro F. Giffuni 4934f43888SPedro F. Giffuni /* EA hash constants */ 5034f43888SPedro F. Giffuni #define EXT2_EXTATTR_NAME_HASH_SHIFT 5 5134f43888SPedro F. Giffuni #define EXT2_EXTATTR_VALUE_HASH_SHIFT 16 5234f43888SPedro F. Giffuni #define EXT2_EXTATTR_BLOCK_HASH_SHIFT 16 5334f43888SPedro F. Giffuni 54ac506a8fSPedro F. Giffuni struct ext2fs_extattr_header { 55ac506a8fSPedro F. Giffuni int32_t h_magic; /* magic number for identification */ 56ac506a8fSPedro F. Giffuni int32_t h_refcount; /* reference count */ 57ac506a8fSPedro F. Giffuni int32_t h_blocks; /* number of disk blocks used */ 58ac506a8fSPedro F. Giffuni int32_t h_hash; /* hash value of all attributes */ 59512f29d1SFedor Uporov int32_t h_checksum; /* crc32c(uuid+id+xattrblock) */ 60512f29d1SFedor Uporov /* id = inum if refcount=1, blknum otherwise */ 61512f29d1SFedor Uporov uint32_t h_reserved[3]; /* zero right now */ 62ac506a8fSPedro F. Giffuni }; 63ac506a8fSPedro F. Giffuni 64ac506a8fSPedro F. Giffuni struct ext2fs_extattr_dinode_header { 65ac506a8fSPedro F. Giffuni int32_t h_magic; /* magic number for identification */ 66ac506a8fSPedro F. Giffuni }; 67ac506a8fSPedro F. Giffuni 68ac506a8fSPedro F. Giffuni struct ext2fs_extattr_entry { 69ac506a8fSPedro F. Giffuni uint8_t e_name_len; /* length of name */ 70ac506a8fSPedro F. Giffuni uint8_t e_name_index; /* attribute name index */ 71ac506a8fSPedro F. Giffuni uint16_t e_value_offs; /* offset in disk block of value */ 72ac506a8fSPedro F. Giffuni uint32_t e_value_block; /* disk block attribute is stored on (n/i) */ 73ac506a8fSPedro F. Giffuni uint32_t e_value_size; /* size of attribute value */ 74ac506a8fSPedro F. Giffuni uint32_t e_hash; /* hash value of name and value */ 75ac506a8fSPedro F. Giffuni char e_name[0]; /* attribute name */ 76ac506a8fSPedro F. Giffuni }; 77ac506a8fSPedro F. Giffuni 78ac506a8fSPedro F. Giffuni #define EXT2_IFIRST(hdr) ((struct ext2fs_extattr_entry *)((hdr)+1)) 79ac506a8fSPedro F. Giffuni 80ac506a8fSPedro F. Giffuni #define EXT2_HDR(bh) ((struct ext2fs_extattr_header *)((bh)->b_data)) 81ac506a8fSPedro F. Giffuni #define EXT2_ENTRY(ptr) ((struct ext2fs_extattr_entry *)(ptr)) 82ac506a8fSPedro F. Giffuni #define EXT2_FIRST_ENTRY(bh) EXT2_ENTRY(EXT2_HDR(bh)+1) 83ac506a8fSPedro F. Giffuni #define EXT2_IS_LAST_ENTRY(entry) (*(uint32_t *)(entry) == 0) 84ac506a8fSPedro F. Giffuni 85ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD_BITS 2 86ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD (1<<EXT2_EXTATTR_PAD_BITS) 87ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_ROUND (EXT2_EXTATTR_PAD-1) 88ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_LEN(name_len) \ 89ac506a8fSPedro F. Giffuni (((name_len) + EXT2_EXTATTR_ROUND + \ 90ac506a8fSPedro F. Giffuni sizeof(struct ext2fs_extattr_entry)) & ~EXT2_EXTATTR_ROUND) 91ac506a8fSPedro F. Giffuni 9234f43888SPedro F. Giffuni #define EXT2_EXTATTR_SIZE(size) \ 9334f43888SPedro F. Giffuni (((size) + EXT2_EXTATTR_ROUND) & ~EXT2_EXTATTR_ROUND) 9434f43888SPedro F. Giffuni 95ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_NEXT(entry) \ 96ac506a8fSPedro F. Giffuni ( (struct ext2fs_extattr_entry *)( \ 97ac506a8fSPedro F. Giffuni (char *)(entry) + EXT2_EXTATTR_LEN((entry)->e_name_len)) ) 98ac506a8fSPedro F. Giffuni 9934f43888SPedro F. Giffuni int ext2_extattr_inode_delete(struct inode *ip, int attrnamespace, 10034f43888SPedro F. Giffuni const char *name); 10134f43888SPedro F. Giffuni 10234f43888SPedro F. Giffuni int ext2_extattr_block_delete(struct inode *ip, int attrnamespace, 10334f43888SPedro F. Giffuni const char *name); 10434f43888SPedro F. Giffuni 10534f43888SPedro F. Giffuni int ext2_extattr_free(struct inode *ip); 106ac506a8fSPedro F. Giffuni int ext2_extattr_inode_list(struct inode *ip, int attrnamespace, 107ac506a8fSPedro F. Giffuni struct uio *uio, size_t *size); 108ac506a8fSPedro F. Giffuni 109ac506a8fSPedro F. Giffuni int ext2_extattr_block_list(struct inode *ip, int attrnamespace, 110ac506a8fSPedro F. Giffuni struct uio *uio, size_t *size); 111ac506a8fSPedro F. Giffuni 112ac506a8fSPedro F. Giffuni int ext2_extattr_inode_get(struct inode *ip, int attrnamespace, 113ac506a8fSPedro F. Giffuni const char *name, struct uio *uio, size_t *size); 114ac506a8fSPedro F. Giffuni 115ac506a8fSPedro F. Giffuni int ext2_extattr_block_get(struct inode *ip, int attrnamespace, 116ac506a8fSPedro F. Giffuni const char *name, struct uio *uio, size_t *size); 117ac506a8fSPedro F. Giffuni 11834f43888SPedro F. Giffuni int ext2_extattr_inode_set(struct inode *ip, int attrnamespace, 11934f43888SPedro F. Giffuni const char *name, struct uio *uio); 12034f43888SPedro F. Giffuni 12134f43888SPedro F. Giffuni int ext2_extattr_block_set(struct inode *ip, int attrnamespace, 12234f43888SPedro F. Giffuni const char *name, struct uio *uio); 12334f43888SPedro F. Giffuni 12434f43888SPedro F. Giffuni int ext2_extattr_valid_attrname(int attrnamespace, const char *attrname); 12534f43888SPedro F. Giffuni 126ac506a8fSPedro F. Giffuni #endif /* !_FS_EXT2FS_EXT2_EXTARTTR_H_ */ 127