Skip to content

Commit

Permalink
(WIP) IFS extended attributes
Browse files Browse the repository at this point in the history
Co-Authored-By: Zhanghze <[email protected]>
Signed-off-by: Jesse Gorzinski <[email protected]>
  • Loading branch information
ThePrez and Zhanghze committed Apr 28, 2023
1 parent 7fa346c commit 9e6671c
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 23 deletions.
32 changes: 28 additions & 4 deletions src/main/java/com/ibm/as400/access/IFSFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1497,8 +1497,8 @@ public String getOwnerName()
return impl_.getOwnerNameByUserHandle(false); //@AC7
}
else
//return impl_.getOwnerName(); //@AE8D
//@AE8A
//return impl_.getOwnerName();
//TODO
{
String pathUpperCase = path_.toUpperCase(system_.getLocale());
if (pathUpperCase.startsWith("/QSYS.LIB") && !pathUpperCase.endsWith(".FILE")) {
Expand Down Expand Up @@ -1794,7 +1794,7 @@ For further information, refer to the specification of the QDBRTVFD (Retrieve Da
public boolean isSourcePhysicalFile()
throws AS400Exception, AS400SecurityException, IOException
{
String pathUpperCase = path_.toUpperCase(system_.getLocale()); //@AE8A
String pathUpperCase = path_.toUpperCase(system_.getLocale()); //TODO fix path lower case issue
if (!pathUpperCase.endsWith(".FILE") ||
pathUpperCase.indexOf("/QSYS.LIB") == -1 ||
!getSubtype().equals("PF"))
Expand Down Expand Up @@ -3741,6 +3741,30 @@ public String toString()
{
return path_;
}


//TODO get Text 'description' of file/directory
public String getText() throws IOException, AS400SecurityException {
if (impl_ == null)
chooseImpl();
return impl_.getText();
}

public String getCodePage() throws IOException, AS400SecurityException {
if (impl_ == null)
chooseImpl();
return impl_.getCodePage();
}

public Hashtable getEAs() throws IOException, AS400SecurityException {
if (impl_ == null)
chooseImpl();
return impl_.getExtendedAttributes();
}
/*
public void setText(String fileText) {
if (impl_ == null)
impl_.setText(fileText);
}
*/
}

189 changes: 188 additions & 1 deletion src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.Hashtable;
import java.util.Vector;


Expand Down Expand Up @@ -80,6 +81,7 @@ class IFSFileDescriptorImplRemote
String fileOwnerName_ = null;
boolean isDirectory_ = false;
//@AC7 End
Hashtable fileText_ = null; //TODO

// Static initialization code.
static
Expand Down Expand Up @@ -2111,7 +2113,7 @@ else if (ds instanceof IFSReturnCodeRep)
//@AC7A Start
private void retrieveAttributes(ClientAccessDataStream ds, int objectHandle) throws IOException, AS400SecurityException {
fileAsp_ = ((IFSLookupRep) ds).getASP();
//if (isDirectory_) { @AE8D
//if (isDirectory_) { TODO remove
fileOwnerName_ = ((IFSLookupRep) ds).getOwnerName(system_.getCcsid());
fileDataCCSID_ = ((IFSLookupRep) ds).getCCSID(serverDatastreamLevel_);
//}
Expand Down Expand Up @@ -2165,6 +2167,191 @@ else if (ds instanceof IFSReturnCodeRep)
}
}
//@AC7A End

//TODO
/*
public IFSGetEAsRep listEAs() throws IOException, AS400SecurityException {
IFSGetEAsRep reply = null;
int fileHandle = UNINITIALIZED;
boolean usedGlobalHandle = false;
try {
// Open the file, and obtain a file handle.
if (fileHandle_ != UNINITIALIZED)
{
fileHandle = fileHandle_;
usedGlobalHandle = true;
}
else
{
fileHandle = createFileHandle(); //@KKBC
if (fileHandle == UNINITIALIZED)
{
if (Trace.traceOn_) Trace.log(Trace.ERROR, "Unable to create handle to file " + path_ + ". IFSReturnCodeRep return code", errorRC_);
return null;
}
}
IFSGetEAsReq req = new IFSGetEAsReq(fileHandle, serverDatastreamLevel_);
int rc = 0;
ClientAccessDataStream ds = null;
try
{
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
}
catch(ConnectionDroppedException e)
{
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
connectionDropped(e);
}
catch(InterruptedException e)
{
Trace.log(Trace.ERROR, "Interrupted");
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
try {
throwException.initCause(e);
} catch (Throwable t) {}
throw throwException;
}
if (ds instanceof IFSGetEAsRep)
{
reply = (IFSGetEAsRep) ds;
return reply;
}
else if (ds instanceof IFSReturnCodeRep)
{
rc = ((IFSReturnCodeRep) ds).getReturnCode();
if (rc != IFSReturnCodeRep.SUCCESS)
{
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
throw new ExtendedIOException(path_, rc);
}
}
else
{
// Unknown data stream.
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_);
throw new
InternalErrorException(Integer.toHexString(ds.getReqRepID()),
InternalErrorException.DATA_STREAM_UNKNOWN);
}
}
finally {
if(!usedGlobalHandle && fileHandle != UNINITIALIZED)
close(fileHandle);
}
return reply;
}*/

public IFSGetEAsRep getExtendedAttributes(byte[][] eaNamelist, int eaNameLength, int ccsid) throws IOException, AS400SecurityException {
IFSGetEAsRep reply = null;
ClientAccessDataStream ds = null;
connect();
//create user handle
int userHandle = UNINITIALIZED, objectHandle = UNINITIALIZED, nodeObjectHandle = UNINITIALIZED;
try{
userHandle = system_.createUserHandle();
try
{
byte[] path = getConverter().stringToByteArray(path_);
//IFSLookupReq req = new IFSLookupReq(path, preferredServerCCSID_, userHandle, IFSLookupReq.OA2, 0, 0);
//IFSLookupReq req = new IFSLookupReq(path, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0); //@AC7A
IFSLookupReq req = new IFSLookupReq(path, preferredServerCCSID_,userHandle);
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
int rc = 0;
if (ds instanceof IFSLookupRep)
{
objectHandle = ((IFSLookupRep) ds).getHandle();
//Open Node to get object request;
IFSOpenNodeReq nodeReq = new IFSOpenNodeReq(objectHandle, serverDatastreamLevel_);
ds = null;
ds = (ClientAccessDataStream) server_.sendAndReceive(nodeReq);
if (ds instanceof IFSOpenNodeRep) {
nodeObjectHandle = ((IFSOpenNodeRep) ds).getObjectHandle();
IFSGetEAsReq eaReq = new IFSGetEAsReq(nodeObjectHandle, eaNamelist, eaNameLength, ccsid, serverDatastreamLevel_);
ds = (ClientAccessDataStream) server_.sendAndReceive(eaReq);
if (ds instanceof IFSGetEAsRep) {
reply = (IFSGetEAsRep) ds;
} else if (ds instanceof IFSReturnCodeRep)
{
rc = ((IFSReturnCodeRep) ds).getReturnCode();
if (rc != IFSReturnCodeRep.SUCCESS)
{
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
}
throw new ExtendedIOException(path_, rc);
}
else
{
// Unknown data stream.
Trace.log(Trace.ERROR, "Unknown reply data stream",
ds.getReqRepID());
throw new
InternalErrorException(Integer.toHexString(ds.getReqRepID()),
InternalErrorException.DATA_STREAM_UNKNOWN);
}
} else if (ds instanceof IFSReturnCodeRep)
{
rc = ((IFSReturnCodeRep) ds).getReturnCode();
if (rc != IFSReturnCodeRep.SUCCESS)
{
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
}
throw new ExtendedIOException(path_, rc);
}
else
{
// Unknown data stream.
Trace.log(Trace.ERROR, "Unknown reply data stream",
ds.getReqRepID());
throw new
InternalErrorException(Integer.toHexString(ds.getReqRepID()),
InternalErrorException.DATA_STREAM_UNKNOWN);
}
}
else if (ds instanceof IFSReturnCodeRep)
{
rc = ((IFSReturnCodeRep) ds).getReturnCode();
if (rc != IFSReturnCodeRep.SUCCESS)
{
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
}
throw new ExtendedIOException(path_, rc);
}
else
{
// Unknown data stream.
Trace.log(Trace.ERROR, "Unknown reply data stream",
ds.getReqRepID());
throw new
InternalErrorException(Integer.toHexString(ds.getReqRepID()),
InternalErrorException.DATA_STREAM_UNKNOWN);
}

} catch(ConnectionDroppedException e)
{
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
connectionDropped(e);
}
catch(InterruptedException e)
{
Trace.log(Trace.ERROR, "Interrupted");
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
try {
throwException.initCause(e);
} catch (Throwable t) {}
throw throwException;
}
}finally{
if(nodeObjectHandle != UNINITIALIZED)
freeHandle(nodeObjectHandle);
if(objectHandle != UNINITIALIZED)
freeHandle(objectHandle);
}
return reply;
}



}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/ibm/as400/access/IFSFileImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.ibm.as400.access;

import java.io.IOException;
import java.util.Hashtable;

/**
Specifies the methods which the implementation objects for the IFSFile class
Expand Down Expand Up @@ -97,6 +98,9 @@ int renameTo(IFSFileImpl file)
int getCCSID(boolean retrieveAll) throws IOException, AS400SecurityException;
String getOwnerName(boolean retrieveAll) throws IOException, AS400SecurityException;
//@AC7 End
String getText() throws IOException, AS400SecurityException;
String getCodePage() throws IOException, AS400SecurityException;
Hashtable getExtendedAttributes() throws IOException, AS400SecurityException;

}

19 changes: 19 additions & 0 deletions src/main/java/com/ibm/as400/access/IFSFileImplProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;


/**
Expand Down Expand Up @@ -715,4 +716,22 @@ public void setSystem(AS400Impl system)
}
}

@Override
public String getText() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
public String getCodePage() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
public Hashtable getExtendedAttributes() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

}
Loading

0 comments on commit 9e6671c

Please sign in to comment.