posix_acl.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/slab.h>
  8. #define ACL_UNDEFINED_ID (-1)
  9. /* a_type field in acl_user_posix_entry_t */
  10. #define ACL_TYPE_ACCESS (0x8000)
  11. #define ACL_TYPE_DEFAULT (0x4000)
  12. /* e_tag entry in struct posix_acl_entry */
  13. #define ACL_USER_OBJ (0x01)
  14. #define ACL_USER (0x02)
  15. #define ACL_GROUP_OBJ (0x04)
  16. #define ACL_GROUP (0x08)
  17. #define ACL_MASK (0x10)
  18. #define ACL_OTHER (0x20)
  19. /* permissions in the e_perm field */
  20. #define ACL_READ (0x04)
  21. #define ACL_WRITE (0x02)
  22. #define ACL_EXECUTE (0x01)
  23. //#define ACL_ADD (0x08)
  24. //#define ACL_DELETE (0x10)
  25. struct posix_acl_entry {
  26. short e_tag;
  27. unsigned short e_perm;
  28. unsigned int e_id;
  29. };
  30. struct posix_acl {
  31. atomic_t a_refcount;
  32. unsigned int a_count;
  33. struct posix_acl_entry a_entries[0];
  34. };
  35. #define FOREACH_ACL_ENTRY(pa, acl, pe) \
  36. for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
  37. /*
  38. * Duplicate an ACL handle.
  39. */
  40. static inline struct posix_acl *
  41. posix_acl_dup(struct posix_acl *acl)
  42. {
  43. if (acl)
  44. atomic_inc(&acl->a_refcount);
  45. return acl;
  46. }
  47. /*
  48. * Free an ACL handle.
  49. */
  50. static inline void
  51. posix_acl_release(struct posix_acl *acl)
  52. {
  53. if (acl && atomic_dec_and_test(&acl->a_refcount))
  54. kfree(acl);
  55. }
  56. /* posix_acl.c */
  57. extern struct posix_acl *posix_acl_alloc(int, gfp_t);
  58. extern struct posix_acl *posix_acl_clone(const struct posix_acl *, gfp_t);
  59. extern int posix_acl_valid(const struct posix_acl *);
  60. extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
  61. extern struct posix_acl *posix_acl_from_mode(mode_t, gfp_t);
  62. extern int posix_acl_equiv_mode(const struct posix_acl *, mode_t *);
  63. extern int posix_acl_create_masq(struct posix_acl *, mode_t *);
  64. extern int posix_acl_chmod_masq(struct posix_acl *, mode_t);
  65. extern struct posix_acl *get_posix_acl(struct inode *, int);
  66. extern int set_posix_acl(struct inode *, int, struct posix_acl *);
  67. #ifdef CONFIG_FS_POSIX_ACL
  68. static inline struct posix_acl *get_cached_acl(struct inode *inode, int type)
  69. {
  70. struct posix_acl **p, *acl;
  71. switch (type) {
  72. case ACL_TYPE_ACCESS:
  73. p = &inode->i_acl;
  74. break;
  75. case ACL_TYPE_DEFAULT:
  76. p = &inode->i_default_acl;
  77. break;
  78. default:
  79. return ERR_PTR(-EINVAL);
  80. }
  81. acl = ACCESS_ONCE(*p);
  82. if (acl) {
  83. spin_lock(&inode->i_lock);
  84. acl = *p;
  85. if (acl != ACL_NOT_CACHED)
  86. acl = posix_acl_dup(acl);
  87. spin_unlock(&inode->i_lock);
  88. }
  89. return acl;
  90. }
  91. static inline void set_cached_acl(struct inode *inode,
  92. int type,
  93. struct posix_acl *acl)
  94. {
  95. struct posix_acl *old = NULL;
  96. spin_lock(&inode->i_lock);
  97. switch (type) {
  98. case ACL_TYPE_ACCESS:
  99. old = inode->i_acl;
  100. inode->i_acl = posix_acl_dup(acl);
  101. break;
  102. case ACL_TYPE_DEFAULT:
  103. old = inode->i_default_acl;
  104. inode->i_default_acl = posix_acl_dup(acl);
  105. break;
  106. }
  107. spin_unlock(&inode->i_lock);
  108. if (old != ACL_NOT_CACHED)
  109. posix_acl_release(old);
  110. }
  111. static inline void forget_cached_acl(struct inode *inode, int type)
  112. {
  113. struct posix_acl *old = NULL;
  114. spin_lock(&inode->i_lock);
  115. switch (type) {
  116. case ACL_TYPE_ACCESS:
  117. old = inode->i_acl;
  118. inode->i_acl = ACL_NOT_CACHED;
  119. break;
  120. case ACL_TYPE_DEFAULT:
  121. old = inode->i_default_acl;
  122. inode->i_default_acl = ACL_NOT_CACHED;
  123. break;
  124. }
  125. spin_unlock(&inode->i_lock);
  126. if (old != ACL_NOT_CACHED)
  127. posix_acl_release(old);
  128. }
  129. #endif
  130. #endif /* __LINUX_POSIX_ACL_H */