Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003   File: linux/posix_acl.h
0004 
0005   (C) 2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
0006 */
0007 
0008 
0009 #ifndef __LINUX_POSIX_ACL_H
0010 #define __LINUX_POSIX_ACL_H
0011 
0012 #include <linux/bug.h>
0013 #include <linux/slab.h>
0014 #include <linux/rcupdate.h>
0015 #include <linux/refcount.h>
0016 #include <uapi/linux/posix_acl.h>
0017 
0018 struct user_namespace;
0019 
0020 struct posix_acl_entry {
0021     short           e_tag;
0022     unsigned short      e_perm;
0023     union {
0024         kuid_t      e_uid;
0025         kgid_t      e_gid;
0026     };
0027 };
0028 
0029 struct posix_acl {
0030     refcount_t      a_refcount;
0031     struct rcu_head     a_rcu;
0032     unsigned int        a_count;
0033     struct posix_acl_entry  a_entries[];
0034 };
0035 
0036 #define FOREACH_ACL_ENTRY(pa, acl, pe) \
0037     for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
0038 
0039 
0040 /*
0041  * Duplicate an ACL handle.
0042  */
0043 static inline struct posix_acl *
0044 posix_acl_dup(struct posix_acl *acl)
0045 {
0046     if (acl)
0047         refcount_inc(&acl->a_refcount);
0048     return acl;
0049 }
0050 
0051 /*
0052  * Free an ACL handle.
0053  */
0054 static inline void
0055 posix_acl_release(struct posix_acl *acl)
0056 {
0057     if (acl && refcount_dec_and_test(&acl->a_refcount))
0058         kfree_rcu(acl, a_rcu);
0059 }
0060 
0061 
0062 /* posix_acl.c */
0063 
0064 extern void posix_acl_init(struct posix_acl *, int);
0065 extern struct posix_acl *posix_acl_alloc(int, gfp_t);
0066 extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
0067 extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
0068 extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
0069 extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
0070 
0071 extern struct posix_acl *get_posix_acl(struct inode *, int);
0072 extern int set_posix_acl(struct user_namespace *, struct inode *, int,
0073              struct posix_acl *);
0074 
0075 struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type);
0076 struct posix_acl *posix_acl_clone(const struct posix_acl *acl, gfp_t flags);
0077 
0078 #ifdef CONFIG_FS_POSIX_ACL
0079 int posix_acl_chmod(struct user_namespace *, struct inode *, umode_t);
0080 extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **,
0081         struct posix_acl **);
0082 int posix_acl_update_mode(struct user_namespace *, struct inode *, umode_t *,
0083               struct posix_acl **);
0084 
0085 extern int simple_set_acl(struct user_namespace *, struct inode *,
0086               struct posix_acl *, int);
0087 extern int simple_acl_create(struct inode *, struct inode *);
0088 
0089 struct posix_acl *get_cached_acl(struct inode *inode, int type);
0090 void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl);
0091 void forget_cached_acl(struct inode *inode, int type);
0092 void forget_all_cached_acls(struct inode *inode);
0093 int posix_acl_valid(struct user_namespace *, const struct posix_acl *);
0094 int posix_acl_permission(struct user_namespace *, struct inode *,
0095              const struct posix_acl *, int);
0096 
0097 static inline void cache_no_acl(struct inode *inode)
0098 {
0099     inode->i_acl = NULL;
0100     inode->i_default_acl = NULL;
0101 }
0102 #else
0103 static inline int posix_acl_chmod(struct user_namespace *mnt_userns,
0104                   struct inode *inode, umode_t mode)
0105 {
0106     return 0;
0107 }
0108 
0109 #define simple_set_acl      NULL
0110 
0111 static inline int simple_acl_create(struct inode *dir, struct inode *inode)
0112 {
0113     return 0;
0114 }
0115 static inline void cache_no_acl(struct inode *inode)
0116 {
0117 }
0118 
0119 static inline int posix_acl_create(struct inode *inode, umode_t *mode,
0120         struct posix_acl **default_acl, struct posix_acl **acl)
0121 {
0122     *default_acl = *acl = NULL;
0123     return 0;
0124 }
0125 
0126 static inline void forget_all_cached_acls(struct inode *inode)
0127 {
0128 }
0129 #endif /* CONFIG_FS_POSIX_ACL */
0130 
0131 struct posix_acl *get_acl(struct inode *inode, int type);
0132 
0133 #endif  /* __LINUX_POSIX_ACL_H */