Esempio n. 1
0
        public GptHardDrive(HardDisk hdd)
        {
            //check for MBR protective partition
            if (!MbrHardDisk.IsMbr(hdd))
            {
                throw new Exception("Not MBR.");
            }
            if (MbrHardDisk.GetType(hdd, 0) != MbrPartitionType.GptProtective)
            {
                throw new Exception("Not GPT.");
            }

            mHeader = LoadHeader(hdd, SectorSize);
            var backup = LoadHeader(hdd, hdd.Length - SectorSize);

            List <PartitionEntry> parts = new List <PartitionEntry>();

            for (int i = 0; i < mHeader.NumberOfPartitions; i++)
            {
                var partEnt = GetLba <PartitionEntry>(hdd, mHeader.StartingLbaOfPartitionEntries, i * mHeader.SizeOfPartitionEntry);
                if (partEnt.Type == Guid.Empty)
                {
                    continue;
                }
                parts.Add(partEnt);
            }

            mPartition = parts.Where(p => sZfsPartitionTypes.Contains(p.Type)).Single();

            Init(hdd, SectorSize * mPartition.FirstLba, SectorSize * (mPartition.LastLba - mPartition.FirstLba));
        }
Esempio n. 2
0
        public MbrHardDisk(HardDisk hdd, int partition)
        {
            hdd.Get(0, out mHeader);

            //for now, always assume a GPT partition
            if (!MbrHardDisk.IsMbr(hdd))
            {
                throw new Exception("Expected a MBR hdd.");
            }
            if (MbrHardDisk.GetType(hdd, 0) != MbrPartitionType.GptProtective)
            {
                throw new Exception("Expected a GPT protective MBR entry.");
            }

            mPartition = mHeader.GetPartition(partition);
            Init(hdd, (long)mPartition.FirstSectorLba * MbrHeader.SectorSize, (long)mPartition.NumberOfSectors * MbrHeader.SectorSize);
        }