xattr_trusted.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * xattr_trusted.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_TRUSTED_PREFIX "trusted."
  38. static size_t ocfs2_xattr_trusted_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_TRUSTED_PREFIX) - 1;
  43. const size_t total_len = prefix_len + name_len + 1;
  44. if (list && total_len <= list_size) {
  45. memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
  46. memcpy(list + prefix_len, name, name_len);
  47. list[prefix_len + name_len] = '\0';
  48. }
  49. return total_len;
  50. }
  51. static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name,
  52. void *buffer, size_t size)
  53. {
  54. if (strcmp(name, "") == 0)
  55. return -EINVAL;
  56. return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name,
  57. buffer, size);
  58. }
  59. static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name,
  60. const void *value, size_t size, int flags)
  61. {
  62. if (strcmp(name, "") == 0)
  63. return -EINVAL;
  64. return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value,
  65. size, flags);
  66. }
  67. struct xattr_handler ocfs2_xattr_trusted_handler = {
  68. .prefix = XATTR_TRUSTED_PREFIX,
  69. .list = ocfs2_xattr_trusted_list,
  70. .get = ocfs2_xattr_trusted_get,
  71. .set = ocfs2_xattr_trusted_set,
  72. };