Ejemplo n.º 1
0
        public void BuildFixed()
        {
            DiskBuilder builder = new DiskBuilder();
            builder.DiskType = DiskCreateType.Vmfs;
            builder.Content = diskContent;

            DiskImageFileSpecification[] fileSpecs = builder.Build("foo");
            Assert.AreEqual(2, fileSpecs.Length);
            Assert.AreEqual("foo.vmdk", fileSpecs[0].Name);

            DiskBuilderFileSystem dbfs = new DiskBuilderFileSystem(fileSpecs);

            using (Disk disk = new Disk(dbfs, "foo.vmdk", FileAccess.Read))
            {
                for (int i = 0; i < 8; i += 1024 * 1024)
                {
                    disk.Content.Position = i;
                    Assert.AreEqual(i, disk.Content.ReadByte());
                }

                disk.Content.Position = 15 * 1024 * 1024;
                Assert.AreEqual(0xFF, disk.Content.ReadByte());
            }
        }
Ejemplo n.º 2
0
        public void ReadWriteSmallVmfs()
        {
            DiscFileSystem fs = new InMemoryFileSystem();
            using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.VmfsSparse))
            {
                byte[] content = new byte[100];
                for (int i = 0; i < content.Length; ++i)
                {
                    content[i] = (byte)i;
                }

                Stream s = disk.Content;
                s.Write(content, 10, 40);
                Assert.AreEqual(40, s.Position);
                s.Write(content, 50, 50);
                Assert.AreEqual(90, s.Position);
                s.Position = 0;

                byte[] buffer = new byte[100];
                s.Read(buffer, 10, 60);
                Assert.AreEqual(60, s.Position);
                for (int i = 0; i < 10; ++i)
                {
                    Assert.AreEqual(0, buffer[i]);
                }
                for (int i = 10; i < 60; ++i)
                {
                    Assert.AreEqual(i, buffer[i]);
                }
            }

            // Check the data persisted
            using (Disk disk = new Disk(fs, "a.vmdk", FileAccess.Read))
            {
                Stream s = disk.Content;

                byte[] buffer = new byte[100];
                s.Read(buffer, 10, 20);
                Assert.AreEqual(20, s.Position);
                for (int i = 0; i < 10; ++i)
                {
                    Assert.AreEqual(0, buffer[i]);
                }
                for (int i = 10; i < 20; ++i)
                {
                    Assert.AreEqual(i, buffer[i]);
                }
            }
        }
Ejemplo n.º 3
0
        public void InitializeDynamic()
        {
            DiscFileSystem fs = new InMemoryFileSystem();
            using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.MonolithicSparse))
            {
                Assert.IsNotNull(disk);
                Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity <= 16 * 1024L * 1024 * 1024);
                Assert.That(disk.Content.Length == 16 * 1024L * 1024 * 1024);
            }

            Assert.Greater(fs.GetFileLength("a.vmdk"), 2 * 1024 * 1024);
            Assert.Less(fs.GetFileLength("a.vmdk"), 4 * 1024 * 1024);

            using (Disk disk = new Disk(fs, "a.vmdk", FileAccess.Read))
            {
                Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity <= 16 * 1024L * 1024 * 1024);
                Assert.That(disk.Content.Length == 16 * 1024L * 1024 * 1024);

                List<DiskImageFile> links = new List<DiskImageFile>(disk.Links);
                List<string> paths = new List<string>(links[0].ExtentPaths);
                Assert.AreEqual(1, paths.Count);
                Assert.AreEqual("a.vmdk", paths[0]);
            }
        }
Ejemplo n.º 4
0
        public void ReadOnlyHosted()
        {
            DiscFileSystem fs = new InMemoryFileSystem();
            using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.MonolithicSparse))
            {
            }

            Disk d2 = new Disk(fs, "a.vmdk", FileAccess.Read);
            Assert.IsFalse(d2.Content.CanWrite);
        }