Exemplo n.º 1
0
        /// <exception cref="WinrtCifs.Smb.SmbException"></exception>
        public virtual int Read(byte[] b, int off, int len)
        {
            if (len <= 0)
            {
                return(0);
            }
            long start = _fp;

            // ensure file is open
            if (_file.IsOpen() == false)
            {
                _file.Open(_openFlags, 0, SmbFile.AttrNormal, _options);
            }
            int r;
            int n;
            SmbComReadAndXResponse response = new SmbComReadAndXResponse(b, off);

            do
            {
                r = len > _readSize ? _readSize : len;
                _file.Send(new SmbComReadAndX(_file.Fid, _fp, r, null), response);
                if ((n = response.DataLength) <= 0)
                {
                    return((int)((_fp - start) > 0L ? _fp - start : -1));
                }
                _fp          += n;
                len          -= n;
                response.Off += n;
            }while (len > 0 && n == r);
            return((int)(_fp - start));
        }
Exemplo n.º 2
0
 /// <exception cref="WinrtCifs.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;
 }
Exemplo n.º 3
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void EnsureOpen()
 {
     // ensure file is open
     if (_file.IsOpen() == false)
     {
         _file.Open(_openFlags, _access | SmbConstants.FileWriteData, SmbFile.AttrNormal,
                    0);
         if (_append)
         {
             _fp = _file.Length();
         }
     }
 }
Exemplo n.º 4
0
 /// <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);
 }
Exemplo n.º 5
0
 /// <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();
     }
 }
Exemplo n.º 6
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual int ReadDirect(byte[] b, int off, int len)
        {
            if (len <= 0)
            {
                return(0);
            }
            long start = _fp;

            if (_tmp == null)
            {
                throw new IOException("Bad file descriptor");
            }
            // ensure file is open
            File.Open(_openFlags, _access, SmbFile.AttrNormal, 0);
            if (File.Log.Level >= 4)
            {
                File.Log.WriteLine("read: fid=" + File.Fid + ",off=" + off + ",len=" + len);
            }
            SmbComReadAndXResponse response = new SmbComReadAndXResponse(b, off);

            if (File.Type == SmbFile.TypeNamedPipe)
            {
                response.ResponseTimeout = 0;
            }
            int r;
            int n;

            do
            {
                r = len > _readSize ? _readSize : len;
                if (File.Log.Level >= 4)
                {
                    File.Log.WriteLine("read: len=" + len + ",r=" + r + ",fp=" + _fp);
                }
                try
                {
                    SmbComReadAndX request = new SmbComReadAndX(File.Fid, _fp, r, null);
                    if (File.Type == SmbFile.TypeNamedPipe)
                    {
                        request.MinCount = request.MaxCount = request.Remaining = 1024;
                    }
                    File.Send(request, response);
                }
                catch (SmbException se)
                {
                    if (File.Type == SmbFile.TypeNamedPipe && se.GetNtStatus() == NtStatus.NtStatusPipeBroken)
                    {
                        return(-1);
                    }
                    throw SeToIoe(se);
                }
                if ((n = response.DataLength) <= 0)
                {
                    return((int)((_fp - start) > 0L ? _fp - start : -1));
                }
                _fp          += n;
                len          -= n;
                response.Off += n;
            }while (len > 0 && n == r);
            return((int)(_fp - start));
        }