com.myJava.file.metadata.posix.jni.wrapper
Class FileAccessWrapper

java.lang.Object
  extended by com.myJava.file.metadata.posix.jni.wrapper.FileAccessWrapper

public class FileAccessWrapper
extends java.lang.Object

This class wraps native POSIX methods for file permissions management.

Author:
Olivier PETRUCCI

Areca Build ID : 7299034069467778562

Field Summary
static int ERR_ACCESS_DENIED
           
static int ERR_ATTRIBUTE_NOT_FOUND
           
static int ERR_BUFFER_TOO_SMALL
           
static int ERR_DISK_QUOTA
           
static int ERR_FILE_NOT_FOUND
           
static int ERR_INTERNAL
           
static int ERR_INVALID_DATA
           
static int ERR_IO
           
static int ERR_LOOP
           
static int ERR_NAME_TOOLONG
           
static int ERR_NOT_A_DIRECTORY
           
static int ERR_NOT_ENOUGH_DISK_SPACE
           
static int ERR_NOT_ENOUGH_MEMORY
           
static int ERR_NOT_IMPLEMENTED
           
static int ERR_PERMISSION_DENIED
           
static int ERR_RO_FILESYSTEM
           
static int ERR_UNEXPECTED
           
static int ERR_UNSUPPORTED
           
static int MASK_PERMISSION
           
static int MASK_TYPE
           
static int TYPE_BLOCKSPECIALFILE
           
static int TYPE_CHARSPECFILE
           
static int TYPE_DIRECTORY
           
static int TYPE_FILE
           
static int TYPE_LINK
           
static int TYPE_PIPE
           
static int TYPE_SOCKET
           
 
Constructor Summary
FileAccessWrapper()
           
 
Method Summary
static void displayModeField(int bf)
          Display the "mode" field's binary form
static GetACLResult getACL(java.lang.String file, boolean defaultACL)
          Return the ACL of the file passed as argument.
static GetAttributeNamesResult getAttributeNames(java.lang.String file, int bufferSize, boolean followSymLinks)
          Return a list of extended attributes names
bufferSize is the memory that will be allocated for the operation.
static GetAttributeValueResult getAttributeValue(java.lang.String file, java.lang.String attributeName, long size, boolean followSymLinks)
          Return the value of the attribute
static GetDataResult getData(java.lang.String file, boolean followSymLinks)
          Returns the result of the "fstat" C method.
static int getGroupId(java.lang.String name)
          Returns the group id matching the name provided as argument.
static java.lang.String getGroupName(int id)
          Returns the group name matching the id provided as argument.
static int getUserId(java.lang.String name)
          Returns the user id matching the name provided as argument.
static java.lang.String getUserName(int id)
          Returns the user name matching the id provided as argument.
static boolean isA(int mode, int tested)
          Returns true if the mode has the "tested" type.
static SetACLResult setACL(java.lang.String file, ACL acl, int size, boolean defaultACL)
          Set the acl for the file passed as argument
If defaultACL == true, then only the default ACL is set
If defaultACL == false, then only the access ACL is set
static SetAttributeValueResult setAttributeValue(java.lang.String file, java.lang.String attributeName, byte[] data, boolean followSymLinks)
          Set the value of the attribute
static SetFileModeResult setFileMode(java.lang.String file, int bitField)
          Sets the file's mode.
static SetFileOwnerResult setFileOwner(java.lang.String file, int owner, int group, boolean followSymLinks)
          Sets the file's owner/group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERR_UNEXPECTED

public static final int ERR_UNEXPECTED
See Also:
Constant Field Values

ERR_NOT_ENOUGH_MEMORY

public static final int ERR_NOT_ENOUGH_MEMORY
See Also:
Constant Field Values

ERR_UNSUPPORTED

public static final int ERR_UNSUPPORTED
See Also:
Constant Field Values

ERR_NAME_TOOLONG

public static final int ERR_NAME_TOOLONG
See Also:
Constant Field Values

ERR_NOT_A_DIRECTORY

public static final int ERR_NOT_A_DIRECTORY
See Also:
Constant Field Values

ERR_FILE_NOT_FOUND

public static final int ERR_FILE_NOT_FOUND
See Also:
Constant Field Values

ERR_BUFFER_TOO_SMALL

public static final int ERR_BUFFER_TOO_SMALL
See Also:
Constant Field Values

ERR_ATTRIBUTE_NOT_FOUND

public static final int ERR_ATTRIBUTE_NOT_FOUND
See Also:
Constant Field Values

ERR_INVALID_DATA

public static final int ERR_INVALID_DATA
See Also:
Constant Field Values

ERR_NOT_ENOUGH_DISK_SPACE

public static final int ERR_NOT_ENOUGH_DISK_SPACE
See Also:
Constant Field Values

ERR_PERMISSION_DENIED

public static final int ERR_PERMISSION_DENIED
See Also:
Constant Field Values

ERR_RO_FILESYSTEM

public static final int ERR_RO_FILESYSTEM
See Also:
Constant Field Values

ERR_DISK_QUOTA

public static final int ERR_DISK_QUOTA
See Also:
Constant Field Values

ERR_INTERNAL

public static final int ERR_INTERNAL
See Also:
Constant Field Values

ERR_IO

public static final int ERR_IO
See Also:
Constant Field Values

ERR_NOT_IMPLEMENTED

public static final int ERR_NOT_IMPLEMENTED
See Also:
Constant Field Values

ERR_LOOP

public static final int ERR_LOOP
See Also:
Constant Field Values

ERR_ACCESS_DENIED

public static final int ERR_ACCESS_DENIED
See Also:
Constant Field Values

MASK_PERMISSION

public static final int MASK_PERMISSION
See Also:
Constant Field Values

MASK_TYPE

public static final int MASK_TYPE
See Also:
Constant Field Values

TYPE_LINK

public static final int TYPE_LINK
See Also:
Constant Field Values

TYPE_SOCKET

public static final int TYPE_SOCKET
See Also:
Constant Field Values

TYPE_CHARSPECFILE

public static final int TYPE_CHARSPECFILE
See Also:
Constant Field Values

TYPE_BLOCKSPECIALFILE

public static final int TYPE_BLOCKSPECIALFILE
See Also:
Constant Field Values

TYPE_FILE

public static final int TYPE_FILE
See Also:
Constant Field Values

TYPE_DIRECTORY

public static final int TYPE_DIRECTORY
See Also:
Constant Field Values

TYPE_PIPE

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

FileAccessWrapper

public FileAccessWrapper()
Method Detail

getData

public static GetDataResult getData(java.lang.String file,
                                    boolean followSymLinks)
Returns the result of the "fstat" C method.
The "st_mode" field is set as follows :
0 OTHER - X
1 OTHER - W
2 OTHER - R
3 GROUP - X
4 GROUP - W
5 GROUP - R
6 USER - X
7 USER - W
8 USER - R
9 STICKY Bit
10 GID Bit
11 UID Bit
12 S_IFIFO
13 S_IFCHR / S_IFLNK / S_IFBLK
14 S_IFDIR / S_IFBLK / S_IFSOCK
15 S_IFREG / S_IFLNK / S_IFSOCK

Where :
S_IFBLK - Is this a block special file? (usually a block-based device of some sort)
S_IFCHR - Is this a character special file? (again, usually a character-based device of some sort)
S_IFDIR - Is this a directory?
S_IFIFO - Is this a pipe or FIFO special file?
S_IFLNK - Is this a symbolic link?
S_IFREG - Is this a regular file?
S_IFSOCK - Is this a socket?


setFileOwner

public static SetFileOwnerResult setFileOwner(java.lang.String file,
                                              int owner,
                                              int group,
                                              boolean followSymLinks)
Sets the file's owner/group.


setFileMode

public static SetFileModeResult setFileMode(java.lang.String file,
                                            int bitField)
Sets the file's mode.
The bit field is filtered by MASK_PERMISSION.

LCHMOD is not implemented on Linux. We will use CHMOD instead and prevent calling this method if the file is a symlink. (permissions not supported on Linux)


getGroupId

public static int getGroupId(java.lang.String name)
Returns the group id matching the name provided as argument.
Returns -1 if no match was found


getGroupName

public static java.lang.String getGroupName(int id)
Returns the group name matching the id provided as argument.
Returns NULL if no match was found


getUserId

public static int getUserId(java.lang.String name)
Returns the user id matching the name provided as argument.
Returns -1 if no match was found


getUserName

public static java.lang.String getUserName(int id)
Returns the user name matching the id provided as argument.
Returns NULL if no match was found


getAttributeNames

public static GetAttributeNamesResult getAttributeNames(java.lang.String file,
                                                        int bufferSize,
                                                        boolean followSymLinks)
Return a list of extended attributes names
bufferSize is the memory that will be allocated for the operation. If it is too small, the method will return an error.


getAttributeValue

public static GetAttributeValueResult getAttributeValue(java.lang.String file,
                                                        java.lang.String attributeName,
                                                        long size,
                                                        boolean followSymLinks)
Return the value of the attribute


setAttributeValue

public static SetAttributeValueResult setAttributeValue(java.lang.String file,
                                                        java.lang.String attributeName,
                                                        byte[] data,
                                                        boolean followSymLinks)
Set the value of the attribute


getACL

public static GetACLResult getACL(java.lang.String file,
                                  boolean defaultACL)
Return the ACL of the file passed as argument.
If defaultACL == true, then only the default ACL is returned
If defaultACL == false, then only the access ACL is returned


setACL

public static SetACLResult setACL(java.lang.String file,
                                  ACL acl,
                                  int size,
                                  boolean defaultACL)
Set the acl for the file passed as argument
If defaultACL == true, then only the default ACL is set
If defaultACL == false, then only the access ACL is set


isA

public static boolean isA(int mode,
                          int tested)
Returns true if the mode has the "tested" type.
"tested" must be chosen among TYPE_LINK, TYPE_SOCKET, TYPE_CHARSPECFILE, TYPE_BLOCKSPECIALFILE, TYPE_FILE, TYPE_DIRECTORY, TYPE_PIPE


displayModeField

public static void displayModeField(int bf)
Display the "mode" field's binary form