/// <summary> /// Initializes a new instance of the <see cref="PartitionDevice"/> class. /// </summary> /// <param name="diskDevice">The disk device.</param> /// <param name="partition">The partition.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> public PartitionDevice(IDiskDevice diskDevice, GenericPartition partition, bool readOnly) { this.diskDevice = diskDevice; startBlock = partition.StartLBA; blockCount = partition.TotalBlocks; this.readOnly = readOnly; base.Parent = diskDevice as Device; base.Name = base.Parent.Name + "/Partition" + (partition.Index + 1).ToString(); // need to give it a unique name base.DeviceStatus = DeviceStatus.Online; }
/// <summary> /// Reads the master boot block. /// </summary> /// <returns></returns> public bool Read() { valid = false; if (diskDevice.BlockSize != 512) return false; // only going to work with 512 sector sizes if (diskDevice.TotalBlocks < 3) return false; BinaryFormat masterboot = new BinaryFormat(diskDevice.ReadBlock(0, 1)); if (masterboot.GetUShort(MBR.MBRSignature) != MBRConstant.MBRSignature) return false; valid = true; diskSignature = masterboot.GetUInt(MBR.DiskSignature); for (uint index = 0; index < MaxMBRPartitions; index++) { uint offset = MBR.FirstPartition + (index * MBRConstant.PartitionSize); GenericPartition partition = new GenericPartition(index); partition.Bootable = masterboot.GetByte(offset + PartitionRecord.Status) == MBRConstant.Bootable; partition.PartitionType = masterboot.GetByte(offset + PartitionRecord.PartitionType); partition.StartLBA = masterboot.GetUInt(offset + PartitionRecord.LBA); partition.TotalBlocks = masterboot.GetUInt(offset + PartitionRecord.Sectors); Partitions[index] = partition; } //TODO: Extended Partitions code = new byte[MBRConstant.CodeAreaSize]; for (uint index = 0; index < MBRConstant.CodeAreaSize; index++) code[index] = masterboot.GetByte(index); return valid; }
/// <summary> /// Initializes a new instance of the <see cref="MasterBootBlock"/> class. /// </summary> /// <param name="diskDevice">The disk device.</param> public MasterBootBlock(IDiskDevice diskDevice) { this.diskDevice = diskDevice; Partitions = new GenericPartition[MaxMBRPartitions]; for (uint i = 0; i < MaxMBRPartitions; i++) Partitions[i] = new GenericPartition(i); Read(); }