1ac506a8fSPedro F. Giffuni /*- 2*7abc09cdSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*7abc09cdSPedro 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 * $FreeBSD$ 29ac506a8fSPedro F. Giffuni */ 30ac506a8fSPedro F. Giffuni 31ac506a8fSPedro F. Giffuni #ifndef _FS_EXT2FS_EXT2_EXTARTTR_H_ 32ac506a8fSPedro F. Giffuni #define _FS_EXT2FS_EXT2_EXTARTTR_H_ 33ac506a8fSPedro F. Giffuni 34ac506a8fSPedro F. Giffuni /* Linux xattr name indexes */ 35ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_USER 1 36ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2 37ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3 38ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_TRUSTED 4 39ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_LUSTRE 5 40ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_SECURITY 6 41ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_SYSTEM 7 42ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_RICHACL 8 43ac506a8fSPedro F. Giffuni #define EXT4_XATTR_INDEX_ENCRYPTION 9 44ac506a8fSPedro F. Giffuni 45ac506a8fSPedro F. Giffuni /* Magic value in attribute blocks */ 46ac506a8fSPedro F. Giffuni #define EXTATTR_MAGIC 0xEA020000 47ac506a8fSPedro F. Giffuni 4834f43888SPedro F. Giffuni /* Max EA name length */ 4934f43888SPedro F. Giffuni #define EXT2_EXTATTR_NAMELEN_MAX 255 5034f43888SPedro F. Giffuni 5134f43888SPedro F. Giffuni /* EA hash constants */ 5234f43888SPedro F. Giffuni #define EXT2_EXTATTR_NAME_HASH_SHIFT 5 5334f43888SPedro F. Giffuni #define EXT2_EXTATTR_VALUE_HASH_SHIFT 16 5434f43888SPedro F. Giffuni #define EXT2_EXTATTR_BLOCK_HASH_SHIFT 16 5534f43888SPedro F. Giffuni 5634f43888SPedro F. Giffuni 57ac506a8fSPedro F. Giffuni struct ext2fs_extattr_header { 58ac506a8fSPedro F. Giffuni int32_t h_magic; /* magic number for identification */ 59ac506a8fSPedro F. Giffuni int32_t h_refcount; /* reference count */ 60ac506a8fSPedro F. Giffuni int32_t h_blocks; /* number of disk blocks used */ 61ac506a8fSPedro F. Giffuni int32_t h_hash; /* hash value of all attributes */ 62ac506a8fSPedro F. Giffuni uint32_t h_reserved[4]; /* zero right now */ 63ac506a8fSPedro F. Giffuni }; 64ac506a8fSPedro F. Giffuni 65ac506a8fSPedro F. Giffuni struct ext2fs_extattr_dinode_header { 66ac506a8fSPedro F. Giffuni int32_t h_magic; /* magic number for identification */ 67ac506a8fSPedro F. Giffuni }; 68ac506a8fSPedro F. Giffuni 69ac506a8fSPedro F. Giffuni struct ext2fs_extattr_entry { 70ac506a8fSPedro F. Giffuni uint8_t e_name_len; /* length of name */ 71ac506a8fSPedro F. Giffuni uint8_t e_name_index; /* attribute name index */ 72ac506a8fSPedro F. Giffuni uint16_t e_value_offs; /* offset in disk block of value */ 73ac506a8fSPedro F. Giffuni uint32_t e_value_block; /* disk block attribute is stored on (n/i) */ 74ac506a8fSPedro F. Giffuni uint32_t e_value_size; /* size of attribute value */ 75ac506a8fSPedro F. Giffuni uint32_t e_hash; /* hash value of name and value */ 76ac506a8fSPedro F. Giffuni char e_name[0]; /* attribute name */ 77ac506a8fSPedro F. Giffuni }; 78ac506a8fSPedro F. Giffuni 79ac506a8fSPedro F. Giffuni #define EXT2_IFIRST(hdr) ((struct ext2fs_extattr_entry *)((hdr)+1)) 80ac506a8fSPedro F. Giffuni 81ac506a8fSPedro F. Giffuni #define EXT2_HDR(bh) ((struct ext2fs_extattr_header *)((bh)->b_data)) 82ac506a8fSPedro F. Giffuni #define EXT2_ENTRY(ptr) ((struct ext2fs_extattr_entry *)(ptr)) 83ac506a8fSPedro F. Giffuni #define EXT2_FIRST_ENTRY(bh) EXT2_ENTRY(EXT2_HDR(bh)+1) 84ac506a8fSPedro F. Giffuni #define EXT2_IS_LAST_ENTRY(entry) (*(uint32_t *)(entry) == 0) 85ac506a8fSPedro F. Giffuni 86ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD_BITS 2 87ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_PAD (1<<EXT2_EXTATTR_PAD_BITS) 88ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_ROUND (EXT2_EXTATTR_PAD-1) 89ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_LEN(name_len) \ 90ac506a8fSPedro F. Giffuni (((name_len) + EXT2_EXTATTR_ROUND + \ 91ac506a8fSPedro F. Giffuni sizeof(struct ext2fs_extattr_entry)) & ~EXT2_EXTATTR_ROUND) 92ac506a8fSPedro F. Giffuni 9334f43888SPedro F. Giffuni #define EXT2_EXTATTR_SIZE(size) \ 9434f43888SPedro F. Giffuni (((size) + EXT2_EXTATTR_ROUND) & ~EXT2_EXTATTR_ROUND) 9534f43888SPedro F. Giffuni 96ac506a8fSPedro F. Giffuni #define EXT2_EXTATTR_NEXT(entry) \ 97ac506a8fSPedro F. Giffuni ( (struct ext2fs_extattr_entry *)( \ 98ac506a8fSPedro F. Giffuni (char *)(entry) + EXT2_EXTATTR_LEN((entry)->e_name_len)) ) 99ac506a8fSPedro F. Giffuni 10034f43888SPedro F. Giffuni int ext2_extattr_inode_delete(struct inode *ip, int attrnamespace, 10134f43888SPedro F. Giffuni const char *name); 10234f43888SPedro F. Giffuni 10334f43888SPedro F. Giffuni int ext2_extattr_block_delete(struct inode *ip, int attrnamespace, 10434f43888SPedro F. Giffuni const char *name); 10534f43888SPedro F. Giffuni 10634f43888SPedro F. Giffuni int ext2_extattr_free(struct inode *ip); 107ac506a8fSPedro F. Giffuni int ext2_extattr_inode_list(struct inode *ip, int attrnamespace, 108ac506a8fSPedro F. Giffuni struct uio *uio, size_t *size); 109ac506a8fSPedro F. Giffuni 110ac506a8fSPedro F. Giffuni int ext2_extattr_block_list(struct inode *ip, int attrnamespace, 111ac506a8fSPedro F. Giffuni struct uio *uio, size_t *size); 112ac506a8fSPedro F. Giffuni 113ac506a8fSPedro F. Giffuni int ext2_extattr_inode_get(struct inode *ip, int attrnamespace, 114ac506a8fSPedro F. Giffuni const char *name, struct uio *uio, size_t *size); 115ac506a8fSPedro F. Giffuni 116ac506a8fSPedro F. Giffuni int ext2_extattr_block_get(struct inode *ip, int attrnamespace, 117ac506a8fSPedro F. Giffuni const char *name, struct uio *uio, size_t *size); 118ac506a8fSPedro F. Giffuni 11934f43888SPedro F. Giffuni int ext2_extattr_inode_set(struct inode *ip, int attrnamespace, 12034f43888SPedro F. Giffuni const char *name, struct uio *uio); 12134f43888SPedro F. Giffuni 12234f43888SPedro F. Giffuni int ext2_extattr_block_set(struct inode *ip, int attrnamespace, 12334f43888SPedro F. Giffuni const char *name, struct uio *uio); 12434f43888SPedro F. Giffuni 12534f43888SPedro F. Giffuni int ext2_extattr_valid_attrname(int attrnamespace, const char *attrname); 12634f43888SPedro F. Giffuni 127ac506a8fSPedro F. Giffuni #endif /* !_FS_EXT2FS_EXT2_EXTARTTR_H_ */ 128