162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#include <linux/reiserfs_xattr.h> 362306a36Sopenharmony_ci#include <linux/init.h> 462306a36Sopenharmony_ci#include <linux/list.h> 562306a36Sopenharmony_ci#include <linux/rwsem.h> 662306a36Sopenharmony_ci#include <linux/xattr.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_cistruct inode; 962306a36Sopenharmony_cistruct dentry; 1062306a36Sopenharmony_cistruct iattr; 1162306a36Sopenharmony_cistruct super_block; 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciint reiserfs_xattr_register_handlers(void) __init; 1462306a36Sopenharmony_civoid reiserfs_xattr_unregister_handlers(void); 1562306a36Sopenharmony_ciint reiserfs_xattr_init(struct super_block *sb, int mount_flags); 1662306a36Sopenharmony_ciint reiserfs_lookup_privroot(struct super_block *sb); 1762306a36Sopenharmony_ciint reiserfs_delete_xattrs(struct inode *inode); 1862306a36Sopenharmony_ciint reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs); 1962306a36Sopenharmony_ciint reiserfs_permission(struct mnt_idmap *idmap, 2062306a36Sopenharmony_ci struct inode *inode, int mask); 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#ifdef CONFIG_REISERFS_FS_XATTR 2362306a36Sopenharmony_ci#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir) 2462306a36Sopenharmony_cissize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size); 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciint reiserfs_xattr_get(struct inode *, const char *, void *, size_t); 2762306a36Sopenharmony_ciint reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int); 2862306a36Sopenharmony_ciint reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *, 2962306a36Sopenharmony_ci struct inode *, const char *, const void *, 3062306a36Sopenharmony_ci size_t, int); 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_user_handler; 3362306a36Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_trusted_handler; 3462306a36Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_security_handler; 3562306a36Sopenharmony_ci#ifdef CONFIG_REISERFS_FS_SECURITY 3662306a36Sopenharmony_ciint reiserfs_security_init(struct inode *dir, struct inode *inode, 3762306a36Sopenharmony_ci const struct qstr *qstr, 3862306a36Sopenharmony_ci struct reiserfs_security_handle *sec); 3962306a36Sopenharmony_ciint reiserfs_security_write(struct reiserfs_transaction_handle *th, 4062306a36Sopenharmony_ci struct inode *inode, 4162306a36Sopenharmony_ci struct reiserfs_security_handle *sec); 4262306a36Sopenharmony_civoid reiserfs_security_free(struct reiserfs_security_handle *sec); 4362306a36Sopenharmony_ci#endif 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistatic inline int reiserfs_xattrs_initialized(struct super_block *sb) 4662306a36Sopenharmony_ci{ 4762306a36Sopenharmony_ci return REISERFS_SB(sb)->priv_root && REISERFS_SB(sb)->xattr_root; 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header)) 5162306a36Sopenharmony_cistatic inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size) 5262306a36Sopenharmony_ci{ 5362306a36Sopenharmony_ci loff_t ret = 0; 5462306a36Sopenharmony_ci if (reiserfs_file_data_log(inode)) { 5562306a36Sopenharmony_ci ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize); 5662306a36Sopenharmony_ci ret >>= inode->i_sb->s_blocksize_bits; 5762306a36Sopenharmony_ci } 5862306a36Sopenharmony_ci return ret; 5962306a36Sopenharmony_ci} 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/* 6262306a36Sopenharmony_ci * We may have to create up to 3 objects: xattr root, xattr dir, xattr file. 6362306a36Sopenharmony_ci * Let's try to be smart about it. 6462306a36Sopenharmony_ci * xattr root: We cache it. If it's not cached, we may need to create it. 6562306a36Sopenharmony_ci * xattr dir: If anything has been loaded for this inode, we can set a flag 6662306a36Sopenharmony_ci * saying so. 6762306a36Sopenharmony_ci * xattr file: Since we don't cache xattrs, we can't tell. We always include 6862306a36Sopenharmony_ci * blocks for it. 6962306a36Sopenharmony_ci * 7062306a36Sopenharmony_ci * However, since root and dir can be created between calls - YOU MUST SAVE 7162306a36Sopenharmony_ci * THIS VALUE. 7262306a36Sopenharmony_ci */ 7362306a36Sopenharmony_cistatic inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode) 7462306a36Sopenharmony_ci{ 7562306a36Sopenharmony_ci size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) { 7862306a36Sopenharmony_ci nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); 7962306a36Sopenharmony_ci if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root)) 8062306a36Sopenharmony_ci nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); 8162306a36Sopenharmony_ci } 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci return nblocks; 8462306a36Sopenharmony_ci} 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistatic inline void reiserfs_init_xattr_rwsem(struct inode *inode) 8762306a36Sopenharmony_ci{ 8862306a36Sopenharmony_ci init_rwsem(&REISERFS_I(inode)->i_xattr_sem); 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#else 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#define reiserfs_listxattr NULL 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistatic inline void reiserfs_init_xattr_rwsem(struct inode *inode) 9662306a36Sopenharmony_ci{ 9762306a36Sopenharmony_ci} 9862306a36Sopenharmony_ci#endif /* CONFIG_REISERFS_FS_XATTR */ 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#ifndef CONFIG_REISERFS_FS_SECURITY 10162306a36Sopenharmony_cistatic inline int reiserfs_security_init(struct inode *dir, 10262306a36Sopenharmony_ci struct inode *inode, 10362306a36Sopenharmony_ci const struct qstr *qstr, 10462306a36Sopenharmony_ci struct reiserfs_security_handle *sec) 10562306a36Sopenharmony_ci{ 10662306a36Sopenharmony_ci return 0; 10762306a36Sopenharmony_ci} 10862306a36Sopenharmony_cistatic inline int 10962306a36Sopenharmony_cireiserfs_security_write(struct reiserfs_transaction_handle *th, 11062306a36Sopenharmony_ci struct inode *inode, 11162306a36Sopenharmony_ci struct reiserfs_security_handle *sec) 11262306a36Sopenharmony_ci{ 11362306a36Sopenharmony_ci return 0; 11462306a36Sopenharmony_ci} 11562306a36Sopenharmony_cistatic inline void reiserfs_security_free(struct reiserfs_security_handle *sec) 11662306a36Sopenharmony_ci{} 11762306a36Sopenharmony_ci#endif 118