Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/reiserfs_xattr.h>
0003 #include <linux/init.h>
0004 #include <linux/list.h>
0005 #include <linux/rwsem.h>
0006 #include <linux/xattr.h>
0007 
0008 struct inode;
0009 struct dentry;
0010 struct iattr;
0011 struct super_block;
0012 
0013 int reiserfs_xattr_register_handlers(void) __init;
0014 void reiserfs_xattr_unregister_handlers(void);
0015 int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
0016 int reiserfs_lookup_privroot(struct super_block *sb);
0017 int reiserfs_delete_xattrs(struct inode *inode);
0018 int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
0019 int reiserfs_permission(struct user_namespace *mnt_userns,
0020             struct inode *inode, int mask);
0021 
0022 #ifdef CONFIG_REISERFS_FS_XATTR
0023 #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
0024 ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
0025 
0026 int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
0027 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
0028 int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
0029                   struct inode *, const char *, const void *,
0030                   size_t, int);
0031 
0032 extern const struct xattr_handler reiserfs_xattr_user_handler;
0033 extern const struct xattr_handler reiserfs_xattr_trusted_handler;
0034 extern const struct xattr_handler reiserfs_xattr_security_handler;
0035 #ifdef CONFIG_REISERFS_FS_SECURITY
0036 int reiserfs_security_init(struct inode *dir, struct inode *inode,
0037                const struct qstr *qstr,
0038                struct reiserfs_security_handle *sec);
0039 int reiserfs_security_write(struct reiserfs_transaction_handle *th,
0040                 struct inode *inode,
0041                 struct reiserfs_security_handle *sec);
0042 void reiserfs_security_free(struct reiserfs_security_handle *sec);
0043 #endif
0044 
0045 static inline int reiserfs_xattrs_initialized(struct super_block *sb)
0046 {
0047     return REISERFS_SB(sb)->priv_root && REISERFS_SB(sb)->xattr_root;
0048 }
0049 
0050 #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
0051 static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
0052 {
0053     loff_t ret = 0;
0054     if (reiserfs_file_data_log(inode)) {
0055         ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
0056         ret >>= inode->i_sb->s_blocksize_bits;
0057     }
0058     return ret;
0059 }
0060 
0061 /*
0062  * We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
0063  * Let's try to be smart about it.
0064  * xattr root: We cache it. If it's not cached, we may need to create it.
0065  * xattr dir: If anything has been loaded for this inode, we can set a flag
0066  *            saying so.
0067  * xattr file: Since we don't cache xattrs, we can't tell. We always include
0068  *             blocks for it.
0069  *
0070  * However, since root and dir can be created between calls - YOU MUST SAVE
0071  * THIS VALUE.
0072  */
0073 static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
0074 {
0075     size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
0076 
0077     if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
0078         nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
0079         if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
0080             nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
0081     }
0082 
0083     return nblocks;
0084 }
0085 
0086 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
0087 {
0088     init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
0089 }
0090 
0091 #else
0092 
0093 #define reiserfs_listxattr NULL
0094 
0095 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
0096 {
0097 }
0098 #endif  /*  CONFIG_REISERFS_FS_XATTR  */
0099 
0100 #ifndef CONFIG_REISERFS_FS_SECURITY
0101 static inline int reiserfs_security_init(struct inode *dir,
0102                      struct inode *inode,
0103                      const struct qstr *qstr,
0104                      struct reiserfs_security_handle *sec)
0105 {
0106     return 0;
0107 }
0108 static inline int
0109 reiserfs_security_write(struct reiserfs_transaction_handle *th,
0110             struct inode *inode,
0111             struct reiserfs_security_handle *sec)
0112 {
0113     return 0;
0114 }
0115 static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
0116 {}
0117 #endif