// ushort Signature;

        public MasterBootRecord()
        {
            for (int index = 0; index < NumberOfPartitionEntries; index++)
            {
                PartitionTable[index] = new PartitionTableEntry();
            }
        }
        public MasterBootRecord(byte[] buffer)
        {
            Array.Copy(buffer, Code, 440);
            DiskSignature = LittleEndianConverter.ToUInt32(buffer, 440);
            int offset = 446;

            for (int index = 0; index < NumberOfPartitionEntries; index++)
            {
                PartitionTable[index] = new PartitionTableEntry(buffer, offset);
                offset += 16;
            }
            MBRSignature = LittleEndianConverter.ToUInt16(buffer, 510);
        }
        public MasterBootRecord(byte[] buffer)
        {
            Array.Copy(buffer, Code, 440);
            DiskSignature = LittleEndianConverter.ToUInt32(buffer, 440);
            int offset = 446;

            for (int index = 0; index < NumberOfPartitionEntries; index++)
            {
                PartitionTable[index] = new PartitionTableEntry(buffer, offset);
                offset += 16;
            }
            ushort signature = LittleEndianConverter.ToUInt16(buffer, 510);

            if (signature != MBRSignature)
            {
                throw new InvalidDataException("Invalid MBR signature");
            }
        }
示例#4
0
        public static List <Partition> GetPartitions(Disk disk)
        {
            List <Partition> result = new List <Partition>();

            MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk);

            if (mbr != null)
            {
                if (!mbr.IsGPTBasedDisk)
                {
                    for (int index = 0; index < mbr.PartitionTable.Length; index++)
                    {
                        PartitionTableEntry entry = mbr.PartitionTable[index];
                        if (entry.SectorCountLBA > 0)
                        {
                            long         size      = entry.SectorCountLBA * disk.BytesPerSector;
                            MBRPartition partition = new MBRPartition(entry.PartitionType, disk, entry.FirstSectorLBA, size);
                            result.Add(partition);
                        }
                    }
                }
                else
                {
                    List <GuidPartitionEntry> entries = GuidPartitionTable.ReadEntriesFromDisk(disk);
                    if (entries != null)
                    {
                        foreach (GuidPartitionEntry entry in entries)
                        {
                            GPTPartition partition = new GPTPartition(entry.PartitionGuid, entry.PartitionTypeGuid, entry.PartitionName, disk, (long)entry.FirstLBA, (long)(entry.SizeLBA * (uint)disk.BytesPerSector));
                            result.Add(partition);
                        }
                    }
                }
            }
            return(result);
        }