Beispiel #1
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);
            }
        }
Beispiel #2
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;
 }
Beispiel #3
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);
            }
        }