blob: a90920e2f9498098dd6e4add9be1bf26b8a1f368 [file] [log] [blame]
Chao Yu6d1a8322018-09-12 09:16:07 +08001// SPDX-License-Identifier: GPL-2.0
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09002/*
Jaegeuk Kimaf48b852012-11-02 17:12:17 +09003 * 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 Kimaf48b852012-11-02 17:12:17 +090013 */
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 Gruenbacher98e9cb52015-12-02 14:44:36 +010027#define F2FS_SYSTEM_ADVISE_NAME "system.advise"
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090028#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 Kimb93531d2015-04-10 16:43:31 -070035/* Should be same as EXT4_XATTR_INDEX_ENCRYPTION */
36#define F2FS_XATTR_INDEX_ENCRYPTION 9
37
38#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090039
40struct f2fs_xattr_header {
41 __le32 h_magic; /* magic number for identification */
42 __le32 h_refcount; /* reference count */
43 __u32 h_reserved[4]; /* zero right now */
44};
45
46struct f2fs_xattr_entry {
47 __u8 e_name_index;
48 __u8 e_name_len;
49 __le16 e_value_size; /* size of attribute value */
50 char e_name[0]; /* attribute name */
51};
52
53#define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
54#define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
Jaegeuk Kimdd9cfe22013-08-13 10:13:55 +090055#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090056#define XATTR_ROUND (3)
57
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070058#define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND)
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090059
60#define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070061 (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090062
63#define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
64 ENTRY_SIZE(entry)))
65
66#define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
67
68#define list_for_each_xattr(entry, addr) \
69 for (entry = XATTR_FIRST_ENTRY(addr);\
70 !IS_XATTR_LAST_ENTRY(entry);\
71 entry = XATTR_NEXT_ENTRY(entry))
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070072#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
73#define XATTR_PADDING_SIZE (sizeof(__u32))
Randall Huangc673f4b2019-04-11 16:26:46 +080074#define XATTR_SIZE(x,i) (((x) ? VALID_XATTR_BLOCK_SIZE : 0) + \
75 (inline_xattr_size(i)))
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070076#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
77 VALID_XATTR_BLOCK_SIZE)
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090078
Jaegeuk Kim65985d92013-08-14 21:57:27 +090079#define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \
80 sizeof(struct f2fs_xattr_header) - \
81 sizeof(struct f2fs_xattr_entry))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090082
Chao Yua9e0ca82019-03-04 17:19:04 +080083#define MAX_INLINE_XATTR_SIZE \
84 (DEF_ADDRS_PER_INODE - \
85 F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
86 DEF_INLINE_RESERVED_SIZE - \
87 MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
88
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +090089/*
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090090 * On-disk structure of f2fs_xattr
Jaegeuk Kim65985d92013-08-14 21:57:27 +090091 * We use inline xattrs space + 1 block for xattr.
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090092 *
93 * +--------------------+
94 * | f2fs_xattr_header |
95 * | |
96 * +--------------------+
97 * | f2fs_xattr_entry |
98 * | .e_name_index = 1 |
99 * | .e_name_len = 3 |
100 * | .e_value_size = 14 |
101 * | .e_name = "foo" |
102 * | "value_of_xattr" |<- value_offs = e_name + e_name_len
103 * +--------------------+
104 * | f2fs_xattr_entry |
105 * | .e_name_index = 4 |
106 * | .e_name = "bar" |
107 * +--------------------+
108 * | |
109 * | Free |
110 * | |
111 * +--------------------+<- MIN_OFFSET
112 * | node_footer |
113 * | (nid, ino, offset) |
114 * +--------------------+
115 *
116 **/
117
118#ifdef CONFIG_F2FS_FS_XATTR
119extern const struct xattr_handler f2fs_xattr_user_handler;
120extern const struct xattr_handler f2fs_xattr_trusted_handler;
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900121extern const struct xattr_handler f2fs_xattr_advise_handler;
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900122extern const struct xattr_handler f2fs_xattr_security_handler;
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900123
124extern const struct xattr_handler *f2fs_xattr_handlers[];
125
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900126extern int f2fs_setxattr(struct inode *, int, const char *,
Jaegeuk Kimc02745e2014-04-23 12:23:14 +0900127 const void *, size_t, struct page *, int);
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700128extern int f2fs_getxattr(struct inode *, int, const char *, void *,
129 size_t, struct page *);
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900130extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900131#else
132
133#define f2fs_xattr_handlers NULL
Jaegeuk Kime1123262014-04-23 12:17:25 +0900134static inline int f2fs_setxattr(struct inode *inode, int index,
Arnd Bergmannfff4c552016-03-15 00:07:56 +0100135 const char *name, const void *value, size_t size,
136 struct page *page, int flags)
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900137{
138 return -EOPNOTSUPP;
139}
Jaegeuk Kime1123262014-04-23 12:17:25 +0900140static inline int f2fs_getxattr(struct inode *inode, int index,
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700141 const char *name, void *buffer,
142 size_t buffer_size, struct page *dpage)
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900143{
144 return -EOPNOTSUPP;
145}
146static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer,
147 size_t buffer_size)
148{
149 return -EOPNOTSUPP;
150}
151#endif
152
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900153#ifdef CONFIG_F2FS_FS_SECURITY
154extern int f2fs_init_security(struct inode *, struct inode *,
155 const struct qstr *, struct page *);
156#else
157static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
158 const struct qstr *qstr, struct page *ipage)
159{
160 return 0;
161}
162#endif
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900163#endif /* __F2FS_XATTR_H__ */