/// <summary> /// Writes data to this cluster chain, possibly growing the chain so it /// can store the additional data. When this method returns without throwing /// an exception, the buffer's <see cref="MemoryStream.Position"/> will /// equal it's <see cref="MemoryStream.Length"/>, and the length will not /// have changed. This is not guaranteed if writing fails. /// </summary> /// <param name="offset">the offset where to write the first byte from the buffer</param> /// <param name="srcBuf">the buffer to write to this <see cref="ClusterChain"/></param> /// <exception cref="IOException">IOException on write error</exception> public void WriteData(long offset, MemoryStream srcBuf) { var len = (int)(srcBuf.Length - srcBuf.Position); if (len == 0) { return; } var minSize = offset + len; if (GetLengthOnDisk() < minSize) { SetSize(minSize); } var chain = fat.GetChain(GetStartCluster()); var chainIdx = (int)(offset / clusterSize); if (offset % clusterSize != 0) { var clusOfs = (int)(offset % clusterSize); var size = Math.Min(len, (int)(clusterSize - (offset % clusterSize))); srcBuf.SetLength(srcBuf.Position + size); device.Write(GetDevOffset(chain[chainIdx], clusOfs), srcBuf); offset += size; len -= size; chainIdx++; } while (len > 0) { var size = Math.Min(clusterSize, len); srcBuf.SetLength(srcBuf.Position + size); device.Write(GetDevOffset(chain[chainIdx], 0), srcBuf); len -= size; chainIdx++; } }
/// <summary> /// Writes a copy of this boot sector to the specified device, if a copy /// is requested. /// </summary> /// <param name="device">the device to write the boot sector copy to</param> /// <exception cref="System.IO.IOException">IOException on write error</exception> /// <seealso cref="GetBootSectorCopySector"/> public void WriteCopy(IBlockDevice device) { if (GetBootSectorCopySector() > 0) { long offset = GetBootSectorCopySector() * SIZE; Buffer.Position = 0; device.Write(offset, Buffer); } }
/// <summary> /// Write the contents of this FAT to the given device at the given offset. /// </summary> /// <param name="offset">the device offset where to write the FAT copy</param> /// <exception cref="IOException">IOException on write error</exception> public void WriteCopy(long offset) { var data = new byte[sectorCount * sectorSize]; for (var index = 0; index < entries.Length; index++) { fatType.WriteEntry(data, index, entries[index]); } device.Write(offset, new MemoryStream(data)); }
public void Write() { if (!IsDirty()) { return; } Buffer.Position = 0; device.Write(offset, Buffer); dirty = false; }
protected override void Write(MemoryStream data) { device.Write(deviceOffset, data); }