Ejemplo n.º 1
0
        private bool CreateVhd()
        {
            using (var stream = new FileStream(this.FileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 1, FileOptions.WriteThrough)) {
                ReFS.RemoveIntegrityStream(stream.SafeFileHandle);

                var footer = new HardDiskFooter();
                footer.BeginUpdate();
                footer.CreatorApplication = VhdCreatorApplication.JosipMedvedVhdAttach;
                footer.CreatorVersion     = Medo.Reflection.EntryAssembly.Version;
                footer.SetSize((UInt64)this.SizeInBytes);
                footer.OriginalSize = footer.CurrentSize;
                footer.DiskType     = VhdDiskType.FixedHardDisk;

                footer.EndUpdate();

                var    lastReport = DateTime.UtcNow;
                byte[] buffer     = new byte[Settings.WriteBufferSize];
                ulong  remaining  = footer.CurrentSize;
                while (remaining > 0)
                {
                    if (bgw.CancellationPending)
                    {
                        stream.Dispose();
                        File.Delete(this.FileName);
                        return(false);
                    }
                    ulong count = (ulong)buffer.Length;
                    if ((ulong)count > remaining)
                    {
                        count = remaining;
                    }
                    stream.Write(buffer, 0, (int)count);
                    remaining -= count;
                    if (lastReport.AddSeconds(1) < DateTime.UtcNow)
                    {
                        bgw.ReportProgress(100 - (int)(remaining * 100 / footer.CurrentSize));
                        lastReport = DateTime.UtcNow;
                    }
                }
                buffer = footer.Bytes;
                stream.Write(buffer, 0, buffer.Length);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void VhdFooter_Create6()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2012, 1, 5, 16, 23, 53, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)1022999998464);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("5077d87d-9bfa-42a6-9033-c39796a69ae5");
            target.SavedState   = false;
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-98-8B-19-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-EE-2F-8D-30-00-00-00-00-EE-2F-8D-30-00-FF-FF-10-FF-00-00-00-03-FF-FF-E8-44-7D-D8-77-50-FA-9B-A6-42-90-33-C3-97-96-A6-9A-E5-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
Ejemplo n.º 3
0
        public void VhdFooter_Create5()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2011, 2, 2, 10, 53, 33, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftSysinternalsDisk2Vhd;
            target.CreatorVersion     = new Version(1, 0);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)160041885696);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("53cd1f52-a439-4be5-92f2-889948b7bc27");
            target.SavedState   = false;
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-14-DB-F4-2D-64-32-76-00-00-01-00-00-57-69-32-6B-00-00-00-25-43-3D-60-00-00-00-00-25-43-3D-60-00-FF-FF-10-FF-00-00-00-03-FF-FF-EA-E4-52-1F-CD-53-39-A4-E5-4B-92-F2-88-99-48-B7-BC-27-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
Ejemplo n.º 4
0
        public void VhdFooter_Create4()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2011, 12, 14, 17, 14, 30, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.OracleVirtualBox;
            target.CreatorVersion     = new Version(4, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)21474836480);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("8542aad1-1b60-44fe-8805-147ad188b510");
            target.SavedState   = false;
            Assert.AreEqual(41610, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-7B-95-F6-76-62-6F-78-00-04-00-01-57-69-32-6B-00-00-00-05-00-00-00-00-00-00-00-05-00-00-00-00-A2-8A-10-3F-00-00-00-03-FF-FF-EE-A0-D1-AA-42-85-60-1B-FE-44-88-05-14-7A-D1-88-B5-10-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
Ejemplo n.º 5
0
        public void VhdFooter_Create3()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = 0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 12, 6, 14, 14, 48, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)107374182400);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("b7afc1bd-aee1-47ac-b7f2-8bc5269f0af2");
            target.SavedState   = false;
            Assert.AreEqual(51400, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-16-70-DF-D8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-19-00-00-00-00-00-00-00-19-00-00-00-00-C8-C8-10-FF-00-00-00-02-FF-FF-E2-A5-BD-C1-AF-B7-E1-AE-AC-47-B7-F2-8B-C5-26-9F-0A-F2-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
Ejemplo n.º 6
0
        public void VhdFooter_Create2()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 5, 29, 2, 41, 12, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)34359738368);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("a9fda548-8174-4d23-b389-e941d2337ef7");
            target.SavedState   = false;
            Assert.AreEqual(16448, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-74-6E-C8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-08-00-00-00-00-00-00-00-08-00-00-00-00-40-40-10-FF-00-00-00-02-FF-FF-E5-9D-48-A5-FD-A9-74-81-23-4D-B3-89-E9-41-D2-33-7E-F7-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
Ejemplo n.º 7
0
        public void VhdFooter_Create1()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 8, 16, 5, 31, 12, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)3221225472);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("5ea9e33a-1ddd-49a3-bd6d-3cd7905ab670");
            target.SavedState   = false;
            Assert.AreEqual(6241, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-DC-BD-20-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-00-C0-00-00-00-00-00-00-00-C0-00-00-00-18-61-10-3F-00-00-00-02-FF-FF-E5-66-3A-E3-A9-5E-DD-1D-A3-49-BD-6D-3C-D7-90-5A-B6-70-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }