Example #1
0
        internal static GuidPartitionTableEntry[] GetInstances(byte[] bytes, uint partitionCount, uint partitionSize)
        {
            // Get PartitionTable
            List <GuidPartitionTableEntry> partitionList = new List <GuidPartitionTableEntry>();

            // Iterate through Partition Entries
            for (int i = GuidPartitionTable.SECTOR_SIZE; i < bytes.Length; i += (int)partitionSize)
            {
                // Instantiate a GuidPartitionTableEntry object
                GuidPartitionTableEntry entry = new GuidPartitionTableEntry(bytes, i);

                // If entry's StartingLBA is 0 then it is not a partition
                if (entry.StartingLBA == 0)
                {
                    break;
                }

                partitionList.Add(entry);
            }

            return(partitionList.ToArray());
        }
Example #2
0
        private GuidPartitionTable(string devicePath)
        {
            byte[] bytes = GuidPartitionTable.GetBytes(devicePath);

            // Test GPT Signature
            Signature = Encoding.ASCII.GetString(bytes, 0x00, 0x08);

            if (Signature == SIGNATURE_STRING)
            {
                Revision   = new Version(BitConverter.ToUInt16(bytes, 0x08), BitConverter.ToUInt16(bytes, 0x0A));
                HeaderSize = BitConverter.ToUInt32(bytes, 0x0C);
                // Get HeaderCRC32 Value
                #region MyLBA

                MyLBA = BitConverter.ToUInt64(bytes, 0x18);
                if (MyLBA != 1)
                {
                    throw new Exception("Invalid MyLBA property value");
                }

                #endregion MyLBA
                AlternateLBA             = BitConverter.ToUInt64(bytes, 0x20);
                FirstUsableLBA           = BitConverter.ToUInt64(bytes, 0x28);
                LastUsableLBA            = BitConverter.ToUInt64(bytes, 0x30);
                DiskGuid                 = new Guid(Helper.GetSubArray(bytes, 0x38, 0x10));
                PartitionEntryLBA        = BitConverter.ToUInt64(bytes, 0x48);
                NumberOfPartitionEntries = BitConverter.ToUInt32(bytes, 0x50);
                SizeOfPartitionEntry     = BitConverter.ToUInt32(bytes, 0x54);
                // Get PartitionEntryArrayCRC32 Value
            }
            else
            {
                throw new Exception("Invalid GPT Signature");
            }

            PartitionTable = GuidPartitionTableEntry.GetInstances(bytes, NumberOfPartitionEntries, SizeOfPartitionEntry);
        }