blob: 02a08fb88a151c9b38a4e5aabc78decb2f0b4101 [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kimaf48b852012-11-02 17:12:17 +09002 * 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 */
30#define F2FS_SYSTEM_ADVISE_PREFIX "system.advise"
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
38
39struct f2fs_xattr_header {
40 __le32 h_magic; /* magic number for identification */
41 __le32 h_refcount; /* reference count */
42 __u32 h_reserved[4]; /* zero right now */
43};
44
45struct f2fs_xattr_entry {
46 __u8 e_name_index;
47 __u8 e_name_len;
48 __le16 e_value_size; /* size of attribute value */
49 char e_name[0]; /* attribute name */
50};
51
52#define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
53#define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
Jaegeuk Kimdd9cfe22013-08-13 10:13:55 +090054#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090055#define XATTR_ROUND (3)
56
57#define XATTR_ALIGN(size) ((size + XATTR_ROUND) & ~XATTR_ROUND)
58
59#define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
60 entry->e_name_len + le16_to_cpu(entry->e_value_size)))
61
62#define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
63 ENTRY_SIZE(entry)))
64
65#define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
66
67#define list_for_each_xattr(entry, addr) \
68 for (entry = XATTR_FIRST_ENTRY(addr);\
69 !IS_XATTR_LAST_ENTRY(entry);\
70 entry = XATTR_NEXT_ENTRY(entry))
71
Jaegeuk Kim65985d92013-08-14 21:57:27 +090072#define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + PAGE_SIZE - \
73 sizeof(struct node_footer) - sizeof(__u32))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090074
Jaegeuk Kim65985d92013-08-14 21:57:27 +090075#define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \
76 sizeof(struct f2fs_xattr_header) - \
77 sizeof(struct f2fs_xattr_entry))
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090078
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +090079/*
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090080 * On-disk structure of f2fs_xattr
Jaegeuk Kim65985d92013-08-14 21:57:27 +090081 * We use inline xattrs space + 1 block for xattr.
Jaegeuk Kimaf48b852012-11-02 17:12:17 +090082 *
83 * +--------------------+
84 * | f2fs_xattr_header |
85 * | |
86 * +--------------------+
87 * | f2fs_xattr_entry |
88 * | .e_name_index = 1 |
89 * | .e_name_len = 3 |
90 * | .e_value_size = 14 |
91 * | .e_name = "foo" |
92 * | "value_of_xattr" |<- value_offs = e_name + e_name_len
93 * +--------------------+
94 * | f2fs_xattr_entry |
95 * | .e_name_index = 4 |
96 * | .e_name = "bar" |
97 * +--------------------+
98 * | |
99 * | Free |
100 * | |
101 * +--------------------+<- MIN_OFFSET
102 * | node_footer |
103 * | (nid, ino, offset) |
104 * +--------------------+
105 *
106 **/
107
108#ifdef CONFIG_F2FS_FS_XATTR
109extern const struct xattr_handler f2fs_xattr_user_handler;
110extern const struct xattr_handler f2fs_xattr_trusted_handler;
111extern const struct xattr_handler f2fs_xattr_acl_access_handler;
112extern const struct xattr_handler f2fs_xattr_acl_default_handler;
113extern const struct xattr_handler f2fs_xattr_advise_handler;
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900114extern const struct xattr_handler f2fs_xattr_security_handler;
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900115
116extern const struct xattr_handler *f2fs_xattr_handlers[];
117
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900118extern int f2fs_setxattr(struct inode *, int, const char *,
119 const void *, size_t, struct page *);
120extern int f2fs_getxattr(struct inode *, int, const char *, void *, size_t);
121extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900122#else
123
124#define f2fs_xattr_handlers NULL
125static inline int f2fs_setxattr(struct inode *inode, int name_index,
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900126 const char *name, const void *value, size_t value_len)
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900127{
128 return -EOPNOTSUPP;
129}
130static inline int f2fs_getxattr(struct inode *inode, int name_index,
131 const char *name, void *buffer, size_t buffer_size)
132{
133 return -EOPNOTSUPP;
134}
135static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer,
136 size_t buffer_size)
137{
138 return -EOPNOTSUPP;
139}
140#endif
141
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900142#ifdef CONFIG_F2FS_FS_SECURITY
143extern int f2fs_init_security(struct inode *, struct inode *,
144 const struct qstr *, struct page *);
145#else
146static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
147 const struct qstr *qstr, struct page *ipage)
148{
149 return 0;
150}
151#endif
Jaegeuk Kimaf48b852012-11-02 17:12:17 +0900152#endif /* __F2FS_XATTR_H__ */