Esempio n. 1
0
 public void CompactTest()
 {
     using (var vhd = VirtualDisk.Open(fn))
     {
         Assert.That(() => vhd.Compact(), Throws.Nothing);
     }
 }
Esempio n. 2
0
        public void VirtualDiskMirror_Synchronous()
        {
            string vhdxpath = Path.Combine(Environment.CurrentDirectory, "testvhdx.vhdx");

            if (File.Exists(vhdxpath))
            {
                File.Delete(vhdxpath);
            }

            string mirrorpath = Path.Combine(Environment.CurrentDirectory, "testmirror.vhdx");

            if (File.Exists(mirrorpath))
            {
                File.Delete(mirrorpath);
            }

            // Create an 8MB virtual disk with a non-standard block size
            VirtualDiskCreateParameters createparams = new VirtualDiskCreateParameters(vhdxpath, VirtualDiskType.VHDX, 8 * 1024 * 1024);

            createparams.BlockSize = 1024 * 1024;

            using (VirtualDisk vdisk = VirtualDisk.Create(createparams))
            {
                Assert.IsNotNull(vdisk);
                vdisk.Mirror(mirrorpath);
            }

            // Open the mirror and ensure that the virtual size and block size match the source
            using (VirtualDisk mirror = VirtualDisk.Open(mirrorpath))
            {
                Assert.IsNotNull(mirror);
                Assert.AreEqual((ulong)8 * 1024 * 1024, mirror.VirtualSize);
                Assert.AreEqual((ulong)1024 * 1024, mirror.BlockSize);
            }
        }
Esempio n. 3
0
        public async Task CompactAsync1Test()
        {
            using var vhd = VirtualDisk.Open(fn, false);
            var rpt = new Reporter();

            rpt.NewVal += (o, e) => TestContext.WriteLine($"{DateTime.Now:o} NewVal={e}");
            var res = await vhd.CompactAsync(default, rpt);
Esempio n. 4
0
        private VirtualDisk OpenDisk(string targetFilePath)
        {
            var disk = new VirtualDisk(targetFilePath);

            disk.Open();
            disk.Attach(VirtualDiskAttachOptions.None);
            return(disk);
        }
Esempio n. 5
0
 public void GetAllAttachedVirtualDiskPathsTest()
 {
     Assert.That(VirtualDisk.GetAllAttachedVirtualDiskPaths(), Is.Empty);
     using (var vhd = VirtualDisk.Open(fn))
     {
         vhd.Attach();
         Assert.That(VirtualDisk.GetAllAttachedVirtualDiskPaths(), Has.Some.EqualTo(fn));
     }
     Assert.That(VirtualDisk.GetAllAttachedVirtualDiskPaths(), Is.Empty);
 }
Esempio n. 6
0
        public async Task CompactTest1()
        {
            using (var vhd = VirtualDisk.Open(fn))
            {
                var cts     = new CancellationTokenSource();
                var rpt     = new Reporter();
                var lastVal = 0;
                rpt.NewVal += (o, e) => TestContext.WriteLine($"{DateTime.Now:o} NewVal={lastVal = e}");
                await vhd.Compact(cts.Token, rpt);

                Assert.That(lastVal, Is.EqualTo(100));
            }
        }
Esempio n. 7
0
 public void OpenAttachRawTest()
 {
     try
     {
         var param = new OPEN_VIRTUAL_DISK_PARAMETERS(false);
         using (var vhd = VirtualDisk.Open(fn, OPEN_VIRTUAL_DISK_FLAG.OPEN_VIRTUAL_DISK_FLAG_NONE, param, VIRTUAL_DISK_ACCESS_MASK.VIRTUAL_DISK_ACCESS_NONE))
         {
             Assert.That(vhd.Attached, Is.False);
             var flags  = ATTACH_VIRTUAL_DISK_FLAG.ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY;
             var aparam = ATTACH_VIRTUAL_DISK_PARAMETERS.Default;
             var sd     = ConvertStringSecurityDescriptorToSecurityDescriptor("O:BAG:BAD:(A;;GA;;;WD)");
             vhd.Attach(flags, ref aparam, sd);
             Assert.That(vhd.Attached, Is.True);
             vhd.Detach();
             Assert.That(vhd.Attached, Is.False);
         }
     }
     finally
     {
     }
 }
Esempio n. 8
0
 public void OpenAttachTest()
 {
     try
     {
         using (var vhd = VirtualDisk.Open(fn))
         {
             Assert.That(vhd.Attached, Is.False);
             vhd.Attach(true, true, false, GetWorldFullFileSecurity());
             Assert.That(vhd.Attached, Is.True);
             TestContext.WriteLine(vhd.PhysicalPath);
             Assert.That(vhd.PhysicalPath, Is.Not.Null);                     // must be attached
             vhd.Detach();
             Assert.That(vhd.Attached, Is.False);
             vhd.Attach();
             Assert.That(vhd.Attached, Is.True);
             vhd.Close();
             Assert.That(vhd.Attached, Is.False);
         }
     }
     finally
     {
     }
 }
Esempio n. 9
0
 public void OpenAttachRawTest()
 {
     try
     {
         var param = new OPEN_VIRTUAL_DISK_PARAMETERS(false);
         using (var vhd = VirtualDisk.Open(fn, OPEN_VIRTUAL_DISK_FLAG.OPEN_VIRTUAL_DISK_FLAG_NONE, param, VIRTUAL_DISK_ACCESS_MASK.VIRTUAL_DISK_ACCESS_NONE))
         {
             Assert.That(vhd.Attached, Is.False);
             var flags  = ATTACH_VIRTUAL_DISK_FLAG.ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY;
             var aparam = ATTACH_VIRTUAL_DISK_PARAMETERS.Default;
             if (!ConvertStringSecurityDescriptorToSecurityDescriptor("O:BAG:BAD:(A;;GA;;;WD)", SDDL_REVISION.SDDL_REVISION_1, out SafeHGlobalHandle sd, out uint hLen))
             {
                 Win32Error.ThrowLastError();
             }
             vhd.Attach(flags, ref aparam, (IntPtr)sd);
             Assert.That(vhd.Attached, Is.True);
             vhd.Detach();
             Assert.That(vhd.Attached, Is.False);
         }
     }
     finally
     {
     }
 }