示例#1
0
 public void Create()
 {
     Geometry g = new Geometry(100, 16, 63);
     Assert.AreEqual(100, g.Cylinders);
     Assert.AreEqual(16, g.HeadsPerCylinder);
     Assert.AreEqual(63, g.SectorsPerTrack);
 }
示例#2
0
        public void FromCapacity()
        {
            // Check the capacity calculated is no greater than requested, and off by no more than 10%
            const long ThreeTwentyMB = 1024 * 1024 * 320;
            Geometry g = Geometry.FromCapacity(ThreeTwentyMB);
            Assert.That(g.Capacity <= ThreeTwentyMB && g.Capacity > ThreeTwentyMB * 0.9);

            // Check exact sizes are maintained - do one pass to allow for finding a geometry that matches
            // the algorithm - then expect identical results each time.
            Geometry startGeometry = new Geometry(333,22,11);
            Geometry trip1 = Geometry.FromCapacity(startGeometry.Capacity);
            Assert.AreEqual(trip1, Geometry.FromCapacity(trip1.Capacity));
        }
示例#3
0
        public void LBARoundTrip()
        {
            Geometry g = new Geometry(100, 16, 63);

            const int TestCylinder = 54;
            const int TestHead = 15;
            const int TestSector = 63;

            long lba = g.ToLogicalBlockAddress(TestCylinder, TestHead, TestSector);
            ChsAddress chs = g.ToChsAddress(lba);

            Assert.AreEqual(TestCylinder, chs.Cylinder);
            Assert.AreEqual(TestHead, chs.Head);
            Assert.AreEqual(TestSector, chs.Sector);
        }
示例#4
0
        private void _copydisks(EnvelopeType ovfEnv, string label, string targetPath)
        {
            m_iscsi = new iSCSI
            {
                UpdateHandler = iscsi_UpdateHandler,
                Cancel        = Cancel                 //in case it has already been cancelled
            };
            m_iscsi.ConfigureTvmNetwork(m_networkUuid, m_isTvmIpStatic, m_tvmIpAddress, m_tvmSubnetMask, m_tvmGateway);

            try
            {
                foreach (XenRef <VDI> vdiuuid in _vdiRefs)
                {
                    string uuid = "";
                    string destinationFilename = "";

                    try
                    {
                        uuid = VDI.get_uuid(XenSession, vdiuuid);
                        destinationFilename = Path.Combine(targetPath, string.Format(@"{0}.vhd", uuid));

                        if (File.Exists(destinationFilename))
                        {
                            destinationFilename = Path.Combine(targetPath, string.Format(@"{0}_{1}.vhd", uuid, Thread.CurrentThread.ManagedThreadId));
                            OVF.UpdateFilename(ovfEnv, string.Format(@"{0}.vhd", uuid), string.Format(@"{0}_{1}.vhd", uuid, Thread.CurrentThread.ManagedThreadId));
                            log.InfoFormat("{0}: VHD Name collision, renamed {1}.vhd to {1}_{2}.vhd",
                                           label, uuid, Thread.CurrentThread.ManagedThreadId);
                        }

                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Export", string.Format(Messages.FILES_TRANSPORT_SETUP, uuid + ".vhd")));

                        using (Stream source = m_iscsi.Connect(XenSession, uuid, true))
                        {
                            OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Export", ""));
                            using (FileStream fs = new FileStream(destinationFilename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
                            {
                                // Create a geometry to give to DiscUtils.Vhd.Disk.InitializeDynamic() just so it doesn't override capacity
                                // when initializing the .
                                DiscUtils.Geometry geometry = DiscUtils.Geometry.FromCapacity(source.Length);

                                using (DiscUtils.Vhd.Disk destination = DiscUtils.Vhd.Disk.InitializeDynamic(fs, Ownership.None, source.Length, geometry))
                                {
                                    m_iscsi.Copy(source, destination.Content, Path.GetFileName(destinationFilename), ShouldVerifyDisks);
                                }
                            }
                        }

                        if (ShouldVerifyDisks)
                        {
                            using (var target = new DiscUtils.Vhd.Disk(destinationFilename, FileAccess.Read))
                            {
                                m_iscsi.Verify(target.Content, destinationFilename);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is OperationCanceledException)
                        {
                            throw;
                        }
                        var msg = string.Format(Messages.ISCSI_COPY_ERROR, destinationFilename);
                        log.Error(msg);
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Failure, "Export", msg, ex));
                        throw new Exception(msg, ex);
                    }
                    finally
                    {
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Export", string.Format(Messages.FILES_TRANSPORT_CLEANUP, uuid + ".vhd")));
                        m_iscsi.Disconnect(XenSession);
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Export", ""));
                    }
                }
            }
            finally
            {
                _vdiRefs.Clear();
            }
        }
示例#5
0
        private static void UpdateBiosGeometry(SparseStream contentStream, Geometry oldGeometry, Geometry newGeometry)
        {
            BiosPartitionTable partTable = new BiosPartitionTable(contentStream, oldGeometry);
            partTable.UpdateBiosGeometry(newGeometry);

            VolumeManager volMgr = new VolumeManager(contentStream);
            foreach (var volume in volMgr.GetLogicalVolumes())
            {
                foreach (var fsInfo in FileSystemManager.DetectDefaultFileSystems(volume.Open()))
                {
                    if (fsInfo.Name == "NTFS")
                    {
                        using (NtfsFileSystem fs = new NtfsFileSystem(volume.Open()))
                        {
                            fs.UpdateBiosGeometry(newGeometry);
                        }
                    }
                }
            }
        }
示例#6
0
 public void TotalSectors()
 {
     Geometry g = new Geometry(333, 22, 11);
     Assert.AreEqual(333 * 22 * 11, g.TotalSectors);
 }
示例#7
0
        /// <summary>
        /// Create a new virtual disk.
        /// </summary>
        /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>).</param>
        /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>).</param>
        /// <param name="path">The path (or URI) for the disk to create.</param>
        /// <param name="capacity">The capacity of the new disk.</param>
        /// <param name="geometry">The geometry of the new disk (or null).</param>
        /// <param name="user">The user identity to use when accessing the <c>path</c> (or null).</param>
        /// <param name="password">The password to use when accessing the <c>path</c> (or null).</param>
        /// <param name="parameters">Untyped parameters controlling the creation process (TBD).</param>
        /// <returns>The newly created disk.</returns>
        public static VirtualDisk CreateDisk(string type, string variant, string path, long capacity, Geometry geometry, string user, string password, Dictionary<string, string> parameters)
        {
            VirtualDiskParameters diskParams = new VirtualDiskParameters()
            {
                AdapterType = GenericDiskAdapterType.Scsi,
                Capacity = capacity,
                Geometry = geometry,
            };

            if (parameters != null)
            {
                foreach (var key in parameters.Keys)
                {
                    diskParams.ExtendedParameters[key] = parameters[key];
                }
            }

            return CreateDisk(type, variant, path, diskParams, user, password);
        }
示例#8
0
 public void Capacity()
 {
     Geometry g = new Geometry(333, 22, 11);
     Assert.AreEqual(333 * 22 * 11 * 512, g.Capacity);
 }
示例#9
0
        /// <summary>
        /// Create a new virtual disk, possibly within an existing disk.
        /// </summary>
        /// <param name="fileSystem">The file system to create the disk on.</param>
        /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>).</param>
        /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>).</param>
        /// <param name="path">The path (or URI) for the disk to create.</param>
        /// <param name="capacity">The capacity of the new disk.</param>
        /// <param name="geometry">The geometry of the new disk (or null).</param>
        /// <param name="parameters">Untyped parameters controlling the creation process (TBD).</param>
        /// <returns>The newly created disk.</returns>
        public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters)
        {
            VirtualDiskFactory factory = TypeMap[type];

            VirtualDiskParameters diskParams = new VirtualDiskParameters()
            {
                AdapterType = GenericDiskAdapterType.Scsi,
                Capacity = capacity,
                Geometry = geometry,
            };

            if (parameters != null)
            {
                foreach (var key in parameters.Keys)
                {
                    diskParams.ExtendedParameters[key] = parameters[key];
                }
            }

            return factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), diskParams);
        }
示例#10
0
 /// <summary>
 /// Create a new virtual disk.
 /// </summary>
 /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>).</param>
 /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>).</param>
 /// <param name="path">The path (or URI) for the disk to create.</param>
 /// <param name="capacity">The capacity of the new disk.</param>
 /// <param name="geometry">The geometry of the new disk (or null).</param>
 /// <param name="parameters">Untyped parameters controlling the creation process (TBD).</param>
 /// <returns>The newly created disk.</returns>
 public static VirtualDisk CreateDisk(string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters)
 {
     return CreateDisk(type, variant, path, capacity, geometry, null, null, parameters);
 }
示例#11
0
 /// <summary>
 /// Converts a geometry into one that is BIOS-safe, if not already.
 /// </summary>
 /// <param name="geometry">The geometry to make BIOS-safe.</param>
 /// <param name="capacity">The capacity of the disk.</param>
 /// <returns>The new geometry</returns>
 /// <remarks>This method returns the LBA-Assisted geometry if the given geometry isn't BIOS-safe.</remarks>
 public static Geometry MakeBiosSafe(Geometry geometry, long capacity)
 {
     if(geometry == null)
     {
         return LbaAssistedBiosGeometry(capacity);
     }
     else if (geometry.IsBiosSafe)
     {
         return geometry;
     }
     else
     {
         return LbaAssistedBiosGeometry(capacity);
     }
 }
示例#12
0
        /// <summary>
        /// Gets the 'Large' BIOS geometry for a disk, given it's physical geometry.
        /// </summary>
        /// <param name="ideGeometry">The physical (aka IDE) geometry of the disk</param>
        /// <returns>The geometry a BIOS using the 'Large' method for calculating disk geometry will indicate for the disk</returns>
        public static Geometry LargeBiosGeometry(Geometry ideGeometry)
        {
            int cylinders = ideGeometry.Cylinders;
            int heads = ideGeometry.HeadsPerCylinder;
            int sectors = ideGeometry.SectorsPerTrack;

            while (cylinders > 1024 && heads <= 127)
            {
                cylinders >>= 1;
                heads <<= 1;
            }

            return new Geometry(cylinders, heads, sectors);
        }
 public abstract VirtualDisk CreateDisk(FileLocator locator, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters);
示例#14
0
        /// <summary>
        /// Create a new virtual disk.
        /// </summary>
        /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>)</param>
        /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>)</param>
        /// <param name="path">The path (or URI) for the disk to create</param>
        /// <param name="capacity">The capacity of the new disk</param>
        /// <param name="geometry">The geometry of the new disk (or null).</param>
        /// <param name="user">The user identity to use when accessing the <c>path</c> (or null)</param>
        /// <param name="password">The password to use when accessing the <c>path</c> (or null)</param>
        /// <param name="parameters">Untyped parameters controlling the creation process (TBD)</param>
        /// <returns>The newly created disk</returns>
        public static VirtualDisk CreateDisk(string type, string variant, string path, long capacity, Geometry geometry, string user, string password, Dictionary<string, string> parameters)
        {
            Uri uri = PathToUri(path);
            VirtualDisk result = null;

            VirtualDiskTransport transport;
            if (!DiskTransports.TryGetValue(uri.Scheme.ToUpperInvariant(), out transport))
            {
                throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, "Unable to parse path '{0}'", path), path);
            }

            try
            {
                transport.Connect(uri, user, password);

                if (transport.IsRawDisk)
                {
                    result = transport.OpenDisk(FileAccess.ReadWrite);
                }
                else
                {
                    VirtualDiskFactory factory = TypeMap[type];

                    result = factory.CreateDisk(transport.GetFileLocator(), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), capacity, geometry, parameters ?? new Dictionary<string, string>());
                }

                if (result != null)
                {
                    result._transport = transport;
                    transport = null;
                }

                return result;
            }
            finally
            {
                if (transport != null)
                {
                    transport.Dispose();
                }
            }
        }
示例#15
0
 /// <summary>
 /// Create a new virtual disk, possibly within an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to create the disk on</param>
 /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>)</param>
 /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>)</param>
 /// <param name="path">The path (or URI) for the disk to create</param>
 /// <param name="capacity">The capacity of the new disk</param>
 /// <param name="geometry">The geometry of the new disk (or null).</param>
 /// <param name="parameters">Untyped parameters controlling the creation process (TBD)</param>
 /// <returns>The newly created disk</returns>
 public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters)
 {
     VirtualDiskFactory factory = TypeMap[type];
     return factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), capacity, geometry, parameters ?? new Dictionary<string, string>());
 }