-static inline void mdd_acl_le_to_cpu(posix_acl_xattr_entry *p)
-{
- p->e_tag = le16_to_cpu(p->e_tag);
- p->e_perm = le16_to_cpu(p->e_perm);
- p->e_id = le32_to_cpu(p->e_id);
-}
-
-static inline void mdd_acl_cpu_to_le(posix_acl_xattr_entry *p)
-{
- p->e_tag = cpu_to_le16(p->e_tag);
- p->e_perm = cpu_to_le16(p->e_perm);
- p->e_id = cpu_to_le32(p->e_id);
-}
-
-/*
- * Check permission based on POSIX ACL.
- */
-static int mdd_posix_acl_permission(struct md_ucred *uc, struct lu_attr *la,
- int want, posix_acl_xattr_entry *entry,
- int count)
-{
- posix_acl_xattr_entry *pa, *pe, *mask_obj;
- int found = 0;
- ENTRY;
-
- if (count <= 0)
- RETURN(-EACCES);
-
- for (pa = &entry[0], pe = &entry[count - 1]; pa <= pe; pa++) {
- mdd_acl_le_to_cpu(pa);
- switch(pa->e_tag) {
- case ACL_USER_OBJ:
- /* (May have been checked already) */
- if (la->la_uid == uc->mu_fsuid)
- goto check_perm;
- break;
- case ACL_USER:
- if (pa->e_id == uc->mu_fsuid)
- goto mask;
- break;
- case ACL_GROUP_OBJ:
- if (mdd_in_group_p(uc, la->la_gid)) {
- found = 1;
- if ((pa->e_perm & want) == want)
- goto mask;
- }
- break;
- case ACL_GROUP:
- if (mdd_in_group_p(uc, pa->e_id)) {
- found = 1;
- if ((pa->e_perm & want) == want)
- goto mask;
- }
- break;
- case ACL_MASK:
- break;
- case ACL_OTHER:
- if (found)
- RETURN(-EACCES);
- else
- goto check_perm;
- default:
- RETURN(-EIO);
- }
- }
- RETURN(-EIO);
-
-mask:
- for (mask_obj = pa + 1; mask_obj <= pe; mask_obj++) {
- mdd_acl_le_to_cpu(mask_obj);
- if (mask_obj->e_tag == ACL_MASK) {
- if ((pa->e_perm & mask_obj->e_perm & want) == want)
- RETURN(0);
-
- RETURN(-EACCES);
- }
- }
-
-check_perm:
- if ((pa->e_perm & want) == want)
- RETURN(0);
-
- RETURN(-EACCES);
-}
-
-/*
- * Get default acl EA only.
- * Hold read_lock for mdd_obj.
- */
-int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj,
- struct md_attr *ma)
-{
- struct lu_buf *buf;
- int rc;
- ENTRY;
-
- if (ma->ma_valid & MA_ACL_DEF)
- RETURN(0);
-
- buf = mdd_buf_get(env, ma->ma_acl, ma->ma_acl_size);
- rc = mdo_xattr_get(env, mdd_obj, buf, XATTR_NAME_ACL_DEFAULT,
- BYPASS_CAPA);
- if (rc > 0) {
- ma->ma_acl_size = rc;
- ma->ma_valid |= MA_ACL_DEF;
- rc = 0;
- } else if ((rc == -EOPNOTSUPP) || (rc == -ENODATA)) {
- rc = 0;
- }
- RETURN(rc);
-}
-
-/*
- * Modify the ACL for the chmod.
- */
-static int mdd_posix_acl_chmod_masq(posix_acl_xattr_entry *entry,
- __u32 mode, int count)
-{
- posix_acl_xattr_entry *group_obj = NULL, *mask_obj = NULL, *pa, *pe;
-
- for (pa = &entry[0], pe = &entry[count - 1]; pa <= pe; pa++) {
- mdd_acl_le_to_cpu(pa);
- switch(pa->e_tag) {
- case ACL_USER_OBJ:
- pa->e_perm = (mode & S_IRWXU) >> 6;
- break;
-
- case ACL_USER:
- case ACL_GROUP:
- break;
-
- case ACL_GROUP_OBJ:
- group_obj = pa;
- break;
-
- case ACL_MASK:
- mask_obj = pa;
- break;
-
- case ACL_OTHER:
- pa->e_perm = (mode & S_IRWXO);
- break;
-
- default:
- return -EIO;
- }
- mdd_acl_cpu_to_le(pa);
- }
-
- if (mask_obj) {
- mask_obj->e_perm = cpu_to_le16((mode & S_IRWXG) >> 3);
- } else {
- if (!group_obj)
- return -EIO;
- group_obj->e_perm = cpu_to_le16((mode & S_IRWXG) >> 3);
- }
-
- return 0;
-}