private Open ( int flags, int access, int attrs, int options ) : void | ||
flags | int | |
access | int | |
attrs | int | |
options | int | |
return | void |
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="System.UriFormatException"></exception> /// <exception cref="UnknownHostException"></exception> public SmbRandomAccessFile(SmbFile file, string mode) { this._file = file; if (mode.Equals("r")) { _openFlags = SmbFile.OCreat | SmbFile.ORdonly; } else { if (mode.Equals("rw")) { _openFlags = SmbFile.OCreat | SmbFile.ORdwr | SmbFile.OAppend; _writeAndxResp = new SmbComWriteAndXResponse(); _options = WriteOptions; _access = SmbConstants.FileReadData | SmbConstants.FileWriteData; } else { throw new ArgumentException("Invalid mode"); } } file.Open(_openFlags, _access, SmbFile.AttrNormal, _options); _readSize = file.Tree.Session.transport.RcvBufSize - 70; _writeSize = file.Tree.Session.transport.SndBufSize - 70; _fp = 0L; }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="System.UriFormatException"></exception> /// <exception cref="UnknownHostException"></exception> internal SmbFileOutputStream(SmbFile file, bool append, int openFlags) { this._file = file; this._append = append; this._openFlags = openFlags; _access = ((int)(((uint)openFlags) >> 16)) & 0xFFFF; if (append) { try { _fp = file.Length(); } catch (SmbAuthException sae) { throw; } catch (SmbException) { _fp = 0L; } } if (file is SmbNamedPipe && file.Unc.StartsWith("\\pipe\\")) { file.Unc = Runtime.Substring(file.Unc, 5); file.Send(new TransWaitNamedPipe("\\pipe" + file.Unc), new TransWaitNamedPipeResponse ()); } file.Open(openFlags, _access | SmbConstants.FileWriteData, SmbFile.AttrNormal, 0); this._openFlags &= ~(SmbFile.OCreat | SmbFile.OTrunc); _writeSize = file.Tree.Session.transport.SndBufSize - 70; _useNtSmbs = file.Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs ); if (_useNtSmbs) { _reqx = new SmbComWriteAndX(); _rspx = new SmbComWriteAndXResponse(); } else { _req = new SmbComWrite(); _rsp = new SmbComWriteResponse(); } }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> internal virtual void CopyTo0(SmbFile dest, byte[][] b, int bsize, WriterThread w, SmbComReadAndX req, SmbComReadAndXResponse resp) { int i; if (_attrExpiration < Runtime.CurrentTimeMillis()) { _attributes = AttrReadonly | AttrDirectory; _createTime = 0L; _lastModified = 0L; _isExists = false; IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO ); _attributes = info.GetAttributes(); _createTime = info.GetCreateTime(); _lastModified = info.GetLastWriteTime(); _isExists = true; _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod; } if (IsDirectory()) { SmbFile[] files; SmbFile ndest; string path = dest.GetUncPath0(); if (path.Length > 1) { try { dest.Mkdir(); dest.SetPathInformation(_attributes, _createTime, _lastModified); } catch (SmbException se) { if (se.GetNtStatus() != NtStatus.NtStatusAccessDenied && se.GetNtStatus() != NtStatus .NtStatusObjectNameCollision) { throw; } } } files = ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, null); try { for (i = 0; i < files.Length; i++) { ndest = new SmbFile(dest, files[i].GetName(), files[i].Type, files[i]._attributes, files[i]._createTime, files[i]._lastModified, files[i]._size); files[i].CopyTo0(ndest, b, bsize, w, req, resp); } } catch (UnknownHostException uhe) { throw new SmbException(Url.ToString(), uhe); } catch (UriFormatException mue) { throw new SmbException(Url.ToString(), mue); } } else { long off; try { Open(ORdonly, 0, AttrNormal, 0); try { dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData | SmbConstants.FileWriteAttributes, _attributes, 0); } catch (SmbAuthException sae) { if ((dest._attributes & AttrReadonly) != 0) { dest.SetPathInformation(dest._attributes & ~AttrReadonly, 0L, 0L); dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData | SmbConstants.FileWriteAttributes, _attributes, 0); } else { throw; } } i = 0; off = 0L; for (; ; ) { req.SetParam(Fid, off, bsize); resp.SetParam(b[i], 0); Send(req, resp); lock (w) { if (w.E != null) { throw w.E; } while (!w.Ready) { try { Runtime.Wait(w); } catch (Exception ie) { throw new SmbException(dest.Url.ToString(), ie); } } if (w.E != null) { throw w.E; } if (resp.DataLength <= 0) { break; } w.Write(b[i], resp.DataLength, dest, off); } i = i == 1 ? 0 : 1; off += resp.DataLength; } dest.Send(new Trans2SetFileInformation(dest.Fid, _attributes, _createTime, _lastModified ), new Trans2SetFileInformationResponse()); dest.Close(0L); } catch (SmbException se) { if (IgnoreCopyToException == false) { throw new SmbException("Failed to copy file from [" + ToString() + "] to [" + dest + "]", se); } if (Log.Level > 1) { Runtime.PrintStackTrace(se, Log); } } finally { Close(); } } }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="System.UriFormatException"></exception> /// <exception cref="UnknownHostException"></exception> internal SmbFileInputStream(SmbFile file, int openFlags) { this.File = file; this._openFlags = openFlags & 0xFFFF; _access = ((int)(((uint)openFlags) >> 16)) & 0xFFFF; if (file.Type != SmbFile.TypeNamedPipe) { file.Open(openFlags, _access, SmbFile.AttrNormal, 0); this._openFlags &= ~(SmbFile.OCreat | SmbFile.OTrunc); } else { file.Connect0(); } _readSize = Math.Min(file.Tree.Session.transport.RcvBufSize - 70, file.Tree.Session .transport.Server.MaxBufferSize - 70); }