public WriteOperation WriteTo(long position, byte[] data) { var operation = new FileTableOperation(drive => drive.Write(position, data), position); Synchronizer.EnqueueOperation(operation); return(operation); }
private void writeAvailableContentBlocks() { lock (_entriesTableLock) { var endDriveBytes = BitConverter.GetBytes((int)ServiceBytes.DriveEnd); var blockBytes = (_contentWriter? .AvailableBlocks ?? new DriveBlock[0]) .SelectMany(x => new AvailableDriveBlock(x).GetBytes()) .ToArray(); var blockLengthBytes = BitConverter.GetBytes(blockBytes.Length); var finalizeBytes = blockBytes .Concat(blockLengthBytes) .Concat(endDriveBytes) .ToArray(); var operation = new FileTableOperation(drive => { var writePosition = drive.Length; drive.SetLength(drive.Length + finalizeBytes.Length); drive.Position = writePosition; return(drive.Write(finalizeBytes)); }, -1); _synchronizer.EnqueueOperation(operation); } }
public WriteOperation SetContentSectorLength(long sectorRegionDataStartPosition, long sectorLength) { var position = sectorRegionDataStartPosition + ByteHelper.GetLength <int>() + ByteHelper.GetLength <long>(); var bytes = BitConverter.GetBytes(sectorLength); var operation = new FileTableOperation(drive => { var retv = drive.Write(position, bytes); return(retv); }, position); Synchronizer.EnqueueOperation(operation); return(operation); }
protected override bool HandleAddedAvailableBlock(DriveBlock block) { //min entry length = 42 if (block.Length < 42) { return(false); } var blockLengthBytes = BitConverter.GetBytes(block.Length); var bytesList = new List <byte>(blockLengthBytes) { (byte)ServiceMarks.Proceed }; var operation = new FileTableOperation(drive => drive.Write(block.Position, bytesList.ToArray()), block.Position); Synchronizer.EnqueueOperation(operation); return(true); }
private WriteOperation writeSectorInfo(SectorInfo sectorInfo) { var bytes = sectorInfo.GetBytes(); lock (_sectorsLock) { if (!_sectorInfoWriter.CheckCanWrite(bytes.Length)) { throw new InvalidOperationException("Unable to write sector info"); } if (sectorInfo.Mark != ServiceMarks.EntriesSector) { return(_sectorInfoWriter.Write(bytes)); } var position = sectorInfo.StartPosition + sectorInfo.Length - ByteHelper.GetLength <int>(); var op = new FileTableOperation(drive => drive.Write(position, ServiceBytes.End), position); _synchronizer.EnqueueOperation(op); return(_sectorInfoWriter.Write(bytes)); } }