public NtStatus ReadFile(string filename, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info) { FileHandle handle = info.Context as FileHandle; Stream stream; bytesRead = 0; lock (_syncObj) { if (handle == null) { return(DokanResult.FileNotFound); } try { stream = handle.GetOrOpenStream(); if (stream == null) { return(DokanResult.FileNotFound); } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Dokan: Error creating file stream of resource '{0}'", e, handle.Resource); return(DokanResult.Error); } } // Do the reading outside the lock - might block when not enough bytes are available try { stream.Seek(offset, SeekOrigin.Begin); bytesRead = stream.Read(buffer, 0, buffer.Length); return(DokanResult.Success); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("Dokan: Error reading from stream of resource '{0}'", ex, handle.Resource); return(DokanResult.Error); } }
public int ReadFile(string filename, byte[] buffer, ref uint readBytes, long offset, DokanFileInfo info) { FileHandle handle = (FileHandle)info.Context; Stream stream; lock (_syncObj) { if (handle == null) { return(-DokanNet.ERROR_FILE_NOT_FOUND); } try { stream = handle.GetOrOpenStream(); if (stream == null) { return(-DokanNet.ERROR_FILE_NOT_FOUND); } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Dokan: Error creating file stream of resource '{0}'", e, handle.Resource); return(DokanNet.DOKAN_ERROR); } } // Do the reading outside the lock - might block when not enough bytes are available try { stream.Seek(offset, SeekOrigin.Begin); readBytes = (uint)stream.Read(buffer, 0, buffer.Length); return(DokanNet.DOKAN_SUCCESS); } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Dokan: Error reading from stream of resource '{0}'", e, handle.Resource); return(DokanNet.DOKAN_ERROR); } }