public void CreateBySizeInGap()
        {
            MemoryStream ms = new MemoryStream();

            using (Disk disk = Disk.InitializeDynamic(ms, Ownership.Dispose, 300 * 1024 * 1024))
            {
                GuidPartitionTable table = GuidPartitionTable.Initialize(disk);

                table.Create(10 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false);

                table.Create((20 * 1024 * 1024) / 512, ((30 * 1024 * 1024) / 512) - 1, GuidPartitionTypes.WindowsBasicData, 0, "Data Partition");

                table.Create((60 * 1024 * 1024) / 512, ((70 * 1024 * 1024) / 512) - 1, GuidPartitionTypes.WindowsBasicData, 0, "Data Partition");

                int idx = table.Create(20 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false);
                Assert.Equal(((30 * 1024 * 1024) / 512), table[idx].FirstSector);
                Assert.Equal(((50 * 1024 * 1024) / 512) - 1, table[idx].LastSector);
            }
        }
        public void Delete()
        {
            MemoryStream ms = new MemoryStream();

            using (Disk disk = Disk.InitializeDynamic(ms, Ownership.Dispose, 10 * 1024 * 1024))
            {
                GuidPartitionTable table = GuidPartitionTable.Initialize(disk);

                Assert.Equal(0, table.Create(1 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false));
                Assert.Equal(1, table.Create(2 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false));
                Assert.Equal(2, table.Create(3 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false));

                long[] sectorCount = new long[] { table[0].SectorCount, table[1].SectorCount, table[2].SectorCount };

                table.Delete(1);

                Assert.Equal(2, table.Count);
                Assert.Equal(sectorCount[2], table[1].SectorCount);
            }
        }
        public void CreateSmallWholeDisk()
        {
            MemoryStream ms = new MemoryStream();

            using (Disk disk = Disk.InitializeDynamic(ms, Ownership.Dispose, 3 * 1024 * 1024))
            {
                GuidPartitionTable table = GuidPartitionTable.Initialize(disk);

                int idx = table.Create(WellKnownPartitionType.WindowsFat, true);

                // Make sure the partition fills from first to last usable.
                Assert.Equal(table.FirstUsableSector, table[idx].FirstSector);
                Assert.Equal(table.LastUsableSector, table[idx].LastSector);
            }
        }
        public void CreateBySize()
        {
            MemoryStream ms = new MemoryStream();

            using (Disk disk = Disk.InitializeDynamic(ms, Ownership.Dispose, 3 * 1024 * 1024))
            {
                GuidPartitionTable table = GuidPartitionTable.Initialize(disk);

                int idx = table.Create(2 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false);

                // Make sure the partition is within 10% of the size requested.
                Assert.True((2 * 1024 * 2) * 0.9 < table[idx].SectorCount);

                Assert.Equal(table.FirstUsableSector, table[idx].FirstSector);
            }
        }
        public void CreateLargeWholeDisk()
        {
            MemoryStream ms = new MemoryStream();

            using (Disk disk = Disk.InitializeDynamic(ms, Ownership.Dispose, 200 * 1024L * 1024 * 1024))
            {
                GuidPartitionTable table = GuidPartitionTable.Initialize(disk);

                int idx = table.Create(WellKnownPartitionType.WindowsFat, true);

                Assert.Equal(2, table.Partitions.Count);
                Assert.Equal(GuidPartitionTypes.MicrosoftReserved, table[0].GuidType);
                Assert.Equal(128 * 1024 * 1024, table[0].SectorCount * 512);

                // Make sure the partition fills from first to last usable, allowing for MicrosoftReserved sector.
                Assert.Equal(table[0].LastSector + 1, table[idx].FirstSector);
                Assert.Equal(table.LastUsableSector, table[idx].LastSector);
            }
        }
        public void DeviceValue_Gpt()
        {
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(80 * 1024 * 1024);
            GuidPartitionTable gpt = GuidPartitionTable.Initialize(ms, Geometry.FromCapacity(ms.Length));

            gpt.Create(WellKnownPartitionType.WindowsNtfs, true);
            VolumeManager volMgr = new VolumeManager(ms);

            RegistryHive hive = RegistryHive.Create(new MemoryStream());
            Store        s    = Store.Initialize(hive.Root);
            BcdObject    obj  = s.CreateInherit(InheritType.AnyObject);

            Element el = obj.AddElement(WellKnownElement.LibraryApplicationDevice, ElementValue.ForDevice(Guid.Empty, volMgr.GetPhysicalVolumes()[0]));

            el = obj.GetElement(WellKnownElement.LibraryApplicationDevice);

            Assert.IsNotNullOrEmpty(el.Value.ToString());
        }