aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/xattr.c')
-rw-r--r--fs/ocfs2/xattr.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index e21a1a8b4257..0f556b00235e 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -37,6 +37,9 @@
37#include <linux/writeback.h> 37#include <linux/writeback.h>
38#include <linux/falloc.h> 38#include <linux/falloc.h>
39#include <linux/sort.h> 39#include <linux/sort.h>
40#include <linux/init.h>
41#include <linux/module.h>
42#include <linux/string.h>
40 43
41#define MLOG_MASK_PREFIX ML_XATTR 44#define MLOG_MASK_PREFIX ML_XATTR
42#include <cluster/masklog.h> 45#include <cluster/masklog.h>
@@ -4740,3 +4743,110 @@ static int ocfs2_delete_xattr_index_block(struct inode *inode,
4740out: 4743out:
4741 return ret; 4744 return ret;
4742} 4745}
4746
4747/*
4748 * 'trusted' attributes support
4749 */
4750
4751#define XATTR_TRUSTED_PREFIX "trusted."
4752
4753static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list,
4754 size_t list_size, const char *name,
4755 size_t name_len)
4756{
4757 const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX) - 1;
4758 const size_t total_len = prefix_len + name_len + 1;
4759
4760 if (list && total_len <= list_size) {
4761 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
4762 memcpy(list + prefix_len, name, name_len);
4763 list[prefix_len + name_len] = '\0';
4764 }
4765 return total_len;
4766}
4767
4768static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name,
4769 void *buffer, size_t size)
4770{
4771 if (strcmp(name, "") == 0)
4772 return -EINVAL;
4773 return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name,
4774 buffer, size);
4775}
4776
4777static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name,
4778 const void *value, size_t size, int flags)
4779{
4780 if (strcmp(name, "") == 0)
4781 return -EINVAL;
4782
4783 return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value,
4784 size, flags);
4785}
4786
4787struct xattr_handler ocfs2_xattr_trusted_handler = {
4788 .prefix = XATTR_TRUSTED_PREFIX,
4789 .list = ocfs2_xattr_trusted_list,
4790 .get = ocfs2_xattr_trusted_get,
4791 .set = ocfs2_xattr_trusted_set,
4792};
4793
4794
4795/*
4796 * 'user' attributes support
4797 */
4798
4799#define XATTR_USER_PREFIX "user."
4800
4801static size_t ocfs2_xattr_user_list(struct inode *inode, char *list,
4802 size_t list_size, const char *name,
4803 size_t name_len)
4804{
4805 const size_t prefix_len = sizeof(XATTR_USER_PREFIX) - 1;
4806 const size_t total_len = prefix_len + name_len + 1;
4807 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
4808
4809 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
4810 return 0;
4811
4812 if (list && total_len <= list_size) {
4813 memcpy(list, XATTR_USER_PREFIX, prefix_len);
4814 memcpy(list + prefix_len, name, name_len);
4815 list[prefix_len + name_len] = '\0';
4816 }
4817 return total_len;
4818}
4819
4820static int ocfs2_xattr_user_get(struct inode *inode, const char *name,
4821 void *buffer, size_t size)
4822{
4823 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
4824
4825 if (strcmp(name, "") == 0)
4826 return -EINVAL;
4827 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
4828 return -EOPNOTSUPP;
4829 return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name,
4830 buffer, size);
4831}
4832
4833static int ocfs2_xattr_user_set(struct inode *inode, const char *name,
4834 const void *value, size_t size, int flags)
4835{
4836 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
4837
4838 if (strcmp(name, "") == 0)
4839 return -EINVAL;
4840 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
4841 return -EOPNOTSUPP;
4842
4843 return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value,
4844 size, flags);
4845}
4846
4847struct xattr_handler ocfs2_xattr_user_handler = {
4848 .prefix = XATTR_USER_PREFIX,
4849 .list = ocfs2_xattr_user_list,
4850 .get = ocfs2_xattr_user_get,
4851 .set = ocfs2_xattr_user_set,
4852};