Exemple #1
0
        public void CreateWholeDisk()
        {
            long capacity         = 3 * 1024 * 1024;
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(capacity);
            Geometry           geom  = Geometry.FromCapacity(capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

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

            // Make sure the partition fills all but the first track on the disk.
            Assert.AreEqual(geom.TotalSectors, table[idx].SectorCount + geom.SectorsPerTrack);

            // Make sure FAT16 was selected for a disk of this size
            Assert.AreEqual(BiosPartitionTypes.Fat16, table[idx].BiosType);

            // Make sure partition starts where expected
            Assert.AreEqual(new ChsAddress(0, 1, 1), ((BiosPartitionInfo)table[idx]).Start);

            // Make sure partition ends at end of disk
            Assert.AreEqual(geom.ToLogicalBlockAddress(geom.LastSector), table[idx].LastSector);
            Assert.AreEqual(geom.LastSector, ((BiosPartitionInfo)table[idx]).End);

            // Make sure the 'active' flag made it through...
            Assert.IsTrue(((BiosPartitionInfo)table[idx]).IsActive);

            // Make sure the partition index is Zero
            Assert.AreEqual(0, ((BiosPartitionInfo)table[idx]).PrimaryIndex);
        }
        /// <summary>
        /// Creates a new partition table on a disk containing a single partition.
        /// </summary>
        /// <param name="disk">The disk to initialize.</param>
        /// <param name="type">The partition type for the single partition</param>
        /// <returns>An object to access the newly created partition table</returns>
        public static BiosPartitionTable Initialize(VirtualDisk disk, WellKnownPartitionType type)
        {
            BiosPartitionTable table = Initialize(disk.Content, disk.BiosGeometry);

            table.Create(type, true);
            return(table);
        }
Exemple #3
0
        public void SetActive()
        {
            long capacity         = 10 * 1024 * 1024;
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(capacity);
            Geometry           geom  = Geometry.FromCapacity(capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

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

            table.SetActivePartition(1);
            table.SetActivePartition(2);
            Assert.IsFalse(((BiosPartitionInfo)table.Partitions[1]).IsActive);
            Assert.IsTrue(((BiosPartitionInfo)table.Partitions[2]).IsActive);
        }
Exemple #4
0
        public void Delete()
        {
            long capacity         = 10 * 1024 * 1024;
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(capacity);
            Geometry           geom  = Geometry.FromCapacity(capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

            Assert.AreEqual(0, table.Create(1 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false));
            Assert.AreEqual(1, table.Create(2 * 1024 * 1024, WellKnownPartitionType.WindowsFat, false));
            Assert.AreEqual(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.AreEqual(2, table.Count);
            Assert.AreEqual(sectorCount[2], table[1].SectorCount);
        }
Exemple #5
0
        public void CreateBySizeInGap()
        {
            SparseMemoryStream ms   = new SparseMemoryStream();
            Geometry           geom = new Geometry(15, 30, 63);

            ms.SetLength(geom.Capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

            Assert.AreEqual(0, table.CreatePrimaryByCylinder(0, 4, 33, false));
            Assert.AreEqual(1, table.CreatePrimaryByCylinder(10, 14, 33, false));
            table.Create(geom.ToLogicalBlockAddress(new ChsAddress(4, 0, 1)) * 512, WellKnownPartitionType.WindowsFat, true);
        }
Exemple #6
0
        public void LargeDisk()
        {
            long capacity         = 300 * 1024L * 1024L * 1024;
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(capacity);
            Geometry           geom  = Geometry.LbaAssistedBiosGeometry(capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

            table.Create(150 * 1024L * 1024L * 1024, WellKnownPartitionType.WindowsNtfs, false);
            table.Create(20 * 1024L * 1024L * 1024, WellKnownPartitionType.WindowsNtfs, false);
            table.Create(20 * 1024L * 1024L * 1024, WellKnownPartitionType.WindowsNtfs, false);

            Assert.AreEqual(3, table.Partitions.Count);
            Assert.Greater(table[0].SectorCount * 512L, 140 * 1024L * 1024L * 1024);
            Assert.Greater(table[1].SectorCount * 512L, 19 * 1024L * 1024L * 1024);
            Assert.Greater(table[2].SectorCount * 512L, 19 * 1024L * 1024L * 1024);

            Assert.Greater(table[0].FirstSector, 0);
            Assert.Greater(table[1].FirstSector, table[0].LastSector);
            Assert.Greater(table[2].FirstSector, table[1].LastSector);
        }
Exemple #7
0
        public void CreateBySize()
        {
            long capacity         = 3 * 1024 * 1024;
            SparseMemoryStream ms = new SparseMemoryStream();

            ms.SetLength(capacity);
            Geometry           geom  = Geometry.FromCapacity(capacity);
            BiosPartitionTable table = BiosPartitionTable.Initialize(ms, geom);

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

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

            Assert.AreEqual(geom.ToLogicalBlockAddress(new ChsAddress(0, 1, 1)), table[idx].FirstSector);
            Assert.AreEqual(geom.HeadsPerCylinder - 1, geom.ToChsAddress((int)table[idx].LastSector).Head);
            Assert.AreEqual(geom.SectorsPerTrack, geom.ToChsAddress((int)table[idx].LastSector).Sector);
        }