posix_acl.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifndef CONFIG_UIDGID_STRICT_TYPE_CHECKS
  34. unsigned int e_id;
  35. #endif
  36. };
  37. };
  38. struct posix_acl {
  39. union {
  40. atomic_t a_refcount;
  41. struct rcu_head a_rcu;
  42. };
  43. unsigned int a_count;
  44. struct posix_acl_entry a_entries[0];
  45. };
  46. #define FOREACH_ACL_ENTRY(pa, acl, pe) \
  47. for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
  48. /*
  49. * Duplicate an ACL handle.
  50. */
  51. static inline struct posix_acl *
  52. posix_acl_dup(struct posix_acl *acl)
  53. {
  54. if (acl)
  55. atomic_inc(&acl->a_refcount);
  56. return acl;
  57. }
  58. /*
  59. * Free an ACL handle.
  60. */
  61. static inline void
  62. posix_acl_release(struct posix_acl *acl)
  63. {
  64. if (acl && atomic_dec_and_test(&acl->a_refcount))
  65. kfree_rcu(acl, a_rcu);
  66. }
  67. /* posix_acl.c */
  68. extern void posix_acl_init(struct posix_acl *, int);
  69. extern struct posix_acl *posix_acl_alloc(int, gfp_t);
  70. extern int posix_acl_valid(const struct posix_acl *);
  71. extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
  72. extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
  73. extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
  74. extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
  75. extern int posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
  76. extern struct posix_acl *get_posix_acl(struct inode *, int);
  77. extern int set_posix_acl(struct inode *, int, struct posix_acl *);
  78. struct posix_acl **acl_by_type(struct inode *inode, int type);
  79. struct posix_acl *get_cached_acl(struct inode *inode, int type);
  80. struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type);
  81. void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl);
  82. void forget_cached_acl(struct inode *inode, int type);
  83. void forget_all_cached_acls(struct inode *inode);
  84. static inline void cache_no_acl(struct inode *inode)
  85. {
  86. #ifdef CONFIG_FS_POSIX_ACL
  87. inode->i_acl = NULL;
  88. inode->i_default_acl = NULL;
  89. #endif
  90. }
  91. #endif /* __LINUX_POSIX_ACL_H */