xattr.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /************************************************************************/
  18. /* */
  19. /* PROJECT : exFAT & FAT12/16/32 File System */
  20. /* FILE : xattr.c */
  21. /* PURPOSE : sdFAT code for supporting xattr(Extended File Attributes) */
  22. /* */
  23. /*----------------------------------------------------------------------*/
  24. /* NOTES */
  25. /* */
  26. /* */
  27. /************************************************************************/
  28. #include <linux/file.h>
  29. #include <linux/fs.h>
  30. #include <linux/xattr.h>
  31. #include <linux/dcache.h>
  32. #include "sdfat.h"
  33. #ifndef CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL
  34. #define CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL ("undefined")
  35. #endif
  36. static const char default_xattr[] = CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL;
  37. static int can_support(const char *name)
  38. {
  39. if (!name || strcmp(name, "security.selinux"))
  40. return -1;
  41. return 0;
  42. }
  43. ssize_t sdfat_listxattr(struct dentry *dentry, char *list, size_t size)
  44. {
  45. return 0;
  46. }
  47. /*************************************************************************
  48. * INNER FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
  49. *************************************************************************/
  50. static int __sdfat_xattr_check_support(const char *name)
  51. {
  52. if (can_support(name))
  53. return -EOPNOTSUPP;
  54. return 0;
  55. }
  56. ssize_t __sdfat_getxattr(const char *name, void *value, size_t size)
  57. {
  58. if (can_support(name))
  59. return -EOPNOTSUPP;
  60. if ((size > strlen(default_xattr)+1) && value)
  61. strcpy(value, default_xattr);
  62. return strlen(default_xattr);
  63. }
  64. /*************************************************************************
  65. * FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
  66. *************************************************************************/
  67. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
  68. static int sdfat_xattr_get(const struct xattr_handler *handler,
  69. struct dentry *dentry, struct inode *inode,
  70. const char *name, void *buffer, size_t size)
  71. {
  72. return __sdfat_getxattr(name, buffer, size);
  73. }
  74. static int sdfat_xattr_set(const struct xattr_handler *handler,
  75. struct dentry *dentry, struct inode *inode,
  76. const char *name, const void *value, size_t size,
  77. int flags)
  78. {
  79. return __sdfat_xattr_check_support(name);
  80. }
  81. const struct xattr_handler sdfat_xattr_handler = {
  82. .prefix = "", /* match anything */
  83. .get = sdfat_xattr_get,
  84. .set = sdfat_xattr_set,
  85. };
  86. const struct xattr_handler *sdfat_xattr_handlers[] = {
  87. &sdfat_xattr_handler,
  88. NULL
  89. };
  90. void setup_sdfat_xattr_handler(struct super_block *sb)
  91. {
  92. sb->s_xattr = sdfat_xattr_handlers;
  93. }
  94. #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) */
  95. int sdfat_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags)
  96. {
  97. return __sdfat_xattr_check_support(name);
  98. }
  99. ssize_t sdfat_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
  100. {
  101. return __sdfat_getxattr(name, value, size);
  102. }
  103. int sdfat_removexattr(struct dentry *dentry, const char *name)
  104. {
  105. return __sdfat_xattr_check_support(name);
  106. }
  107. void setup_sdfat_xattr_handler(struct super_block *sb)
  108. {
  109. /* DO NOTHING */
  110. }
  111. #endif