public void SetFileSize(FileHandle handle, long size) { if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); handle.File.SetSize(size); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, $", size: {size}"); } else { handle.File.SetSize(size); } }
public void CloseFile(FileHandle handle) { if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); handle.File.Dispose(); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, string.Empty); } else { handle.File.Dispose(); } }
public Result ReadFile(FileHandle handle, long offset, Span <byte> destination, ReadOption option) { Result rc = ReadFile(out long bytesRead, handle, offset, destination, option); if (rc.IsFailure()) { return(rc); } if (bytesRead == destination.Length) { return(Result.Success); } return(ResultFs.OutOfRange.Log()); }
public void WriteFile(FileHandle handle, ReadOnlySpan <byte> source, long offset, WriteOption option) { if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); handle.File.Write(source, offset, option); TimeSpan endTime = Time.GetCurrent(); string optionString = (option & WriteOption.Flush) == 0 ? "" : $", write_option: {option}"; OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}"); } else { handle.File.Write(source, offset, option); } }
public int ReadFile(FileHandle handle, Span <byte> destination, long offset, ReadOption option) { int bytesRead; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); bytesRead = handle.File.Read(destination, offset, option); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}"); } else { bytesRead = handle.File.Read(destination, offset, option); } return(bytesRead); }
public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span <byte> destination, ReadOption option) { Result rc; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); rc = handle.File.Read(out bytesRead, offset, destination, option); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}"); } else { rc = handle.File.Read(out bytesRead, offset, destination, option); } return(rc); }
public Result RunOperationWithAccessLog(LocalAccessLogMode logType, FileHandle handle, Func <Result> operation, Func <string> textGenerator, [CallerMemberName] string caller = "") { Result rc; if (IsEnabledAccessLog(logType) && handle.File.Parent.IsAccessLogEnabled) { TimeSpan startTime = Time.GetCurrent(); rc = operation(); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(rc, startTime, endTime, handle, textGenerator(), caller); } else { rc = operation(); } return(rc); }
public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan <byte> source, WriteOption option) { Result rc; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); rc = handle.File.Write(offset, source, option); TimeSpan endTime = Time.GetCurrent(); string optionString = (option & WriteOption.Flush) == 0 ? "" : $", write_option: {option}"; OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}"); } else { rc = handle.File.Write(offset, source, option); } return(rc); }
public static void CopyFile(this FileSystemManager fs, string sourcePath, string destPath, IProgressReport logger = null) { using (FileHandle sourceHandle = fs.OpenFile(sourcePath, OpenMode.Read)) using (FileHandle destHandle = fs.OpenFile(destPath, OpenMode.Write | OpenMode.Append)) { const int maxBufferSize = 0x10000; long fileSize = fs.GetFileSize(sourceHandle); int bufferSize = (int)Math.Min(maxBufferSize, fileSize); logger?.SetTotal(fileSize); byte[] buffer = ArrayPool <byte> .Shared.Rent(bufferSize); try { for (long offset = 0; offset < fileSize; offset += bufferSize) { int toRead = (int)Math.Min(fileSize - offset, bufferSize); Span <byte> buf = buffer.AsSpan(0, toRead); fs.ReadFile(sourceHandle, buf, offset); fs.WriteFile(destHandle, buf, offset); logger?.ReportAdd(toRead); } } finally { ArrayPool <byte> .Shared.Return(buffer); logger?.SetTotal(0); } fs.FlushFile(destHandle); } }
public FileHandle OpenFile(string path, OpenMode mode) { FindFileSystem(path.AsSpan(), out FileSystemAccessor fileSystem, out ReadOnlySpan <char> subPath) .ThrowIfFailure(); FileHandle handle; if (IsEnabledAccessLog() && fileSystem.IsAccessLogEnabled) { TimeSpan startTime = Time.GetCurrent(); FileAccessor file = fileSystem.OpenFile(subPath.ToString(), mode); handle = new FileHandle(file); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, $", path: \"{path}\", open_mode: {mode}"); } else { FileAccessor file = fileSystem.OpenFile(subPath.ToString(), mode); handle = new FileHandle(file); } return(handle); }
internal bool IsEnabledHandleAccessLog(FileHandle handle) { return(handle.File.Parent.IsAccessLogEnabled); }
public OpenMode GetFileOpenMode(FileHandle handle) { return(handle.File.OpenMode); }
public Result SetFileSize(FileHandle handle, long size) { return(RunOperationWithAccessLog(AccessLogTarget.All, handle, () => handle.File.SetSize(size), () => $", size: {size}")); }
public Result GetFileSize(out long fileSize, FileHandle handle) { return(handle.File.GetSize(out fileSize)); }
public Result FlushFile(FileHandle handle) { return(RunOperationWithAccessLog(AccessLogTarget.All, handle, () => handle.File.Flush(), () => string.Empty)); }
public Result ReadFile(FileHandle handle, long offset, Span <byte> destination) { return(ReadFile(handle, offset, destination, ReadOption.None)); }
public void WriteFile(FileHandle handle, ReadOnlySpan <byte> source, long offset) { WriteFile(handle, source, offset, WriteOption.None); }
public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan <byte> source) { return(WriteFile(handle, offset, source, WriteOption.None)); }
public FileHandleStorage(FileSystemClient fsClient, FileHandle handle, bool closeHandleOnDispose) { FsClient = fsClient; Handle = handle; CloseHandle = closeHandleOnDispose; }
public Result ReadFile(FileHandle handle, long offset, Span <byte> destination, in ReadOption option)
public FileHandleStorage(FileHandle handle) : this(handle, false) { }
// ========================== // Operations on file handles // ========================== public int ReadFile(FileHandle handle, Span <byte> destination, long offset) { return(ReadFile(handle, destination, offset, ReadOption.None)); }
internal void OutputAccessLog(Result result, TimeSpan startTime, TimeSpan endTime, FileHandle handle, string message, [CallerMemberName] string caller = "") { OutputAccessLogImpl(result, startTime, endTime, handle.GetId(), message, caller); }
public FileHandleStorage(FileSystemClient fsClient, FileHandle handle) : this(fsClient, handle, false) { }
public FileHandleStorage(FileHandle handle, bool closeHandleOnDispose) { Handle = handle; CloseHandle = closeHandleOnDispose; FsClient = Handle.File.Parent.FsClient; }
public long GetFileSize(FileHandle handle) { return(handle.File.GetSize()); }