public void Write(int index, byte[] data) { if (mSector.Type != SECTOR.SectorType.FILE_NODE) { throw new Exception("Cannot write data to node type " + mSector.Type.ToString()); } //load blocks LoadBlocks(); // extend file with more sectors if needed FILE_NODE fileSector = mSector as FILE_NODE; int fileFileLength = Math.Max(fileSector.FileSize, index + data.Length); VirtualBlock.ExtendBlocks(mDrive, mBlocks, fileSector.FileSize, fileFileLength); //write data to the blocks VirtualBlock.WriteBlockData(mDrive, mBlocks, index, data); //wrte out data CommitBlocks(); // write out new file size to disk if (fileFileLength != fileSector.FileSize) { fileSector.FileSize = fileFileLength; Drive.Disk.WriteSector(mNodeSector, fileSector.RawBytes); } }
public byte[] Read(int index, int length) { if (mSector.Type != SECTOR.SectorType.FILE_NODE) { throw new Exception("Cannot read data to node type " + mSector.Type.ToString()); } LoadBlocks(); return(VirtualBlock.ReadBlockData(mDrive, mBlocks, index, length)); }