xattr.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. File: linux/xattr.h
  3. Extended attributes handling.
  4. Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
  5. Copyright (c) 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
  6. Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
  7. */
  8. #ifndef _LINUX_XATTR_H
  9. #define _LINUX_XATTR_H
  10. #include <linux/slab.h>
  11. #include <linux/types.h>
  12. #include <linux/spinlock.h>
  13. #include <uapi/linux/xattr.h>
  14. struct inode;
  15. struct dentry;
  16. /*
  17. * struct xattr_handler: When @name is set, match attributes with exactly that
  18. * name. When @prefix is set instead, match attributes with that prefix and
  19. * with a non-empty suffix.
  20. */
  21. struct xattr_handler {
  22. const char *name;
  23. const char *prefix;
  24. int flags; /* fs private flags */
  25. size_t (*list)(const struct xattr_handler *, struct dentry *dentry,
  26. char *list, size_t list_size, const char *name,
  27. size_t name_len);
  28. int (*get)(const struct xattr_handler *, struct dentry *dentry,
  29. const char *name, void *buffer, size_t size);
  30. int (*set)(const struct xattr_handler *, struct dentry *dentry,
  31. const char *name, const void *buffer, size_t size,
  32. int flags);
  33. };
  34. const char *xattr_full_name(const struct xattr_handler *, const char *);
  35. struct xattr {
  36. const char *name;
  37. void *value;
  38. size_t value_len;
  39. };
  40. ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
  41. ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
  42. ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
  43. int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
  44. int vfs_setxattr(struct dentry *, const char *, const void *, size_t, int);
  45. int vfs_removexattr(struct dentry *, const char *);
  46. ssize_t generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size);
  47. ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
  48. int generic_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags);
  49. int generic_removexattr(struct dentry *dentry, const char *name);
  50. ssize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
  51. char **xattr_value, size_t size, gfp_t flags);
  52. static inline const char *xattr_prefix(const struct xattr_handler *handler)
  53. {
  54. return handler->prefix ?: handler->name;
  55. }
  56. struct simple_xattrs {
  57. struct list_head head;
  58. spinlock_t lock;
  59. };
  60. struct simple_xattr {
  61. struct list_head list;
  62. char *name;
  63. size_t size;
  64. char value[0];
  65. };
  66. /*
  67. * initialize the simple_xattrs structure
  68. */
  69. static inline void simple_xattrs_init(struct simple_xattrs *xattrs)
  70. {
  71. INIT_LIST_HEAD(&xattrs->head);
  72. spin_lock_init(&xattrs->lock);
  73. }
  74. /*
  75. * free all the xattrs
  76. */
  77. static inline void simple_xattrs_free(struct simple_xattrs *xattrs)
  78. {
  79. struct simple_xattr *xattr, *node;
  80. list_for_each_entry_safe(xattr, node, &xattrs->head, list) {
  81. kfree(xattr->name);
  82. kfree(xattr);
  83. }
  84. }
  85. struct simple_xattr *simple_xattr_alloc(const void *value, size_t size);
  86. int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
  87. void *buffer, size_t size);
  88. int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
  89. const void *value, size_t size, int flags);
  90. ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer, size_t size);
  91. void simple_xattr_list_add(struct simple_xattrs *xattrs,
  92. struct simple_xattr *new_xattr);
  93. #endif /* _LINUX_XATTR_H */