xattr_trusted.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2006 NEC Corporation
  5. *
  6. * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/fs.h>
  13. #include <linux/jffs2.h>
  14. #include <linux/xattr.h>
  15. #include <linux/mtd/mtd.h>
  16. #include "nodelist.h"
  17. static int jffs2_trusted_getxattr(const struct xattr_handler *handler,
  18. struct dentry *dentry, const char *name,
  19. void *buffer, size_t size)
  20. {
  21. if (!strcmp(name, ""))
  22. return -EINVAL;
  23. return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_TRUSTED,
  24. name, buffer, size);
  25. }
  26. static int jffs2_trusted_setxattr(const struct xattr_handler *handler,
  27. struct dentry *dentry, const char *name,
  28. const void *buffer, size_t size, int flags)
  29. {
  30. if (!strcmp(name, ""))
  31. return -EINVAL;
  32. return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_TRUSTED,
  33. name, buffer, size, flags);
  34. }
  35. static size_t jffs2_trusted_listxattr(const struct xattr_handler *handler,
  36. struct dentry *dentry, char *list,
  37. size_t list_size, const char *name,
  38. size_t name_len)
  39. {
  40. size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1;
  41. if (!capable(CAP_SYS_ADMIN))
  42. return 0;
  43. if (list && retlen<=list_size) {
  44. strcpy(list, XATTR_TRUSTED_PREFIX);
  45. strcpy(list + XATTR_TRUSTED_PREFIX_LEN, name);
  46. }
  47. return retlen;
  48. }
  49. const struct xattr_handler jffs2_trusted_xattr_handler = {
  50. .prefix = XATTR_TRUSTED_PREFIX,
  51. .list = jffs2_trusted_listxattr,
  52. .set = jffs2_trusted_setxattr,
  53. .get = jffs2_trusted_getxattr
  54. };