posix_acl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #define ACL_UNDEFINED_ID (-1)
  11. /* a_type field in acl_user_posix_entry_t */
  12. #define ACL_TYPE_ACCESS (0x8000)
  13. #define ACL_TYPE_DEFAULT (0x4000)
  14. /* e_tag entry in struct posix_acl_entry */
  15. #define ACL_USER_OBJ (0x01)
  16. #define ACL_USER (0x02)
  17. #define ACL_GROUP_OBJ (0x04)
  18. #define ACL_GROUP (0x08)
  19. #define ACL_MASK (0x10)
  20. #define ACL_OTHER (0x20)
  21. /* permissions in the e_perm field */
  22. #define ACL_READ (0x04)
  23. #define ACL_WRITE (0x02)
  24. #define ACL_EXECUTE (0x01)
  25. //#define ACL_ADD (0x08)
  26. //#define ACL_DELETE (0x10)
  27. struct posix_acl_entry {
  28. short e_tag;
  29. unsigned short e_perm;
  30. union {
  31. kuid_t e_uid;
  32. kgid_t e_gid;
  33. };
  34. };
  35. struct posix_acl {
  36. union {
  37. atomic_t a_refcount;
  38. struct rcu_head a_rcu;
  39. };
  40. unsigned int a_count;
  41. struct posix_acl_entry a_entries[0];
  42. };
  43. #define FOREACH_ACL_ENTRY(pa, acl, pe) \
  44. for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
  45. /*
  46. * Duplicate an ACL handle.
  47. */
  48. static inline struct posix_acl *
  49. posix_acl_dup(struct posix_acl *acl)
  50. {
  51. if (acl)
  52. atomic_inc(&acl->a_refcount);
  53. return acl;
  54. }
  55. /*
  56. * Free an ACL handle.
  57. */
  58. static inline void
  59. posix_acl_release(struct posix_acl *acl)
  60. {
  61. if (acl && atomic_dec_and_test(&acl->a_refcount))
  62. kfree_rcu(acl, a_rcu);
  63. }
  64. /* posix_acl.c */
  65. extern void posix_acl_init(struct posix_acl *, int);
  66. extern struct posix_acl *posix_acl_alloc(int, gfp_t);
  67. extern int posix_acl_valid(const struct posix_acl *);
  68. extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
  69. extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
  70. extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
  71. extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
  72. extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
  73. extern struct posix_acl *get_posix_acl(struct inode *, int);
  74. extern int set_posix_acl(struct inode *, int, struct posix_acl *);
  75. #ifdef CONFIG_FS_POSIX_ACL
  76. extern int posix_acl_chmod(struct inode *, umode_t);
  77. extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **,
  78. struct posix_acl **);
  79. extern int posix_acl_update_mode(struct inode *, umode_t *, struct posix_acl **);
  80. extern int simple_set_acl(struct inode *, struct posix_acl *, int);
  81. extern int simple_acl_create(struct inode *, struct inode *);
  82. struct posix_acl **acl_by_type(struct inode *inode, int type);
  83. struct posix_acl *get_cached_acl(struct inode *inode, int type);
  84. struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type);
  85. void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl);
  86. void forget_cached_acl(struct inode *inode, int type);
  87. void forget_all_cached_acls(struct inode *inode);
  88. static inline void cache_no_acl(struct inode *inode)
  89. {
  90. inode->i_acl = NULL;
  91. inode->i_default_acl = NULL;
  92. }
  93. #else
  94. static inline int posix_acl_chmod(struct inode *inode, umode_t mode)
  95. {
  96. return 0;
  97. }
  98. #define simple_set_acl NULL
  99. static inline int simple_acl_create(struct inode *dir, struct inode *inode)
  100. {
  101. return 0;
  102. }
  103. static inline void cache_no_acl(struct inode *inode)
  104. {
  105. }
  106. static inline int posix_acl_create(struct inode *inode, umode_t *mode,
  107. struct posix_acl **default_acl, struct posix_acl **acl)
  108. {
  109. *default_acl = *acl = NULL;
  110. return 0;
  111. }
  112. static inline void forget_all_cached_acls(struct inode *inode)
  113. {
  114. }
  115. #endif /* CONFIG_FS_POSIX_ACL */
  116. struct posix_acl *get_acl(struct inode *inode, int type);
  117. #endif /* __LINUX_POSIX_ACL_H */