Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * fs/f2fs/xattr.h
0004  *
0005  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
0006  *             http://www.samsung.com/
0007  *
0008  * Portions of this code from linux/fs/ext2/xattr.h
0009  *
0010  * On-disk format of extended attributes for the ext2 filesystem.
0011  *
0012  * (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
0013  */
0014 #ifndef __F2FS_XATTR_H__
0015 #define __F2FS_XATTR_H__
0016 
0017 #include <linux/init.h>
0018 #include <linux/xattr.h>
0019 
0020 /* Magic value in attribute blocks */
0021 #define F2FS_XATTR_MAGIC                0xF2F52011
0022 
0023 /* Maximum number of references to one attribute block */
0024 #define F2FS_XATTR_REFCOUNT_MAX         1024
0025 
0026 /* Name indexes */
0027 #define F2FS_SYSTEM_ADVISE_NAME         "system.advise"
0028 #define F2FS_XATTR_INDEX_USER           1
0029 #define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS   2
0030 #define F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT  3
0031 #define F2FS_XATTR_INDEX_TRUSTED        4
0032 #define F2FS_XATTR_INDEX_LUSTRE         5
0033 #define F2FS_XATTR_INDEX_SECURITY       6
0034 #define F2FS_XATTR_INDEX_ADVISE         7
0035 /* Should be same as EXT4_XATTR_INDEX_ENCRYPTION */
0036 #define F2FS_XATTR_INDEX_ENCRYPTION     9
0037 #define F2FS_XATTR_INDEX_VERITY         11
0038 
0039 #define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT  "c"
0040 #define F2FS_XATTR_NAME_VERITY          "v"
0041 
0042 struct f2fs_xattr_header {
0043     __le32  h_magic;        /* magic number for identification */
0044     __le32  h_refcount;     /* reference count */
0045     __u32   h_reserved[4];  /* zero right now */
0046 };
0047 
0048 struct f2fs_xattr_entry {
0049     __u8    e_name_index;
0050     __u8    e_name_len;
0051     __le16  e_value_size;   /* size of attribute value */
0052     char    e_name[];      /* attribute name */
0053 };
0054 
0055 #define XATTR_HDR(ptr)      ((struct f2fs_xattr_header *)(ptr))
0056 #define XATTR_ENTRY(ptr)    ((struct f2fs_xattr_entry *)(ptr))
0057 #define XATTR_FIRST_ENTRY(ptr)  (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
0058 #define XATTR_ROUND     (3)
0059 
0060 #define XATTR_ALIGN(size)   (((size) + XATTR_ROUND) & ~XATTR_ROUND)
0061 
0062 #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
0063             (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)))
0064 
0065 #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
0066             ENTRY_SIZE(entry)))
0067 
0068 #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
0069 
0070 #define list_for_each_xattr(entry, addr) \
0071         for (entry = XATTR_FIRST_ENTRY(addr);\
0072                 !IS_XATTR_LAST_ENTRY(entry);\
0073                 entry = XATTR_NEXT_ENTRY(entry))
0074 #define VALID_XATTR_BLOCK_SIZE  (PAGE_SIZE - sizeof(struct node_footer))
0075 #define XATTR_PADDING_SIZE  (sizeof(__u32))
0076 #define XATTR_SIZE(i)       ((F2FS_I(i)->i_xattr_nid ?      \
0077                     VALID_XATTR_BLOCK_SIZE : 0) +   \
0078                         (inline_xattr_size(i)))
0079 #define MIN_OFFSET(i)       XATTR_ALIGN(inline_xattr_size(i) +  \
0080                         VALID_XATTR_BLOCK_SIZE)
0081 
0082 #define MAX_VALUE_LEN(i)    (MIN_OFFSET(i) -            \
0083                 sizeof(struct f2fs_xattr_header) -  \
0084                 sizeof(struct f2fs_xattr_entry))
0085 
0086 #define MAX_INLINE_XATTR_SIZE                       \
0087             (DEF_ADDRS_PER_INODE -              \
0088             F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) -   \
0089             DEF_INLINE_RESERVED_SIZE -          \
0090             MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
0091 
0092 /*
0093  * On-disk structure of f2fs_xattr
0094  * We use inline xattrs space + 1 block for xattr.
0095  *
0096  * +--------------------+
0097  * | f2fs_xattr_header  |
0098  * |                    |
0099  * +--------------------+
0100  * | f2fs_xattr_entry   |
0101  * | .e_name_index = 1  |
0102  * | .e_name_len = 3    |
0103  * | .e_value_size = 14 |
0104  * | .e_name = "foo"    |
0105  * | "value_of_xattr"   |<- value_offs = e_name + e_name_len
0106  * +--------------------+
0107  * | f2fs_xattr_entry   |
0108  * | .e_name_index = 4  |
0109  * | .e_name = "bar"    |
0110  * +--------------------+
0111  * |                    |
0112  * |        Free        |
0113  * |                    |
0114  * +--------------------+<- MIN_OFFSET
0115  * |   node_footer      |
0116  * | (nid, ino, offset) |
0117  * +--------------------+
0118  *
0119  **/
0120 
0121 #ifdef CONFIG_F2FS_FS_XATTR
0122 extern const struct xattr_handler f2fs_xattr_user_handler;
0123 extern const struct xattr_handler f2fs_xattr_trusted_handler;
0124 extern const struct xattr_handler f2fs_xattr_advise_handler;
0125 extern const struct xattr_handler f2fs_xattr_security_handler;
0126 
0127 extern const struct xattr_handler *f2fs_xattr_handlers[];
0128 
0129 extern int f2fs_setxattr(struct inode *, int, const char *,
0130                 const void *, size_t, struct page *, int);
0131 extern int f2fs_getxattr(struct inode *, int, const char *, void *,
0132                         size_t, struct page *);
0133 extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
0134 extern int f2fs_init_xattr_caches(struct f2fs_sb_info *);
0135 extern void f2fs_destroy_xattr_caches(struct f2fs_sb_info *);
0136 #else
0137 
0138 #define f2fs_xattr_handlers NULL
0139 #define f2fs_listxattr      NULL
0140 static inline int f2fs_setxattr(struct inode *inode, int index,
0141         const char *name, const void *value, size_t size,
0142         struct page *page, int flags)
0143 {
0144     return -EOPNOTSUPP;
0145 }
0146 static inline int f2fs_getxattr(struct inode *inode, int index,
0147             const char *name, void *buffer,
0148             size_t buffer_size, struct page *dpage)
0149 {
0150     return -EOPNOTSUPP;
0151 }
0152 static inline int f2fs_init_xattr_caches(struct f2fs_sb_info *sbi) { return 0; }
0153 static inline void f2fs_destroy_xattr_caches(struct f2fs_sb_info *sbi) { }
0154 #endif
0155 
0156 #ifdef CONFIG_F2FS_FS_SECURITY
0157 extern int f2fs_init_security(struct inode *, struct inode *,
0158                 const struct qstr *, struct page *);
0159 #else
0160 static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
0161                 const struct qstr *qstr, struct page *ipage)
0162 {
0163     return 0;
0164 }
0165 #endif
0166 #endif /* __F2FS_XATTR_H__ */