xattr_user.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * xattr_user.c
  5. *
  6. * Copyright (C) 2008 Oracle. All rights reserved.
  7. *
  8. * CREDITS:
  9. * Lots of code in this file is taken from ext3.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public
  22. * License along with this program; if not, write to the
  23. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. * Boston, MA 021110-1307, USA.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/string.h>
  29. #define MLOG_MASK_PREFIX ML_INODE
  30. #include <cluster/masklog.h>
  31. #include "ocfs2.h"
  32. #include "alloc.h"
  33. #include "dlmglue.h"
  34. #include "file.h"
  35. #include "ocfs2_fs.h"
  36. #include "xattr.h"
  37. #define XATTR_USER_PREFIX "user."
  38. static size_t ocfs2_xattr_user_list(struct inode *inode, char *list,
  39. size_t list_size, const char *name,
  40. size_t name_len)
  41. {
  42. const size_t prefix_len = sizeof(XATTR_USER_PREFIX) - 1;
  43. const size_t total_len = prefix_len + name_len + 1;
  44. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  45. if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
  46. return 0;
  47. if (list && total_len <= list_size) {
  48. memcpy(list, XATTR_USER_PREFIX, prefix_len);
  49. memcpy(list + prefix_len, name, name_len);
  50. list[prefix_len + name_len] = '\0';
  51. }
  52. return total_len;
  53. }
  54. static int ocfs2_xattr_user_get(struct inode *inode, const char *name,
  55. void *buffer, size_t size)
  56. {
  57. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  58. if (strcmp(name, "") == 0)
  59. return -EINVAL;
  60. if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
  61. return -EOPNOTSUPP;
  62. return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name,
  63. buffer, size);
  64. }
  65. static int ocfs2_xattr_user_set(struct inode *inode, const char *name,
  66. const void *value, size_t size, int flags)
  67. {
  68. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  69. if (strcmp(name, "") == 0)
  70. return -EINVAL;
  71. if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR)
  72. return -EOPNOTSUPP;
  73. return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value,
  74. size, flags);
  75. }
  76. struct xattr_handler ocfs2_xattr_user_handler = {
  77. .prefix = XATTR_USER_PREFIX,
  78. .list = ocfs2_xattr_user_list,
  79. .get = ocfs2_xattr_user_get,
  80. .set = ocfs2_xattr_user_set,
  81. };