Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 2 | #include <linux/reiserfs_xattr.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/list.h> |
| 5 | #include <linux/rwsem.h> |
Al Viro | 79a628d | 2016-04-10 18:50:48 -0400 | [diff] [blame] | 6 | #include <linux/xattr.h> |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 7 | |
| 8 | struct inode; |
| 9 | struct dentry; |
| 10 | struct iattr; |
| 11 | struct super_block; |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 12 | |
| 13 | int reiserfs_xattr_register_handlers(void) __init; |
| 14 | void reiserfs_xattr_unregister_handlers(void); |
| 15 | int reiserfs_xattr_init(struct super_block *sb, int mount_flags); |
| 16 | int reiserfs_lookup_privroot(struct super_block *sb); |
| 17 | int reiserfs_delete_xattrs(struct inode *inode); |
| 18 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs); |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame^] | 19 | int reiserfs_permission(struct user_namespace *mnt_userns, |
| 20 | struct inode *inode, int mask); |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 21 | |
| 22 | #ifdef CONFIG_REISERFS_FS_XATTR |
| 23 | #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir) |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 24 | ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 25 | |
| 26 | int reiserfs_xattr_get(struct inode *, const char *, void *, size_t); |
| 27 | int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int); |
| 28 | int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *, |
| 29 | struct inode *, const char *, const void *, |
| 30 | size_t, int); |
| 31 | |
| 32 | extern const struct xattr_handler reiserfs_xattr_user_handler; |
| 33 | extern const struct xattr_handler reiserfs_xattr_trusted_handler; |
| 34 | extern const struct xattr_handler reiserfs_xattr_security_handler; |
| 35 | #ifdef CONFIG_REISERFS_FS_SECURITY |
| 36 | int reiserfs_security_init(struct inode *dir, struct inode *inode, |
| 37 | const struct qstr *qstr, |
| 38 | struct reiserfs_security_handle *sec); |
| 39 | int reiserfs_security_write(struct reiserfs_transaction_handle *th, |
| 40 | struct inode *inode, |
| 41 | struct reiserfs_security_handle *sec); |
| 42 | void reiserfs_security_free(struct reiserfs_security_handle *sec); |
| 43 | #endif |
| 44 | |
| 45 | static inline int reiserfs_xattrs_initialized(struct super_block *sb) |
| 46 | { |
| 47 | return REISERFS_SB(sb)->priv_root != NULL; |
| 48 | } |
| 49 | |
| 50 | #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header)) |
| 51 | static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size) |
| 52 | { |
| 53 | loff_t ret = 0; |
| 54 | if (reiserfs_file_data_log(inode)) { |
| 55 | ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize); |
| 56 | ret >>= inode->i_sb->s_blocksize_bits; |
| 57 | } |
| 58 | return ret; |
| 59 | } |
| 60 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 61 | /* |
| 62 | * We may have to create up to 3 objects: xattr root, xattr dir, xattr file. |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 63 | * Let's try to be smart about it. |
| 64 | * xattr root: We cache it. If it's not cached, we may need to create it. |
| 65 | * xattr dir: If anything has been loaded for this inode, we can set a flag |
| 66 | * saying so. |
| 67 | * xattr file: Since we don't cache xattrs, we can't tell. We always include |
| 68 | * blocks for it. |
| 69 | * |
| 70 | * However, since root and dir can be created between calls - YOU MUST SAVE |
| 71 | * THIS VALUE. |
| 72 | */ |
| 73 | static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode) |
| 74 | { |
| 75 | size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
| 76 | |
| 77 | if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) { |
| 78 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 79 | if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root)) |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 80 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
| 81 | } |
| 82 | |
| 83 | return nblocks; |
| 84 | } |
| 85 | |
| 86 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) |
| 87 | { |
| 88 | init_rwsem(&REISERFS_I(inode)->i_xattr_sem); |
| 89 | } |
| 90 | |
| 91 | #else |
| 92 | |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 93 | #define reiserfs_listxattr NULL |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 94 | |
| 95 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) |
| 96 | { |
| 97 | } |
| 98 | #endif /* CONFIG_REISERFS_FS_XATTR */ |
| 99 | |
| 100 | #ifndef CONFIG_REISERFS_FS_SECURITY |
| 101 | static inline int reiserfs_security_init(struct inode *dir, |
| 102 | struct inode *inode, |
| 103 | const struct qstr *qstr, |
| 104 | struct reiserfs_security_handle *sec) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | static inline int |
| 109 | reiserfs_security_write(struct reiserfs_transaction_handle *th, |
| 110 | struct inode *inode, |
| 111 | struct reiserfs_security_handle *sec) |
| 112 | { |
| 113 | return 0; |
| 114 | } |
| 115 | static inline void reiserfs_security_free(struct reiserfs_security_handle *sec) |
| 116 | {} |
| 117 | #endif |