18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#include <linux/reiserfs_xattr.h>
38c2ecf20Sopenharmony_ci#include <linux/init.h>
48c2ecf20Sopenharmony_ci#include <linux/list.h>
58c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
68c2ecf20Sopenharmony_ci#include <linux/xattr.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistruct inode;
98c2ecf20Sopenharmony_cistruct dentry;
108c2ecf20Sopenharmony_cistruct iattr;
118c2ecf20Sopenharmony_cistruct super_block;
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciint reiserfs_xattr_register_handlers(void) __init;
148c2ecf20Sopenharmony_civoid reiserfs_xattr_unregister_handlers(void);
158c2ecf20Sopenharmony_ciint reiserfs_xattr_init(struct super_block *sb, int mount_flags);
168c2ecf20Sopenharmony_ciint reiserfs_lookup_privroot(struct super_block *sb);
178c2ecf20Sopenharmony_ciint reiserfs_delete_xattrs(struct inode *inode);
188c2ecf20Sopenharmony_ciint reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
198c2ecf20Sopenharmony_ciint reiserfs_permission(struct inode *inode, int mask);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_FS_XATTR
228c2ecf20Sopenharmony_ci#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
238c2ecf20Sopenharmony_cissize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciint reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
268c2ecf20Sopenharmony_ciint reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
278c2ecf20Sopenharmony_ciint reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
288c2ecf20Sopenharmony_ci			      struct inode *, const char *, const void *,
298c2ecf20Sopenharmony_ci			      size_t, int);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_user_handler;
328c2ecf20Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_trusted_handler;
338c2ecf20Sopenharmony_ciextern const struct xattr_handler reiserfs_xattr_security_handler;
348c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_FS_SECURITY
358c2ecf20Sopenharmony_ciint reiserfs_security_init(struct inode *dir, struct inode *inode,
368c2ecf20Sopenharmony_ci			   const struct qstr *qstr,
378c2ecf20Sopenharmony_ci			   struct reiserfs_security_handle *sec);
388c2ecf20Sopenharmony_ciint reiserfs_security_write(struct reiserfs_transaction_handle *th,
398c2ecf20Sopenharmony_ci			    struct inode *inode,
408c2ecf20Sopenharmony_ci			    struct reiserfs_security_handle *sec);
418c2ecf20Sopenharmony_civoid reiserfs_security_free(struct reiserfs_security_handle *sec);
428c2ecf20Sopenharmony_ci#endif
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline int reiserfs_xattrs_initialized(struct super_block *sb)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	return REISERFS_SB(sb)->priv_root && REISERFS_SB(sb)->xattr_root;
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
508c2ecf20Sopenharmony_cistatic inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	loff_t ret = 0;
538c2ecf20Sopenharmony_ci	if (reiserfs_file_data_log(inode)) {
548c2ecf20Sopenharmony_ci		ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
558c2ecf20Sopenharmony_ci		ret >>= inode->i_sb->s_blocksize_bits;
568c2ecf20Sopenharmony_ci	}
578c2ecf20Sopenharmony_ci	return ret;
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/*
618c2ecf20Sopenharmony_ci * We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
628c2ecf20Sopenharmony_ci * Let's try to be smart about it.
638c2ecf20Sopenharmony_ci * xattr root: We cache it. If it's not cached, we may need to create it.
648c2ecf20Sopenharmony_ci * xattr dir: If anything has been loaded for this inode, we can set a flag
658c2ecf20Sopenharmony_ci *            saying so.
668c2ecf20Sopenharmony_ci * xattr file: Since we don't cache xattrs, we can't tell. We always include
678c2ecf20Sopenharmony_ci *             blocks for it.
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci * However, since root and dir can be created between calls - YOU MUST SAVE
708c2ecf20Sopenharmony_ci * THIS VALUE.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_cistatic inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
778c2ecf20Sopenharmony_ci		nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
788c2ecf20Sopenharmony_ci		if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
798c2ecf20Sopenharmony_ci			nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
808c2ecf20Sopenharmony_ci	}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	return nblocks;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline void reiserfs_init_xattr_rwsem(struct inode *inode)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#else
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define reiserfs_listxattr NULL
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline void reiserfs_init_xattr_rwsem(struct inode *inode)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci#endif  /*  CONFIG_REISERFS_FS_XATTR  */
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#ifndef CONFIG_REISERFS_FS_SECURITY
1008c2ecf20Sopenharmony_cistatic inline int reiserfs_security_init(struct inode *dir,
1018c2ecf20Sopenharmony_ci					 struct inode *inode,
1028c2ecf20Sopenharmony_ci					 const struct qstr *qstr,
1038c2ecf20Sopenharmony_ci					 struct reiserfs_security_handle *sec)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	return 0;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_cistatic inline int
1088c2ecf20Sopenharmony_cireiserfs_security_write(struct reiserfs_transaction_handle *th,
1098c2ecf20Sopenharmony_ci			struct inode *inode,
1108c2ecf20Sopenharmony_ci			struct reiserfs_security_handle *sec)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	return 0;
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_cistatic inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
1158c2ecf20Sopenharmony_ci{}
1168c2ecf20Sopenharmony_ci#endif
117