xattr.h 3.6 KB

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