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