Package org.apache.hadoop.fs.permission
Class FsPermission
java.lang.Object
org.apache.hadoop.fs.permission.FsPermission
- All Implemented Interfaces:
ObjectInputValidation,Serializable,Writable
- Direct Known Subclasses:
FsCreateModes
@Public
@Stable
public class FsPermission
extends Object
implements Writable, Serializable, ObjectInputValidation
A class for file/directory permissions.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intMaximum acceptable length of a permission string to parsestatic final String -
Constructor Summary
ConstructorsConstructorDescriptionFsPermission(int mode) Construct by the given mode.FsPermission(short mode) Construct by the given mode.FsPermission(String mode) Construct by given mode, either in octal or symbolic format.FsPermission(FsAction u, FsAction g, FsAction o) Construct by the givenFsAction.FsPermission(FsAction u, FsAction g, FsAction o, boolean sb) FsPermission(FsPermission other) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionapplyUMask(FsPermission umask) Apply a umask to this permission and return a new one.static FsPermissioncreateImmutable(short permission) Create an immutableFsPermissionobject.booleanvoidfromShort(short n) booleanDeprecated.static FsPermissionGet the default permission for cache pools.static FsPermissionGet the default permission for directory and symlink.static FsPermissionGet the default permission for directory.booleanDeprecated.Get encryption bit from theFileStatusobject.booleanDeprecated.Get ec bit from theFileStatusobject.static FsPermissionGet the default permission for file.Get masked permission if exists.booleanstatic FsPermissiongetUMask(Configuration conf) Get the user file creation mask (umask)UMASK_LABELconfig param has umask value that is either symbolic or octal.Get unmasked permission if exists.inthashCode()static FsPermissionCreate and initialize aFsPermissionfromDataInput.voidreadFields(DataInput in) Deprecated.static voidsetUMask(Configuration conf, FsPermission umask) Set the user file creation mask (umask)shortDeprecated.shorttoOctal()Returns the FsPermission in an octal format.shorttoShort()Encode the object to a short.toString()voidstatic FsPermissionCreate a FsPermission from a Unix symbolic permission stringvoidwrite(DataOutput out) Deprecated.
-
Field Details
-
MAX_PERMISSION_LENGTH
public static final int MAX_PERMISSION_LENGTHMaximum acceptable length of a permission string to parse- See Also:
-
UMASK_LABEL
- See Also:
-
DEFAULT_UMASK
public static final int DEFAULT_UMASK- See Also:
-
-
Constructor Details
-
FsPermission
Construct by the givenFsAction.- Parameters:
u- user actiong- group actiono- other action
-
FsPermission
-
FsPermission
public FsPermission(short mode) Construct by the given mode.- Parameters:
mode- mode.- See Also:
-
FsPermission
public FsPermission(int mode) Construct by the given mode. octal mask is applied.before mask after mask file type sticky bit octal 100644 644 file no decimal 33188 420 octal 101644 1644 file yes decimal 33700 1420 octal 40644 644 directory no decimal 16804 420 octal 41644 1644 directory yes decimal 17316 1420100644 becomes 644 while 644 remains as 644- Parameters:
mode- Mode is supposed to come from the result of native stat() call. It contains complete permission information: rwxrwxrwx, sticky bit, whether it is a directory or a file, etc. Upon applying mask, only permission and sticky bit info will be kept because they are the only parts to be used for now.- See Also:
-
FsPermission
Copy constructor- Parameters:
other- other permission
-
FsPermission
Construct by given mode, either in octal or symbolic format.- Parameters:
mode- mode as a string, either in octal or symbolic format- Throws:
IllegalArgumentException- ifmodeis invalid
-
-
Method Details
-
createImmutable
Create an immutableFsPermissionobject.- Parameters:
permission- permission.- Returns:
- FsPermission.
-
getUserAction
- Returns:
- Return user
FsAction.
-
getGroupAction
- Returns:
- Return group
FsAction.
-
getOtherAction
- Returns:
- Return other
FsAction.
-
fromShort
public void fromShort(short n) -
write
Deprecated.Description copied from interface:WritableSerialize the fields of this object toout.- Specified by:
writein interfaceWritable- Parameters:
out-DataOuputto serialize this object into.- Throws:
IOException- any other problem for write.
-
readFields
Deprecated.Description copied from interface:WritableDeserialize the fields of this object fromin.For efficiency, implementations should attempt to re-use storage in the existing object where possible.
- Specified by:
readFieldsin interfaceWritable- Parameters:
in-DataInputto deseriablize this object from.- Throws:
IOException- any other problem for readFields.
-
getMasked
Get masked permission if exists.- Returns:
- masked.
-
getUnmasked
Get unmasked permission if exists.- Returns:
- unmasked.
-
read
Create and initialize aFsPermissionfromDataInput.- Parameters:
in- data input.- Returns:
- FsPermission.
- Throws:
IOException- raised on errors performing I/O.
-
toShort
public short toShort()Encode the object to a short.- Returns:
- object to a short.
-
toExtendedShort
Deprecated.Encodes the object to a short. UnliketoShort(), this method may return values outside the fixed range 00000 - 01777 if extended features are encoded into this permission, such as the ACL bit.- Returns:
- short extended short representation of this permission
-
toOctal
public short toOctal()Returns the FsPermission in an octal format.- Returns:
- short Unlike
toShort()which provides a binary representation, this method returns the standard octal style permission.
-
equals
-
hashCode
public int hashCode() -
toString
-
applyUMask
Apply a umask to this permission and return a new one. The umask is used by create, mkdir, and other Hadoop filesystem operations. The mode argument for these operations is modified by removing the bits which are set in the umask. Thus, the umask limits the permissions which newly created files and directories get.- Parameters:
umask- The umask to use- Returns:
- The effective permission
-
getUMask
Get the user file creation mask (umask)UMASK_LABELconfig param has umask value that is either symbolic or octal. Symbolic umask is applied relative to file mode creation mask; the permission op characters '+' clears the corresponding bit in the mask, '-' sets bits in the mask. Octal umask, the specified bits are set in the file mode creation mask.- Parameters:
conf- configuration.- Returns:
- FsPermission UMask.
-
getStickyBit
public boolean getStickyBit() -
getAclBit
Deprecated.Get acl bit from theFileStatusobject.Returns true if there is also an ACL (access control list).- Returns:
- boolean true if there is also an ACL (access control list).
-
getEncryptedBit
Deprecated.Get encryption bit from theFileStatusobject.Returns true if the file is encrypted or directory is in an encryption zone.- Returns:
- if the file is encrypted or directory is in an encryption zone true, not false.
-
getErasureCodedBit
Deprecated.Get ec bit from theFileStatusobject.Returns true if the file or directory is erasure coded.- Returns:
- if the file or directory is erasure coded true, not false.
-
setUMask
Set the user file creation mask (umask)- Parameters:
conf- configuration.umask- umask.
-
getDefault
Get the default permission for directory and symlink. In previous versions, this default permission was also used to create files, so files created end up with ugo+x permission. See HADOOP-9155 for detail. Two new methods are added to solve this, please usegetDirDefault()for directory, and usegetFileDefault()for file. This method is kept for compatibility.- Returns:
- Default FsPermission.
-
getDirDefault
Get the default permission for directory.- Returns:
- DirDefault FsPermission.
-
getFileDefault
Get the default permission for file.- Returns:
- FileDefault FsPermission.
-
getCachePoolDefault
Get the default permission for cache pools.- Returns:
- CachePoolDefault FsPermission.
-
valueOf
Create a FsPermission from a Unix symbolic permission string- Parameters:
unixSymbolicPermission- e.g. "-rw-rw-rw-"- Returns:
- FsPermission.
-
validateObject
- Specified by:
validateObjectin interfaceObjectInputValidation- Throws:
InvalidObjectException
-
FileStatusobject.