/** * @throws SmbException * */ SmbFileInputStream ( SmbFile file, SmbTreeHandleImpl th, SmbFileHandleImpl fh ) throws SmbException { this.file = file; this.handle = fh; this.unsharedFile = false; this.smb2 = th.isSMB2(); try { init(th); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
/** * @throws SmbException * */ SmbFileInputStream ( SmbFile file, SmbTreeHandleImpl th, SmbFileHandleImpl fh ) throws SmbException { this.file = file; this.handle = fh; this.unsharedFile = false; this.smb2 = th.isSMB2(); try { init(th); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setLastModified ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, 0L, time, 0L); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void delete () throws SmbException { try { delete(this.fileLocator.getUNCPath()); } catch ( CIFSException e ) { throw SmbException.wrap(e); } close(); }
@Override public void setLastAccess ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, 0L, 0L, time); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setLastModified ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, 0L, time, 0L); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setCreateTime ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, time, 0L, 0L); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setLastAccess ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, 0L, 0L, time); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setCreateTime ( long time ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(0, time, 0L, 0L); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void delete () throws SmbException { try { delete(this.fileLocator.getUNCPath()); } catch ( CIFSException e ) { throw SmbException.wrap(e); } close(); }
@Override public int getType () throws SmbException { try { int t = this.fileLocator.getType(); if ( t == TYPE_SHARE ) { try ( SmbTreeHandle th = ensureTreeConnected() ) { this.fileLocator.updateType(th.getTreeType()); } } return t; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public int getType () throws SmbException { try { int t = this.fileLocator.getType(); if ( t == TYPE_SHARE ) { try ( SmbTreeHandle th = ensureTreeConnected() ) { this.fileLocator.updateType(th.getTreeType()); } } return t; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
/** * Establish a tree connection with the configured logon share * * @throws SmbException */ @Override public void treeConnectLogon () throws SmbException { String logonShare = getContext().getConfig().getLogonShare(); if ( logonShare == null || logonShare.isEmpty() ) { throw new SmbException("Logon share is not defined"); } try ( SmbTreeImpl t = getSmbTree(logonShare, null) ) { t.treeConnect(null, null); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
SmbFileInputStream ( SmbFile file, int openFlags, int access, int sharing, boolean unshared ) throws SmbException { this.file = file; this.unsharedFile = unshared; this.openFlags = openFlags; this.access = access; try ( SmbTreeHandleInternal th = file.ensureTreeConnected() ) { this.smb2 = th.isSMB2(); if ( file.getType() != SmbConstants.TYPE_NAMED_PIPE ) { try ( SmbFileHandle h = ensureOpen() ) {} this.openFlags &= ~ ( SmbConstants.O_CREAT | SmbConstants.O_TRUNC ); } init(th); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public void setAttributes ( int attrs ) throws SmbException { if ( this.fileLocator.isRootOrShare() ) { throw new SmbException("Invalid operation for workgroups, servers, or shares"); } try { setPathInformation(attrs & ATTR_SET_MASK, 0L, 0L, 0L); } catch ( SmbException e ) { if ( e.getNtStatus() != 0xC00000BB ) { throw e; } throw new SmbUnsupportedOperationException("Attribute not supported by server"); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
SmbFileInputStream ( SmbFile file, int openFlags, int access, int sharing, boolean unshared ) throws SmbException { this.file = file; this.unsharedFile = unshared; this.openFlags = openFlags; this.access = access; try ( SmbTreeHandleInternal th = file.ensureTreeConnected() ) { this.smb2 = th.isSMB2(); if ( file.getType() != SmbConstants.TYPE_NAMED_PIPE ) { try ( SmbFileHandle h = ensureOpen() ) {} this.openFlags &= ~ ( SmbConstants.O_CREAT | SmbConstants.O_TRUNC ); } init(th); } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public long getDiskFreeSpace () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE || t == TYPE_FILESYSTEM ) { AllocInfo allocInfo = fetchAllocationInfo(th); this.size = allocInfo.getCapacity(); this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return allocInfo.getFree(); } return 0L; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public long getDiskFreeSpace () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE || t == TYPE_FILESYSTEM ) { AllocInfo allocInfo = fetchAllocationInfo(th); this.size = allocInfo.getCapacity(); this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return allocInfo.getFree(); } return 0L; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public long fileIndex () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { if ( th.isSMB2() ) { Smb2QueryInfoRequest req = new Smb2QueryInfoRequest(th.getConfig()); req.setFileInfoClass(FileInformation.FILE_INTERNAL_INFO); Smb2QueryInfoResponse resp = withOpen(th, req); FileInternalInfo info = resp.getInfo(FileInternalInfo.class); return info.getIndexNumber(); } } catch ( CIFSException e ) { throw SmbException.wrap(e); } return 0; }
@Override public long fileIndex () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { if ( th.isSMB2() ) { Smb2QueryInfoRequest req = new Smb2QueryInfoRequest(th.getConfig()); req.setFileInfoClass(FileInformation.FILE_INTERNAL_INFO); Smb2QueryInfoResponse resp = withOpen(th, req); FileInternalInfo info = resp.getInfo(FileInternalInfo.class); return info.getIndexNumber(); } } catch ( CIFSException e ) { throw SmbException.wrap(e); } return 0; }