1 /** 2 * xattr.h 3 * 4 * Many parts of codes are copied from Linux kernel/fs/f2fs. 5 * 6 * Copyright (C) 2015 Huawei Ltd. 7 * Witten by: 8 * Hou Pengyang <houpengyang@huawei.com> 9 * Liu Shuoran <liushuoran@huawei.com> 10 * Jaegeuk Kim <jaegeuk@kernel.org> 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License version 2 as 14 * published by the Free Software Foundation. 15 */ 16 #ifndef _XATTR_H_ 17 #define _XATTR_H_ 18 19 #include "f2fs.h" 20 21 struct f2fs_xattr_header { 22 __le32 h_magic; /* magic number for identification */ 23 __le32 h_refcount; /* reference count */ 24 __u32 h_sloadd[4]; /* zero right now */ 25 }; 26 27 struct f2fs_xattr_entry { 28 __u8 e_name_index; 29 __u8 e_name_len; 30 __le16 e_value_size; /* size of attribute value */ 31 char e_name[0]; /* attribute name */ 32 }; 33 34 #define XATTR_ROUND (3) 35 36 #define XATTR_SELINUX_SUFFIX "selinux" 37 #define F2FS_XATTR_INDEX_SECURITY 6 38 #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) 39 40 #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr)) 41 #define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr)) 42 #define F2FS_XATTR_MAGIC 0xF2F52011 43 44 #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *) ((char *)(entry) +\ 45 ENTRY_SIZE(entry))) 46 #define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1)) 47 48 #define XATTR_ALIGN(size) ((size + XATTR_ROUND) & ~XATTR_ROUND) 49 50 #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \ 51 entry->e_name_len + le16_to_cpu(entry->e_value_size))) 52 53 #define list_for_each_xattr(entry, addr) \ 54 for (entry = XATTR_FIRST_ENTRY(addr); \ 55 !IS_XATTR_LAST_ENTRY(entry); \ 56 entry = XATTR_NEXT_ENTRY(entry)) 57 58 #define MIN_OFFSET XATTR_ALIGN(PAGE_SIZE - \ 59 sizeof(struct node_footer) - sizeof(__u32)) 60 61 #define MAX_VALUE_LEN (MIN_OFFSET - \ 62 sizeof(struct f2fs_xattr_header) - \ 63 sizeof(struct f2fs_xattr_entry)) 64 65 #endif 66