Nishad Kamdar | d29fbcd | 2020-04-25 18:49:08 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 2 | /* |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 3 | * fs/f2fs/xattr.h |
| 4 | * |
| 5 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 6 | * http://www.samsung.com/ |
| 7 | * |
| 8 | * Portions of this code from linux/fs/ext2/xattr.h |
| 9 | * |
| 10 | * On-disk format of extended attributes for the ext2 filesystem. |
| 11 | * |
| 12 | * (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org> |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 13 | */ |
| 14 | #ifndef __F2FS_XATTR_H__ |
| 15 | #define __F2FS_XATTR_H__ |
| 16 | |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/xattr.h> |
| 19 | |
| 20 | /* Magic value in attribute blocks */ |
| 21 | #define F2FS_XATTR_MAGIC 0xF2F52011 |
| 22 | |
| 23 | /* Maximum number of references to one attribute block */ |
| 24 | #define F2FS_XATTR_REFCOUNT_MAX 1024 |
| 25 | |
| 26 | /* Name indexes */ |
Andreas Gruenbacher | 98e9cb5 | 2015-12-02 14:44:36 +0100 | [diff] [blame] | 27 | #define F2FS_SYSTEM_ADVISE_NAME "system.advise" |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 28 | #define F2FS_XATTR_INDEX_USER 1 |
| 29 | #define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2 |
| 30 | #define F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT 3 |
| 31 | #define F2FS_XATTR_INDEX_TRUSTED 4 |
| 32 | #define F2FS_XATTR_INDEX_LUSTRE 5 |
| 33 | #define F2FS_XATTR_INDEX_SECURITY 6 |
| 34 | #define F2FS_XATTR_INDEX_ADVISE 7 |
Jaegeuk Kim | b93531d | 2015-04-10 16:43:31 -0700 | [diff] [blame] | 35 | /* Should be same as EXT4_XATTR_INDEX_ENCRYPTION */ |
| 36 | #define F2FS_XATTR_INDEX_ENCRYPTION 9 |
Eric Biggers | 95ae251 | 2019-07-22 09:26:24 -0700 | [diff] [blame] | 37 | #define F2FS_XATTR_INDEX_VERITY 11 |
Jaegeuk Kim | b93531d | 2015-04-10 16:43:31 -0700 | [diff] [blame] | 38 | |
| 39 | #define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c" |
Eric Biggers | 95ae251 | 2019-07-22 09:26:24 -0700 | [diff] [blame] | 40 | #define F2FS_XATTR_NAME_VERITY "v" |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 41 | |
| 42 | struct f2fs_xattr_header { |
| 43 | __le32 h_magic; /* magic number for identification */ |
| 44 | __le32 h_refcount; /* reference count */ |
| 45 | __u32 h_reserved[4]; /* zero right now */ |
| 46 | }; |
| 47 | |
| 48 | struct f2fs_xattr_entry { |
| 49 | __u8 e_name_index; |
| 50 | __u8 e_name_len; |
| 51 | __le16 e_value_size; /* size of attribute value */ |
Gustavo A. R. Silva | 50b1203 | 2020-03-09 13:10:08 -0500 | [diff] [blame] | 52 | char e_name[]; /* attribute name */ |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr)) |
| 56 | #define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr)) |
Jaegeuk Kim | dd9cfe2 | 2013-08-13 10:13:55 +0900 | [diff] [blame] | 57 | #define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1)) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 58 | #define XATTR_ROUND (3) |
| 59 | |
Tomohiro Kusumi | 68afcf2 | 2017-04-09 02:11:36 +0300 | [diff] [blame] | 60 | #define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 61 | |
| 62 | #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \ |
Tomohiro Kusumi | 68afcf2 | 2017-04-09 02:11:36 +0300 | [diff] [blame] | 63 | (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 64 | |
| 65 | #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\ |
| 66 | ENTRY_SIZE(entry))) |
| 67 | |
| 68 | #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) |
| 69 | |
| 70 | #define list_for_each_xattr(entry, addr) \ |
| 71 | for (entry = XATTR_FIRST_ENTRY(addr);\ |
| 72 | !IS_XATTR_LAST_ENTRY(entry);\ |
| 73 | entry = XATTR_NEXT_ENTRY(entry)) |
Chao Yu | 22588f8 | 2017-03-23 13:38:26 +0800 | [diff] [blame] | 74 | #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) |
| 75 | #define XATTR_PADDING_SIZE (sizeof(__u32)) |
Chao Yu | ba3b583 | 2020-02-14 17:44:11 +0800 | [diff] [blame] | 76 | #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \ |
| 77 | VALID_XATTR_BLOCK_SIZE : 0) + \ |
Randall Huang | 2777e65 | 2019-04-11 16:26:46 +0800 | [diff] [blame] | 78 | (inline_xattr_size(i))) |
Chao Yu | ba38c27 | 2017-01-24 20:39:51 +0800 | [diff] [blame] | 79 | #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ |
| 80 | VALID_XATTR_BLOCK_SIZE) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 81 | |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 82 | #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ |
| 83 | sizeof(struct f2fs_xattr_header) - \ |
| 84 | sizeof(struct f2fs_xattr_entry)) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 85 | |
Chao Yu | dd6c89b | 2019-03-04 17:19:04 +0800 | [diff] [blame] | 86 | #define MAX_INLINE_XATTR_SIZE \ |
| 87 | (DEF_ADDRS_PER_INODE - \ |
| 88 | F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ |
| 89 | DEF_INLINE_RESERVED_SIZE - \ |
| 90 | MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) |
| 91 | |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 92 | /* |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 93 | * On-disk structure of f2fs_xattr |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 94 | * We use inline xattrs space + 1 block for xattr. |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 95 | * |
| 96 | * +--------------------+ |
| 97 | * | f2fs_xattr_header | |
| 98 | * | | |
| 99 | * +--------------------+ |
| 100 | * | f2fs_xattr_entry | |
| 101 | * | .e_name_index = 1 | |
| 102 | * | .e_name_len = 3 | |
| 103 | * | .e_value_size = 14 | |
| 104 | * | .e_name = "foo" | |
| 105 | * | "value_of_xattr" |<- value_offs = e_name + e_name_len |
| 106 | * +--------------------+ |
| 107 | * | f2fs_xattr_entry | |
| 108 | * | .e_name_index = 4 | |
| 109 | * | .e_name = "bar" | |
| 110 | * +--------------------+ |
| 111 | * | | |
| 112 | * | Free | |
| 113 | * | | |
| 114 | * +--------------------+<- MIN_OFFSET |
| 115 | * | node_footer | |
| 116 | * | (nid, ino, offset) | |
| 117 | * +--------------------+ |
| 118 | * |
| 119 | **/ |
| 120 | |
| 121 | #ifdef CONFIG_F2FS_FS_XATTR |
| 122 | extern const struct xattr_handler f2fs_xattr_user_handler; |
| 123 | extern const struct xattr_handler f2fs_xattr_trusted_handler; |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 124 | extern const struct xattr_handler f2fs_xattr_advise_handler; |
Jaegeuk Kim | 8ae8f16 | 2013-06-03 19:46:19 +0900 | [diff] [blame] | 125 | extern const struct xattr_handler f2fs_xattr_security_handler; |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 126 | |
| 127 | extern const struct xattr_handler *f2fs_xattr_handlers[]; |
| 128 | |
Jaegeuk Kim | 8ae8f16 | 2013-06-03 19:46:19 +0900 | [diff] [blame] | 129 | extern int f2fs_setxattr(struct inode *, int, const char *, |
Jaegeuk Kim | c02745e | 2014-04-23 12:23:14 +0900 | [diff] [blame] | 130 | const void *, size_t, struct page *, int); |
Jaegeuk Kim | bce8d11 | 2014-10-13 19:42:53 -0700 | [diff] [blame] | 131 | extern int f2fs_getxattr(struct inode *, int, const char *, void *, |
| 132 | size_t, struct page *); |
Jaegeuk Kim | 8ae8f16 | 2013-06-03 19:46:19 +0900 | [diff] [blame] | 133 | extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t); |
Chao Yu | a999150 | 2020-02-25 18:17:10 +0800 | [diff] [blame] | 134 | extern int f2fs_init_xattr_caches(struct f2fs_sb_info *); |
| 135 | extern void f2fs_destroy_xattr_caches(struct f2fs_sb_info *); |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 136 | #else |
| 137 | |
| 138 | #define f2fs_xattr_handlers NULL |
Chengguang Xu | 195f406 | 2020-05-26 17:05:43 +0800 | [diff] [blame] | 139 | #define f2fs_listxattr NULL |
Jaegeuk Kim | e112326 | 2014-04-23 12:17:25 +0900 | [diff] [blame] | 140 | static inline int f2fs_setxattr(struct inode *inode, int index, |
Arnd Bergmann | fff4c55 | 2016-03-15 00:07:56 +0100 | [diff] [blame] | 141 | const char *name, const void *value, size_t size, |
| 142 | struct page *page, int flags) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 143 | { |
| 144 | return -EOPNOTSUPP; |
| 145 | } |
Jaegeuk Kim | e112326 | 2014-04-23 12:17:25 +0900 | [diff] [blame] | 146 | static inline int f2fs_getxattr(struct inode *inode, int index, |
Jaegeuk Kim | bce8d11 | 2014-10-13 19:42:53 -0700 | [diff] [blame] | 147 | const char *name, void *buffer, |
| 148 | size_t buffer_size, struct page *dpage) |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 149 | { |
| 150 | return -EOPNOTSUPP; |
| 151 | } |
YueHaibing | db25155 | 2020-03-28 19:27:36 +0800 | [diff] [blame] | 152 | static inline int f2fs_init_xattr_caches(struct f2fs_sb_info *sbi) { return 0; } |
| 153 | static inline void f2fs_destroy_xattr_caches(struct f2fs_sb_info *sbi) { } |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 154 | #endif |
| 155 | |
Jaegeuk Kim | 8ae8f16 | 2013-06-03 19:46:19 +0900 | [diff] [blame] | 156 | #ifdef CONFIG_F2FS_FS_SECURITY |
| 157 | extern int f2fs_init_security(struct inode *, struct inode *, |
| 158 | const struct qstr *, struct page *); |
| 159 | #else |
| 160 | static inline int f2fs_init_security(struct inode *inode, struct inode *dir, |
| 161 | const struct qstr *qstr, struct page *ipage) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | #endif |
Jaegeuk Kim | af48b85 | 2012-11-02 17:12:17 +0900 | [diff] [blame] | 166 | #endif /* __F2FS_XATTR_H__ */ |