public static async Task <IEnumerable <LoadSegBlock> > Read( RigidDiskBlock rigidDiskBlock, FileSystemHeaderBlock fileSystemHeaderBlock, Stream stream) { var loadSegBlocks = new List <LoadSegBlock>(); var segListBlock = fileSystemHeaderBlock.SegListBlocks; do { // calculate seg list block offset var segListBlockOffset = rigidDiskBlock.BlockSize * segListBlock; // seek partition block offset stream.Seek(segListBlockOffset, SeekOrigin.Begin); // read block var block = await BlockHelper.ReadBlock(stream); // parse file system header block var loadSegBlock = await Parse(block); loadSegBlocks.Add(loadSegBlock); // get next partition list block and increase partition number segListBlock = loadSegBlock.NextLoadSegBlock; } while (segListBlock > 0); return(loadSegBlocks); }
public static void ResetFileSystemHeaderBlockPointers(FileSystemHeaderBlock fileSystemHeaderBlock) { fileSystemHeaderBlock.NextFileSysHeaderBlock = 0; fileSystemHeaderBlock.SegListBlocks = 0; foreach (var loadSegBlock in fileSystemHeaderBlock.LoadSegBlocks) { ResetLoadSegBlockPointers(loadSegBlock); } }
public static async Task <byte[]> BuildBlock(FileSystemHeaderBlock fileSystemHeaderBlock) { var blockStream = new MemoryStream( fileSystemHeaderBlock.BlockBytes == null || fileSystemHeaderBlock.BlockBytes.Length == 0 ? new byte[BlockSize.FileSystemHeaderBlock * 4] : fileSystemHeaderBlock.BlockBytes); await blockStream.WriteAsciiString(BlockIdentifiers.FileSystemHeaderBlock); await blockStream.WriteLittleEndianUInt32(BlockSize.FileSystemHeaderBlock); // size // skip checksum, calculated when block is built blockStream.Seek(4, SeekOrigin.Current); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock .HostId); // SCSI Target ID of host, not really used await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock .NextFileSysHeaderBlock); // Block number of the next FileSysHeaderBlock await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.Flags); // Flags // skip reserved blockStream.Seek(4 * 2, SeekOrigin.Current); await blockStream .WriteBytes(fileSystemHeaderBlock .DosType); // # Dostype of the file system, file system description: match this with partition environment's DE_DOSTYPE entry await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock .Version); // filesystem version 0x0027001b == 39.27 await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.PatchFlags); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.Type); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.Task); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.Lock); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.Handler); await blockStream.WriteLittleEndianUInt32(fileSystemHeaderBlock.StackSize); await blockStream.WriteLittleEndianInt32(fileSystemHeaderBlock.Priority); await blockStream.WriteLittleEndianInt32(fileSystemHeaderBlock.Startup); await blockStream.WriteLittleEndianInt32(fileSystemHeaderBlock .SegListBlocks); // first of linked list of LoadSegBlocks await blockStream.WriteLittleEndianInt32(fileSystemHeaderBlock.GlobalVec); // skip reserved blockStream.Seek((23 + 21) * 4, SeekOrigin.Current); // calculate and update checksum var blockBytes = blockStream.ToArray(); fileSystemHeaderBlock.Checksum = await BlockHelper.UpdateChecksum(blockBytes, 8); fileSystemHeaderBlock.BlockBytes = blockBytes; return(blockBytes); }