Esempio n. 1
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="fileLocator">The object used to locate / create the component files.</param>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="parameters">The desired parameters for the new disk.</param>
        /// <returns>The newly created disk image</returns>
        internal static DiskImageFile Initialize(FileLocator fileLocator, string path, DiskParameters parameters)
        {
            if (parameters.Capacity <= 0)
            {
                throw new ArgumentException("Capacity must be greater than zero", "parameters");
            }

            Geometry geometry = parameters.Geometry ?? DefaultGeometry(parameters.Capacity);

            Geometry biosGeometry;

            if (parameters.BiosGeometry != null)
            {
                biosGeometry = parameters.BiosGeometry;
            }
            else
            {
                biosGeometry = Geometry.MakeBiosSafe(geometry, parameters.Capacity);
            }


            DiskAdapterType adapterType = (parameters.AdapterType == DiskAdapterType.None) ? DiskAdapterType.LsiLogicScsi : parameters.AdapterType;
            DiskCreateType  createType  = (parameters.CreateType == DiskCreateType.None) ? DiskCreateType.MonolithicSparse : parameters.CreateType;

            DescriptorFile baseDescriptor = CreateSimpleDiskDescriptor(geometry, biosGeometry, createType, adapterType);

            return(DoInitialize(fileLocator, path, parameters.Capacity, createType, baseDescriptor));
        }
Esempio n. 2
0
        private static ExtentType CreateTypeToExtentType(DiskCreateType type)
        {
            switch (type)
            {
            case DiskCreateType.FullDevice:
            case DiskCreateType.MonolithicFlat:
            case DiskCreateType.PartitionedDevice:
            case DiskCreateType.TwoGbMaxExtentFlat:
                return(ExtentType.Flat);

            case DiskCreateType.MonolithicSparse:
            case DiskCreateType.StreamOptimized:
            case DiskCreateType.TwoGbMaxExtentSparse:
                return(ExtentType.Sparse);

            case DiskCreateType.Vmfs:
                return(ExtentType.Vmfs);

            case DiskCreateType.VmfsPassthroughRawDeviceMap:
                return(ExtentType.VmfsRdm);

            case DiskCreateType.VmfsRaw:
            case DiskCreateType.VmfsRawDeviceMap:
                return(ExtentType.VmfsRaw);

            case DiskCreateType.VmfsSparse:
                return(ExtentType.VmfsSparse);

            default:
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to convert {0}", type));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <param name="type">The type of virtual disk to create</param>
        /// <returns>The newly created disk image</returns>
        public static DiskImageFile Initialize(string path, long capacity, DiskCreateType type)
        {
            DiskParameters diskParams = new DiskParameters();

            diskParams.Capacity   = capacity;
            diskParams.CreateType = type;

            return(Initialize(path, diskParams));
        }
Esempio n. 4
0
        private static DescriptorFile CreateDifferencingDiskDescriptor(DiskCreateType type, DiskImageFile parent, string parentPath)
        {
            DescriptorFile baseDescriptor = new DescriptorFile();

            baseDescriptor.ContentId          = (uint)_rng.Next();
            baseDescriptor.ParentContentId    = parent.ContentId;
            baseDescriptor.ParentFileNameHint = parentPath;
            baseDescriptor.CreateType         = type;
            return(baseDescriptor);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="fileSystem">The file system to create the VMDK on.</param>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk.</param>
        /// <param name="createType">The type of virtual disk to create.</param>
        /// <returns>The newly created disk image.</returns>
        public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, long capacity,
                                               DiskCreateType createType)
        {
            DiskParameters diskParams = new DiskParameters();

            diskParams.Capacity   = capacity;
            diskParams.CreateType = createType;

            return(Initialize(fileSystem, path, diskParams));
        }
Esempio n. 6
0
 internal static VirtualDiskTypeInfo MakeDiskTypeInfo(DiskCreateType createType)
 {
     return new VirtualDiskTypeInfo()
     {
         Name = "VMDK",
         Variant = CreateTypeToVariant(createType),
         CanBeHardDisk = true,
         DeterministicGeometry = false,
         PreservesBiosGeometry = false,
         CalcGeometry = c => DiskImageFile.DefaultGeometry(c),
     };
 }
Esempio n. 7
0
 internal static VirtualDiskTypeInfo MakeDiskTypeInfo(DiskCreateType createType)
 {
     return(new VirtualDiskTypeInfo()
     {
         Name = "VMDK",
         Variant = CreateTypeToVariant(createType),
         CanBeHardDisk = true,
         DeterministicGeometry = false,
         PreservesBiosGeometry = false,
         CalcGeometry = c => DiskImageFile.DefaultGeometry(c),
     });
 }
Esempio n. 8
0
        private static string FormatCreateType(DiskCreateType value)
        {
            switch (value)
            {
            case DiskCreateType.MonolithicSparse:
                return("monolithicSparse");

            case DiskCreateType.VmfsSparse:
                return("vmfsSparse");

            case DiskCreateType.MonolithicFlat:
                return("monolithicFlat");

            case DiskCreateType.Vmfs:
                return("vmfs");

            case DiskCreateType.TwoGbMaxExtentSparse:
                return("twoGbMaxExtentSparse");

            case DiskCreateType.TwoGbMaxExtentFlat:
                return("twoGbMaxExtentFlat");

            case DiskCreateType.FullDevice:
                return("fullDevice");

            case DiskCreateType.VmfsRaw:
                return("vmfsRaw");

            case DiskCreateType.PartitionedDevice:
                return("partitionedDevice");

            case DiskCreateType.VmfsRawDeviceMap:
                return("vmfsRawDeviceMap");

            case DiskCreateType.VmfsPassthroughRawDeviceMap:
                return("vmfsPassthroughRawDeviceMap");

            case DiskCreateType.StreamOptimized:
                return("streamOptimized");

            case DiskCreateType.SeSparse:
                return("seSparse");

            case DiskCreateType.VsanSparse:
                return("vsanSparse");

            default:
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Unknown type: {0}", value), nameof(value));
            }
        }
Esempio n. 9
0
        internal static DescriptorFile CreateSimpleDiskDescriptor(Geometry geometry, Geometry biosGeometery,
                                                                  DiskCreateType createType, DiskAdapterType adapterType)
        {
            DescriptorFile baseDescriptor = new DescriptorFile();

            baseDescriptor.DiskGeometry    = geometry;
            baseDescriptor.BiosGeometry    = biosGeometery;
            baseDescriptor.ContentId       = (uint)_rng.Next();
            baseDescriptor.CreateType      = createType;
            baseDescriptor.UniqueId        = Guid.NewGuid();
            baseDescriptor.HardwareVersion = "4";
            baseDescriptor.AdapterType     = adapterType;
            return(baseDescriptor);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new virtual disk that is a linked clone of an existing disk.
        /// </summary>
        /// <param name="path">The path to the new disk</param>
        /// <param name="type">The type of the new disk</param>
        /// <param name="parent">The disk to clone</param>
        /// <returns>The new virtual disk</returns>
        public static DiskImageFile InitializeDifferencing(string path, DiskCreateType type, string parent)
        {
            if (type != DiskCreateType.MonolithicSparse && type != DiskCreateType.TwoGbMaxExtentSparse && type != DiskCreateType.VmfsSparse)
            {
                throw new ArgumentException("Differencing disks must be sparse", "type");
            }

            using (DiskImageFile parentFile = new DiskImageFile(parent, FileAccess.Read))
            {
                DescriptorFile baseDescriptor = CreateDifferencingDiskDescriptor(type, parentFile, parent);

                FileLocator locator = new LocalFileLocator(Path.GetDirectoryName(path));
                return(DoInitialize(locator, Path.GetFileName(path), parentFile.Capacity, type, baseDescriptor));
            }
        }
Esempio n. 11
0
        private static DiskCreateType DiffDiskCreateType(DiskCreateType diskCreateType)
        {
            switch (diskCreateType)
            {
            case DiskCreateType.FullDevice:
            case DiskCreateType.MonolithicFlat:
            case DiskCreateType.MonolithicSparse:
            case DiskCreateType.PartitionedDevice:
            case DiskCreateType.StreamOptimized:
            case DiskCreateType.TwoGbMaxExtentFlat:
            case DiskCreateType.TwoGbMaxExtentSparse:
                return(DiskCreateType.MonolithicSparse);

            default:
                return(DiskCreateType.VmfsSparse);
            }
        }
Esempio n. 12
0
        private static string CreateTypeToVariant(DiskCreateType createType)
        {
            switch (createType)
            {
            case DiskCreateType.MonolithicFlat:
            case DiskCreateType.TwoGbMaxExtentFlat:
                return("fixed");

            case DiskCreateType.MonolithicSparse:
            case DiskCreateType.TwoGbMaxExtentSparse:
                return("dynamic");

            case DiskCreateType.Vmfs:
                return("vmfsfixed");

            case DiskCreateType.VmfsSparse:
                return("vmfsdynamic");

            default:
                return("fixed");
            }
        }
Esempio n. 13
0
        private static ExtentType CreateTypeToExtentType(DiskCreateType type)
        {
            switch (type)
            {
                case DiskCreateType.FullDevice:
                case DiskCreateType.MonolithicFlat:
                case DiskCreateType.PartitionedDevice:
                case DiskCreateType.TwoGbMaxExtentFlat:
                    return ExtentType.Flat;

                case DiskCreateType.MonolithicSparse:
                case DiskCreateType.StreamOptimized:
                case DiskCreateType.TwoGbMaxExtentSparse:
                    return ExtentType.Sparse;

                case DiskCreateType.Vmfs:
                    return ExtentType.Vmfs;

                case DiskCreateType.VmfsPassthroughRawDeviceMap:
                    return ExtentType.VmfsRdm;

                case DiskCreateType.VmfsRaw:
                case DiskCreateType.VmfsRawDeviceMap:
                    return ExtentType.VmfsRaw;

                case DiskCreateType.VmfsSparse:
                    return ExtentType.VmfsSparse;

                default:
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to convert {0}", type));
            }
        }
Esempio n. 14
0
        private static DiskImageFile DoInitialize(FileLocator fileLocator, string file, long capacity, DiskCreateType type, DescriptorFile baseDescriptor)
        {
            if (type == DiskCreateType.MonolithicSparse)
            {
                // MonolithicSparse is a special case, the descriptor is embedded in the file itself...
                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    long descriptorStart;
                    CreateExtent(fs, capacity, ExtentType.Sparse, 10 * Sizes.OneKiB, out descriptorStart);

                    ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, ExtentType.Sparse, file, 0);
                    fs.Position = descriptorStart * Sizes.Sector;
                    baseDescriptor.Extents.Add(extent);
                    baseDescriptor.Write(fs);
                }
            }
            else
            {
                ExtentType extentType = CreateTypeToExtentType(type);
                long totalSize = 0;
                List<ExtentDescriptor> extents = new List<ExtentDescriptor>();
                if (type == DiskCreateType.MonolithicFlat || type == DiskCreateType.VmfsSparse || type == DiskCreateType.Vmfs)
                {
                    string adornment = "flat";
                    if(type == DiskCreateType.VmfsSparse)
                    {
                        adornment = string.IsNullOrEmpty(baseDescriptor.ParentFileNameHint) ? "sparse" : "delta";
                    }

                    string fileName = AdornFileName(file, adornment);

                    using(Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        CreateExtent(fs, capacity, extentType);
                        extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, extentType, fileName, 0));
                        totalSize = capacity;
                    }
                }
                else if (type == DiskCreateType.TwoGbMaxExtentFlat || type == DiskCreateType.TwoGbMaxExtentSparse)
                {
                    int i = 1;
                    while (totalSize < capacity)
                    {
                        string adornment;
                        if (type == DiskCreateType.TwoGbMaxExtentSparse)
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "s{0:x3}", i);
                        }
                        else
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "{0:x6}", i);
                        }

                        string fileName = AdornFileName(file, adornment);

                        using (Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                        {
                            long extentSize = Math.Min(2 * Sizes.OneGiB - Sizes.OneMiB, capacity - totalSize);
                            CreateExtent(fs, extentSize, extentType);
                            extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, extentSize / Sizes.Sector, extentType, fileName, 0));
                            totalSize += extentSize;
                        }

                        ++i;
                    }
                }
                else
                {
                    throw new NotSupportedException("Creating disks of this type is not supported");
                }

                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    baseDescriptor.Extents.AddRange(extents);
                    baseDescriptor.Write(fs);
                }
            }

            return new DiskImageFile(fileLocator, file, FileAccess.ReadWrite);
        }
Esempio n. 15
0
        /// <summary>
        /// Creates a new virtual disk that is a linked clone of an existing disk.
        /// </summary>
        /// <param name="fileSystem">The file system to create the VMDK on</param>
        /// <param name="path">The path to the new disk</param>
        /// <param name="type">The type of the new disk</param>
        /// <param name="parent">The disk to clone</param>
        /// <returns>The new virtual disk</returns>
        public static DiskImageFile InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parent)
        {
            if (type != DiskCreateType.MonolithicSparse && type != DiskCreateType.TwoGbMaxExtentSparse && type != DiskCreateType.VmfsSparse)
            {
                throw new ArgumentException("Differencing disks must be sparse", "type");
            }

            string basePath = Path.GetDirectoryName(path);
            FileLocator locator = new DiscFileLocator(fileSystem, basePath);
            FileLocator parentLocator = locator.GetRelativeLocator(Path.GetDirectoryName(parent));

            using (DiskImageFile parentFile = new DiskImageFile(parentLocator, Path.GetFileName(parent), FileAccess.Read))
            {
                DescriptorFile baseDescriptor = CreateDifferencingDiskDescriptor(type, parentFile, parent);

                return DoInitialize(locator, Path.GetFileName(path), parentFile.Capacity, type, baseDescriptor);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a new virtual disk that is a linked clone of an existing disk.
        /// </summary>
        /// <param name="fileSystem">The file system to create the VMDK on.</param>
        /// <param name="path">The path to the new disk.</param>
        /// <param name="type">The type of the new disk.</param>
        /// <param name="parent">The disk to clone.</param>
        /// <returns>The new virtual disk.</returns>
        public static DiskImageFile InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parent)
        {
            if (type != DiskCreateType.MonolithicSparse && type != DiskCreateType.TwoGbMaxExtentSparse && type != DiskCreateType.VmfsSparse)
            {
                throw new ArgumentException("Differencing disks must be sparse", "type");
            }

            string      basePath      = Utilities.GetDirectoryFromPath(path);
            FileLocator locator       = new DiscFileLocator(fileSystem, basePath);
            FileLocator parentLocator = locator.GetRelativeLocator(Utilities.GetDirectoryFromPath(parent));

            using (DiskImageFile parentFile = new DiskImageFile(parentLocator, Utilities.GetFileFromPath(parent), FileAccess.Read))
            {
                DescriptorFile baseDescriptor = CreateDifferencingDiskDescriptor(type, parentFile, parent);

                return(DoInitialize(locator, Utilities.GetFileFromPath(path), parentFile.Capacity, type, baseDescriptor));
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Creates a new virtual disk at the specified location on a file system.
 /// </summary>
 /// <param name="fileSystem">The file system to contain the disk</param>
 /// <param name="path">The file system path to the disk</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType type, DiskAdapterType adapterType)
 {
     return(new Disk(DiskImageFile.Initialize(fileSystem, path, capacity, type, adapterType), Ownership.Dispose));
 }
Esempio n. 18
0
 /// <summary>
 /// Creates a new virtual disk at the specified path.
 /// </summary>
 /// <param name="path">The name of the VMDK to create.</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(string path, long capacity, DiskCreateType type, DiskAdapterType adapterType)
 {
     return(Initialize(path, capacity, null, type, adapterType));
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new virtual disk at the specified path.
 /// </summary>
 /// <param name="path">The name of the VMDK to create.</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(string path, long capacity, DiskCreateType type, DiskAdapterType adapterType)
 {
     return Initialize(path, capacity, null, type, adapterType);
 }
Esempio n. 20
0
        private static string CreateTypeToVariant(DiskCreateType createType)
        {
            switch (createType)
            {
                case DiskCreateType.MonolithicFlat:
                case DiskCreateType.TwoGbMaxExtentFlat:
                    return "fixed";

                case DiskCreateType.MonolithicSparse:
                case DiskCreateType.TwoGbMaxExtentSparse:
                    return "dynamic";

                case DiskCreateType.Vmfs:
                    return "vmfsfixed";

                case DiskCreateType.VmfsSparse:
                    return "vmfsdynamic";

                default:
                    return "fixed";
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Creates a new virtual disk at the specified path.
 /// </summary>
 /// <param name="path">The name of the VMDK to create.</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="geometry">The desired geometry of the new disk, or <c>null</c> for default</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(string path, long capacity, Geometry geometry, DiskCreateType type, DiskAdapterType adapterType)
 {
     return new Disk(DiskImageFile.Initialize(path, capacity, geometry, type, adapterType), Ownership.Dispose);
 }
Esempio n. 22
0
 /// <summary>
 /// Initializes a new instance of the DiskBuilder class.
 /// </summary>
 public DiskBuilder()
 {
     _diskType = DiskCreateType.Vmfs;
     _adapterType = DiskAdapterType.LsiLogicScsi;
 }
Esempio n. 23
0
 /// <summary>
 /// Creates a new virtual disk at the specified location on a file system.
 /// </summary>
 /// <param name="fileSystem">The file system to contain the disk</param>
 /// <param name="path">The file system path to the disk</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType type, DiskAdapterType adapterType)
 {
     return new Disk(DiskImageFile.Initialize(fileSystem, path, capacity, type, adapterType), Ownership.Dispose);
 }
Esempio n. 24
0
        private static DiskImageFile DoInitialize(FileLocator fileLocator, string file, long capacity, DiskCreateType type, DescriptorFile baseDescriptor)
        {
            if (type == DiskCreateType.MonolithicSparse)
            {
                // MonolithicSparse is a special case, the descriptor is embedded in the file itself...
                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    long descriptorStart;
                    CreateExtent(fs, capacity, ExtentType.Sparse, 10 * Sizes.OneKiB, out descriptorStart);

                    ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, ExtentType.Sparse, file, 0);
                    fs.Position = descriptorStart * Sizes.Sector;
                    baseDescriptor.Extents.Add(extent);
                    baseDescriptor.Write(fs);
                }
            }
            else
            {
                ExtentType extentType           = CreateTypeToExtentType(type);
                long       totalSize            = 0;
                List <ExtentDescriptor> extents = new List <ExtentDescriptor>();
                if (type == DiskCreateType.MonolithicFlat || type == DiskCreateType.VmfsSparse || type == DiskCreateType.Vmfs)
                {
                    string adornment = "flat";
                    if (type == DiskCreateType.VmfsSparse)
                    {
                        adornment = string.IsNullOrEmpty(baseDescriptor.ParentFileNameHint) ? "sparse" : "delta";
                    }

                    string fileName = AdornFileName(file, adornment);

                    using (Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        CreateExtent(fs, capacity, extentType);
                        extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, capacity / Sizes.Sector, extentType, fileName, 0));
                        totalSize = capacity;
                    }
                }
                else if (type == DiskCreateType.TwoGbMaxExtentFlat || type == DiskCreateType.TwoGbMaxExtentSparse)
                {
                    int i = 1;
                    while (totalSize < capacity)
                    {
                        string adornment;
                        if (type == DiskCreateType.TwoGbMaxExtentSparse)
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "s{0:x3}", i);
                        }
                        else
                        {
                            adornment = string.Format(CultureInfo.InvariantCulture, "{0:x6}", i);
                        }

                        string fileName = AdornFileName(file, adornment);

                        using (Stream fs = fileLocator.Open(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                        {
                            long extentSize = Math.Min(2 * Sizes.OneGiB - Sizes.OneMiB, capacity - totalSize);
                            CreateExtent(fs, extentSize, extentType);
                            extents.Add(new ExtentDescriptor(ExtentAccess.ReadWrite, extentSize / Sizes.Sector, extentType, fileName, 0));
                            totalSize += extentSize;
                        }

                        ++i;
                    }
                }
                else
                {
                    throw new NotSupportedException("Creating disks of this type is not supported");
                }

                using (Stream fs = fileLocator.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    baseDescriptor.Extents.AddRange(extents);
                    baseDescriptor.Write(fs);
                }
            }

            return(new DiskImageFile(fileLocator, file, FileAccess.ReadWrite));
        }
Esempio n. 25
0
 /// <summary>
 /// Creates a new virtual disk as a thin clone of an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to contain the disk</param>
 /// <param name="path">The path to the new disk.</param>
 /// <param name="type">The type of disk to create</param>
 /// <param name="parentPath">The path to the parent disk.</param>
 /// <returns>The new disk.</returns>
 public static Disk InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parentPath)
 {
     return new Disk(DiskImageFile.InitializeDifferencing(fileSystem, path, type, parentPath), Ownership.Dispose);
 }
Esempio n. 26
0
 internal static DescriptorFile CreateSimpleDiskDescriptor(Geometry geometry, Geometry biosGeometery, DiskCreateType createType, DiskAdapterType adapterType)
 {
     DescriptorFile baseDescriptor = new DescriptorFile();
     baseDescriptor.DiskGeometry = geometry;
     baseDescriptor.BiosGeometry = biosGeometery;
     baseDescriptor.ContentId = (uint)_rng.Next();
     baseDescriptor.CreateType = createType;
     baseDescriptor.UniqueId = Guid.NewGuid();
     baseDescriptor.HardwareVersion = "4";
     baseDescriptor.AdapterType = adapterType;
     return baseDescriptor;
 }
Esempio n. 27
0
 private static string FormatCreateType(DiskCreateType value)
 {
     switch (value)
     {
         case DiskCreateType.MonolithicSparse:
             return "monolithicSparse";
         case DiskCreateType.VmfsSparse:
             return "vmfsSparse";
         case DiskCreateType.MonolithicFlat:
             return "monolithicFlat";
         case DiskCreateType.Vmfs:
             return "vmfs";
         case DiskCreateType.TwoGbMaxExtentSparse:
             return "twoGbMaxExtentSparse";
         case DiskCreateType.TwoGbMaxExtentFlat:
             return "twoGbMaxExtentFlat";
         case DiskCreateType.FullDevice:
             return "fullDevice";
         case DiskCreateType.VmfsRaw:
             return "vmfsRaw";
         case DiskCreateType.PartitionedDevice:
             return "partitionedDevice";
         case DiskCreateType.VmfsRawDeviceMap:
             return "vmfsRawDeviceMap";
         case DiskCreateType.VmfsPassthroughRawDeviceMap:
             return "vmfsPassthroughRawDeviceMap";
         case DiskCreateType.StreamOptimized:
             return "streamOptimized";
         default:
             throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unknown type: {0}", value), "value");
     }
 }
Esempio n. 28
0
 private static DescriptorFile CreateDifferencingDiskDescriptor(DiskCreateType type, DiskImageFile parent, string parentPath)
 {
     DescriptorFile baseDescriptor = new DescriptorFile();
     baseDescriptor.ContentId = (uint)_rng.Next();
     baseDescriptor.ParentContentId = parent.ContentId;
     baseDescriptor.ParentFileNameHint = parentPath;
     baseDescriptor.CreateType = type;
     return baseDescriptor;
 }
Esempio n. 29
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <param name="type">The type of virtual disk to create</param>
        /// <returns>The newly created disk image</returns>
        public static DiskImageFile Initialize(string path, long capacity, DiskCreateType type)
        {
            DiskParameters diskParams = new DiskParameters();
            diskParams.Capacity = capacity;
            diskParams.CreateType = type;

            return Initialize(path, diskParams);
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the DiskBuilder class.
 /// </summary>
 public DiskBuilder()
 {
     _diskType    = DiskCreateType.Vmfs;
     _adapterType = DiskAdapterType.LsiLogicScsi;
 }
Esempio n. 31
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <param name="geometry">The desired geometry of the new disk, or <c>null</c> for default</param>
        /// <param name="createType">The type of virtual disk to create</param>
        /// <param name="adapterType">The type of disk adapter used with the disk</param>
        /// <returns>The newly created disk image</returns>
        public static DiskImageFile Initialize(string path, long capacity, Geometry geometry, DiskCreateType createType, DiskAdapterType adapterType)
        {
            DiskParameters diskParams = new DiskParameters();
            diskParams.Capacity = capacity;
            diskParams.Geometry = geometry;
            diskParams.CreateType = createType;
            diskParams.AdapterType = adapterType;

            return Initialize(path, diskParams);
        }
Esempio n. 32
0
 /// <summary>
 /// Creates a new virtual disk at the specified path.
 /// </summary>
 /// <param name="path">The name of the VMDK to create.</param>
 /// <param name="capacity">The desired capacity of the new disk</param>
 /// <param name="geometry">The desired geometry of the new disk, or <c>null</c> for default</param>
 /// <param name="type">The type of virtual disk to create</param>
 /// <param name="adapterType">The type of virtual disk adapter</param>
 /// <returns>The newly created disk image</returns>
 public static Disk Initialize(string path, long capacity, Geometry geometry, DiskCreateType type, DiskAdapterType adapterType)
 {
     return(new Disk(DiskImageFile.Initialize(path, capacity, geometry, type, adapterType), Ownership.Dispose));
 }
Esempio n. 33
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="fileSystem">The file system to create the VMDK on</param>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <param name="createType">The type of virtual disk to create</param>
        /// <param name="adapterType">The type of disk adapter used with the disk</param>
        /// <returns>The newly created disk image</returns>
        public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType createType, DiskAdapterType adapterType)
        {
            DiskParameters diskParams = new DiskParameters();
            diskParams.Capacity = capacity;
            diskParams.CreateType = createType;
            diskParams.AdapterType = adapterType;

            return Initialize(fileSystem, path, diskParams);
        }
Esempio n. 34
0
 /// <summary>
 /// Creates a new virtual disk as a thin clone of an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to contain the disk</param>
 /// <param name="path">The path to the new disk.</param>
 /// <param name="type">The type of disk to create</param>
 /// <param name="parentPath">The path to the parent disk.</param>
 /// <returns>The new disk.</returns>
 public static Disk InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parentPath)
 {
     return(new Disk(DiskImageFile.InitializeDifferencing(fileSystem, path, type, parentPath), Ownership.Dispose));
 }
Esempio n. 35
0
        /// <summary>
        /// Creates a new virtual disk at the specified path.
        /// </summary>
        /// <param name="path">The name of the VMDK to create.</param>
        /// <param name="capacity">The desired capacity of the new disk</param>
        /// <param name="geometry">The desired geometry of the new disk, or <c>null</c> for default</param>
        /// <param name="createType">The type of virtual disk to create</param>
        /// <param name="adapterType">The type of disk adapter used with the disk</param>
        /// <returns>The newly created disk image</returns>
        public static DiskImageFile Initialize(string path, long capacity, Geometry geometry, DiskCreateType createType, DiskAdapterType adapterType)
        {
            DiskParameters diskParams = new DiskParameters();

            diskParams.Capacity    = capacity;
            diskParams.Geometry    = geometry;
            diskParams.CreateType  = createType;
            diskParams.AdapterType = adapterType;

            return(Initialize(path, diskParams));
        }