org.apache.hadoop.fs.permission
Class FsPermission

java.lang.Object
  extended by org.apache.hadoop.fs.permission.FsPermission
All Implemented Interfaces:
Writable

@InterfaceAudience.Public
@InterfaceStability.Stable
public class FsPermission
extends Object
implements Writable

A class for file/directory permissions.


Field Summary
static int DEFAULT_UMASK
           
static String DEPRECATED_UMASK_LABEL
          umask property label deprecated key and code in getUMask method to accommodate it may be removed in version .23
static int MAX_PERMISSION_LENGTH
          Maximum acceptable length of a permission string to parse
static String UMASK_LABEL
           
 
Constructor Summary
FsPermission(FsAction u, FsAction g, FsAction o)
          Construct by the given FsAction.
FsPermission(FsAction u, FsAction g, FsAction o, boolean sb)
           
FsPermission(FsPermission other)
          Copy constructor
FsPermission(short mode)
          Construct by the given mode.
FsPermission(String mode)
          Construct by given mode, either in octal or symbolic format.
 
Method Summary
 FsPermission applyUMask(FsPermission umask)
          Apply a umask to this permission and return a new one.
static FsPermission createImmutable(short permission)
          Create an immutable FsPermission object.
 boolean equals(Object obj)
           
 void fromShort(short n)
           
 boolean getAclBit()
          Returns true if there is also an ACL (access control list).
static FsPermission getCachePoolDefault()
          Get the default permission for cache pools.
static FsPermission getDefault()
          Get the default permission for directory and symlink.
static FsPermission getDirDefault()
          Get the default permission for directory.
 boolean getEncryptedBit()
          Returns true if the file is encrypted or directory is in an encryption zone
static FsPermission getFileDefault()
          Get the default permission for file.
 FsAction getGroupAction()
          Return group FsAction.
 FsAction getOtherAction()
          Return other FsAction.
 boolean getStickyBit()
           
static FsPermission getUMask(Configuration conf)
          Get the user file creation mask (umask) UMASK_LABEL config param has umask value that is either symbolic or octal.
 FsAction getUserAction()
          Return user FsAction.
 int hashCode()
           
static FsPermission read(DataInput in)
          Create and initialize a FsPermission from DataInput.
 void readFields(DataInput in)
          Deserialize the fields of this object from in.
static void setUMask(Configuration conf, FsPermission umask)
          Set the user file creation mask (umask)
 short toExtendedShort()
          Encodes the object to a short.
 short toShort()
          Encode the object to a short.
 String toString()
           
static FsPermission valueOf(String unixSymbolicPermission)
          Create a FsPermission from a Unix symbolic permission string
 void write(DataOutput out)
          Serialize the fields of this object to out.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_PERMISSION_LENGTH

public static final int MAX_PERMISSION_LENGTH
Maximum acceptable length of a permission string to parse

See Also:
Constant Field Values

DEPRECATED_UMASK_LABEL

public static final String DEPRECATED_UMASK_LABEL
umask property label deprecated key and code in getUMask method to accommodate it may be removed in version .23

See Also:
Constant Field Values

UMASK_LABEL

public static final String UMASK_LABEL
See Also:
Constant Field Values

DEFAULT_UMASK

public static final int DEFAULT_UMASK
See Also:
Constant Field Values
Constructor Detail

FsPermission

public FsPermission(FsAction u,
                    FsAction g,
                    FsAction o)
Construct by the given FsAction.

Parameters:
u - user action
g - group action
o - other action

FsPermission

public FsPermission(FsAction u,
                    FsAction g,
                    FsAction o,
                    boolean sb)

FsPermission

public FsPermission(short mode)
Construct by the given mode.

Parameters:
mode -
See Also:
toShort()

FsPermission

public FsPermission(FsPermission other)
Copy constructor

Parameters:
other - other permission

FsPermission

public FsPermission(String mode)
Construct by given mode, either in octal or symbolic format.

Parameters:
mode - mode as a string, either in octal or symbolic format
Throws:
IllegalArgumentException - if mode is invalid
Method Detail

createImmutable

public static FsPermission createImmutable(short permission)
Create an immutable FsPermission object.


getUserAction

public FsAction getUserAction()
Return user FsAction.


getGroupAction

public FsAction getGroupAction()
Return group FsAction.


getOtherAction

public FsAction getOtherAction()
Return other FsAction.


fromShort

public void fromShort(short n)

write

public void write(DataOutput out)
           throws IOException
Description copied from interface: Writable
Serialize the fields of this object to out.

Specified by:
write in interface Writable
Parameters:
out - DataOuput to serialize this object into.
Throws:
IOException

readFields

public void readFields(DataInput in)
                throws IOException
Description copied from interface: Writable
Deserialize the fields of this object from in.

For efficiency, implementations should attempt to re-use storage in the existing object where possible.

Specified by:
readFields in interface Writable
Parameters:
in - DataInput to deseriablize this object from.
Throws:
IOException

read

public static FsPermission read(DataInput in)
                         throws IOException
Create and initialize a FsPermission from DataInput.

Throws:
IOException

toShort

public short toShort()
Encode the object to a short.


toExtendedShort

public short toExtendedShort()
Encodes the object to a short. Unlike toShort(), 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

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

applyUMask

public FsPermission applyUMask(FsPermission umask)
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

public static FsPermission getUMask(Configuration conf)
Get the user file creation mask (umask) UMASK_LABEL config 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. DEPRECATED_UMASK_LABEL config param has umask value set to decimal.


getStickyBit

public boolean getStickyBit()

getAclBit

public boolean getAclBit()
Returns true if there is also an ACL (access control list).

Returns:
boolean true if there is also an ACL (access control list).

getEncryptedBit

public boolean getEncryptedBit()
Returns true if the file is encrypted or directory is in an encryption zone


setUMask

public static void setUMask(Configuration conf,
                            FsPermission umask)
Set the user file creation mask (umask)


getDefault

public static FsPermission 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 use getDirDefault() for directory, and use getFileDefault() for file. This method is kept for compatibility.


getDirDefault

public static FsPermission getDirDefault()
Get the default permission for directory.


getFileDefault

public static FsPermission getFileDefault()
Get the default permission for file.


getCachePoolDefault

public static FsPermission getCachePoolDefault()
Get the default permission for cache pools.


valueOf

public static FsPermission valueOf(String unixSymbolicPermission)
Create a FsPermission from a Unix symbolic permission string

Parameters:
unixSymbolicPermission - e.g. "-rw-rw-rw-"


Copyright © 2014 Apache Software Foundation. All Rights Reserved.