/** * @param mode1 first mode of the and operation * @param mode2 second mode of the and operation * @return the AND result of the two Modes */ public static Mode and(Mode mode1, Mode mode2) { Bits u = mode1.mOwnerBits.and(mode2.mOwnerBits); Bits g = mode1.mGroupBits.and(mode2.mGroupBits); Bits o = mode1.mOtherBits.and(mode2.mOtherBits); return new Mode(u, g, o); }
/** * Applies the given umask {@link Mode} to this mode. * * @param mode the mode to update * @param umask the umask to apply * @return the updated object */ private static Mode applyUMask(Mode mode, Mode umask) { mode.setOwnerBits(mode.getOwnerBits().and(umask.getOwnerBits().not())); mode.setGroupBits(mode.getGroupBits().and(umask.getGroupBits().not())); mode.setOtherBits(mode.getOtherBits().and(umask.getOtherBits().not())); return mode; }
/** * Gets the default mode. * * @return the default {@link Mode} */ public static Mode defaults() { return new Mode(Constants.DEFAULT_FILE_SYSTEM_MODE); }
/** * Update the mask to be the union of owning group entry, named user entry and named group entry. * This method must be called when the aforementioned entries are modified. */ public void updateMask() { if (hasExtended()) { AclActions actions = getOwningGroupActions(); mExtendedEntries.updateMask(actions); } }
/** * @return the string representation for the CLI */ public String toCliString() { return toModeBits().toString(); }
private boolean checkMode(AccessControlList acl, String user, List<String> groups, Mode.Bits mode) { for (AclAction action : mode.toAclActionSet()) { if (!acl.checkPermission(user, groups, action)) { return false; } } return true; }
/** * @param mode the digital representation of a {@link Mode} * @return the owner {@link Bits} */ public static Bits extractOwnerBits(short mode) { return Bits.values()[(mode >>> 6) & 7]; }
/** * @return the owning user actions */ public AclActions getOwningUserActions() { return Mode.extractOwnerBits(mMode).toAclActions(); }
/** * @return the owning group actions */ public AclActions getOwningGroupActions() { return Mode.extractGroupBits(mMode).toAclActions(); }
/** * @return other actions */ public AclActions getOtherActions() { return Mode.extractOtherBits(mMode).toAclActions(); }
/** * Copy constructor. * * @param mode another {@link Mode} */ public Mode(Mode mode) { set(mode.mOwnerBits, mode.mGroupBits, mode.mOtherBits); }
/** * @return true if has extended ACL (named users, named groups) */ public boolean hasExtended() { return mExtendedEntries != null && mExtendedEntries.hasExtended(); }
/** * Creates the "full access" mode. * * @return the none {@link Mode} */ public static Mode createFullAccess() { return new Mode(Bits.ALL, Bits.ALL, Bits.ALL); }
/** * @param mode the digital representation of a {@link Mode} * @return the other {@link Bits} */ public static Bits extractOtherBits(short mode) { return Bits.values()[mode & 7]; }
/** * @return the complement of these bits */ public Bits not() { return SVALS[7 - ordinal()]; }