posix_acl.h 3.3 KB

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