]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/f2fs/xattr.h
Merge tag 'nfs-for-4.13-3' of git://git.linux-nfs.org/projects/anna/linux-nfs
[mirror_ubuntu-artful-kernel.git] / fs / f2fs / xattr.h
CommitLineData
0a8165d7 1/*
af48b85b
JK
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 */
98e9cb57 30#define F2FS_SYSTEM_ADVISE_NAME "system.advise"
af48b85b
JK
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
b93531dd
JK
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"
af48b85b
JK
42
43struct 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
49struct 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))
dd9cfe23 58#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
af48b85b
JK
59#define XATTR_ROUND (3)
60
68afcf2d 61#define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND)
af48b85b
JK
62
63#define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
68afcf2d 64 (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)))
af48b85b
JK
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))
22588f87
CY
75#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
76#define XATTR_PADDING_SIZE (sizeof(__u32))
ba38c27e
CY
77#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
78 VALID_XATTR_BLOCK_SIZE)
af48b85b 79
65985d93
JK
80#define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \
81 sizeof(struct f2fs_xattr_header) - \
82 sizeof(struct f2fs_xattr_entry))
af48b85b 83
0a8165d7 84/*
af48b85b 85 * On-disk structure of f2fs_xattr
65985d93 86 * We use inline xattrs space + 1 block for xattr.
af48b85b
JK
87 *
88 * +--------------------+
89 * | f2fs_xattr_header |
90 * | |
91 * +--------------------+
92 * | f2fs_xattr_entry |
93 * | .e_name_index = 1 |
94 * | .e_name_len = 3 |
95 * | .e_value_size = 14 |
96 * | .e_name = "foo" |
97 * | "value_of_xattr" |<- value_offs = e_name + e_name_len
98 * +--------------------+
99 * | f2fs_xattr_entry |
100 * | .e_name_index = 4 |
101 * | .e_name = "bar" |
102 * +--------------------+
103 * | |
104 * | Free |
105 * | |
106 * +--------------------+<- MIN_OFFSET
107 * | node_footer |
108 * | (nid, ino, offset) |
109 * +--------------------+
110 *
111 **/
112
113#ifdef CONFIG_F2FS_FS_XATTR
114extern const struct xattr_handler f2fs_xattr_user_handler;
115extern const struct xattr_handler f2fs_xattr_trusted_handler;
af48b85b 116extern const struct xattr_handler f2fs_xattr_advise_handler;
8ae8f162 117extern const struct xattr_handler f2fs_xattr_security_handler;
af48b85b
JK
118
119extern const struct xattr_handler *f2fs_xattr_handlers[];
120
8ae8f162 121extern int f2fs_setxattr(struct inode *, int, const char *,
c02745ef 122 const void *, size_t, struct page *, int);
bce8d112
JK
123extern int f2fs_getxattr(struct inode *, int, const char *, void *,
124 size_t, struct page *);
8ae8f162 125extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
af48b85b
JK
126#else
127
128#define f2fs_xattr_handlers NULL
e1123268 129static inline int f2fs_setxattr(struct inode *inode, int index,
fff4c55d
AB
130 const char *name, const void *value, size_t size,
131 struct page *page, int flags)
af48b85b
JK
132{
133 return -EOPNOTSUPP;
134}
e1123268 135static inline int f2fs_getxattr(struct inode *inode, int index,
bce8d112
JK
136 const char *name, void *buffer,
137 size_t buffer_size, struct page *dpage)
af48b85b
JK
138{
139 return -EOPNOTSUPP;
140}
141static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer,
142 size_t buffer_size)
143{
144 return -EOPNOTSUPP;
145}
146#endif
147
8ae8f162
JK
148#ifdef CONFIG_F2FS_FS_SECURITY
149extern int f2fs_init_security(struct inode *, struct inode *,
150 const struct qstr *, struct page *);
151#else
152static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
153 const struct qstr *qstr, struct page *ipage)
154{
155 return 0;
156}
157#endif
af48b85b 158#endif /* __F2FS_XATTR_H__ */