posix_acl.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. File: linux/posix_acl.h
  4. (C) 2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
  5. */
  6. #ifndef __LINUX_POSIX_ACL_H
  7. #define __LINUX_POSIX_ACL_H
  8. #include <linux/bug.h>
  9. #include <linux/slab.h>
  10. #include <linux/rcupdate.h>
  11. #include <linux/refcount.h>
  12. #include <uapi/linux/posix_acl.h>
  13. struct posix_acl_entry {
  14. short e_tag;
  15. unsigned short e_perm;
  16. union {
  17. kuid_t e_uid;
  18. kgid_t e_gid;
  19. };
  20. };
  21. struct posix_acl {
  22. refcount_t a_refcount;
  23. struct rcu_head a_rcu;
  24. unsigned int a_count;
  25. struct posix_acl_entry a_entries[];
  26. };
  27. #define FOREACH_ACL_ENTRY(pa, acl, pe) \
  28. for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
  29. /*
  30. * Duplicate an ACL handle.
  31. */
  32. static inline struct posix_acl *
  33. posix_acl_dup(struct posix_acl *acl)
  34. {
  35. if (acl)
  36. refcount_inc(&acl->a_refcount);
  37. return acl;
  38. }
  39. /*
  40. * Free an ACL handle.
  41. */
  42. static inline void
  43. posix_acl_release(struct posix_acl *acl)
  44. {
  45. if (acl && refcount_dec_and_test(&acl->a_refcount))
  46. kfree_rcu(acl, a_rcu);
  47. }
  48. /* posix_acl.c */
  49. extern void posix_acl_init(struct posix_acl *, int);
  50. extern struct posix_acl *posix_acl_alloc(int, gfp_t);
  51. extern int posix_acl_valid(struct user_namespace *, const struct posix_acl *);
  52. extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
  53. extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
  54. extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
  55. extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
  56. extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
  57. extern struct posix_acl *get_posix_acl(struct inode *, int);
  58. extern int set_posix_acl(struct inode *, int, struct posix_acl *);
  59. #ifdef CONFIG_FS_POSIX_ACL
  60. extern int posix_acl_chmod(struct inode *, umode_t);
  61. extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **,
  62. struct posix_acl **);
  63. extern int posix_acl_update_mode(struct inode *, umode_t *, struct posix_acl **);
  64. extern int simple_set_acl(struct inode *, struct posix_acl *, int);
  65. extern int simple_acl_create(struct inode *, struct inode *);
  66. struct posix_acl *get_cached_acl(struct inode *inode, int type);
  67. struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type);
  68. void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl);
  69. void forget_cached_acl(struct inode *inode, int type);
  70. void forget_all_cached_acls(struct inode *inode);
  71. static inline void cache_no_acl(struct inode *inode)
  72. {
  73. inode->i_acl = NULL;
  74. inode->i_default_acl = NULL;
  75. }
  76. #else
  77. static inline int posix_acl_chmod(struct inode *inode, umode_t mode)
  78. {
  79. return 0;
  80. }
  81. #define simple_set_acl NULL
  82. static inline int simple_acl_create(struct inode *dir, struct inode *inode)
  83. {
  84. return 0;
  85. }
  86. static inline void cache_no_acl(struct inode *inode)
  87. {
  88. }
  89. static inline int posix_acl_create(struct inode *inode, umode_t *mode,
  90. struct posix_acl **default_acl, struct posix_acl **acl)
  91. {
  92. *default_acl = *acl = NULL;
  93. return 0;
  94. }
  95. static inline void forget_all_cached_acls(struct inode *inode)
  96. {
  97. }
  98. #endif /* CONFIG_FS_POSIX_ACL */
  99. struct posix_acl *get_acl(struct inode *inode, int type);
  100. #endif /* __LINUX_POSIX_ACL_H */