posix_acl.h 3.0 KB

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