- /* For cross_open case, the "mask" is open flags,
- * so convert it to permission mask first.
- * XXX: MDS_OPEN_CROSS must be NOT equal to permission mask MAY_*. */
- if (unlikely(mask & MDS_OPEN_CROSS))
- mask = accmode(env, la, mask & ~MDS_OPEN_CROSS);
-
- check_create = mask & MAY_CREATE;
- check_link = mask & MAY_LINK;
- check_unlink = mask & MAY_UNLINK;
- check_rename_src = mask & MAY_RENAME_SRC;
- check_rename_tar = mask & MAY_RENAME_TAR;
- check_vtx_part = mask & MAY_VTX_PART;
- check_vtx_full = mask & MAY_VTX_FULL;
- check_rgetfacl = mask & MAY_RGETFACL;
-
- mask &= ~(MAY_CREATE | MAY_LINK |
- MAY_UNLINK |
- MAY_RENAME_SRC | MAY_RENAME_TAR |
- MAY_VTX_PART | MAY_VTX_FULL |
- MAY_RGETFACL);
-
- rc = mdd_permission_internal_locked(env, mdd_cobj, NULL, mask,
- MOR_TGT_CHILD);
-
- if (!rc && (check_create || check_link))
- rc = mdd_may_create(env, mdd_cobj, NULL, 1, check_link);
-
- if (!rc && check_unlink)
- rc = mdd_may_unlink(env, mdd_cobj, la);
-
- if (!rc && (check_rename_src || check_rename_tar)) {
- LASSERT(pobj);
- mdd_pobj = md2mdd_obj(pobj);
- rc = mdd_may_delete(env, mdd_pobj, mdd_cobj, la, NULL, 1,
- check_rename_tar);
- }
-
- if (!rc && (check_vtx_part || check_vtx_full)) {
- uc = lu_ucred_assert(env);
- if (likely(!la)) {
- la = &mdd_env_info(env)->mti_la;
- rc = mdd_la_get(env, mdd_cobj, la, BYPASS_CAPA);
- if (rc)
- RETURN(rc);
- }
-
- if (!(la->la_mode & S_ISVTX) || (la->la_uid == uc->uc_fsuid) ||
- (check_vtx_full && (ma->ma_attr.la_valid & LA_UID) &&
- (ma->ma_attr.la_uid == uc->uc_fsuid))) {
- ma->ma_attr_flags |= MDS_VTX_BYPASS;
- } else {
- ma->ma_attr_flags &= ~MDS_VTX_BYPASS;
- if (check_vtx_full)
- rc = -EPERM;
- }
- }
-
- if (unlikely(!rc && check_rgetfacl)) {
- if (likely(!uc))