/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="path">The path to the disk image</param> /// <param name="access">The access requested to the disk</param> public Disk(string path, FileAccess access) { DiskImageFile file = new DiskImageFile(path, access); _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="fileSystem">The file system containing the disk.</param> /// <param name="path">The file system relative path to the disk.</param> /// <param name="access">The access requested to the disk.</param> public Disk(DiscFileSystem fileSystem, string path, FileAccess access) { FileLocator fileLocator = new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)); DiskImageFile file = new DiskImageFile(fileLocator, Utilities.GetFileFromPath(path), access); _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
private void ResolveFileChain() { DiskImageFile file = _files[_files.Count - 1].First; while (file.NeedsParent) { FileLocator fileLocator = file.RelativeFileLocator; bool found = false; foreach (string testPath in file.GetParentLocations()) { if (fileLocator.Exists(testPath)) { DiskImageFile newFile = new DiskImageFile(fileLocator, testPath, FileAccess.Read); if (newFile.UniqueId != file.ParentUniqueId) { throw new IOException(string.Format(CultureInfo.InstalledUICulture, "Invalid disk chain found looking for parent with id {0}, found {1} with id {2}", file.ParentUniqueId, newFile.FullPath, newFile.UniqueId)); } file = newFile; _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); found = true; break; } } if (!found) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "Failed to find parent for disk '{0}'", file.FullPath)); } } }
/// <summary> /// Creates a new VHDX differencing disk file. /// </summary> /// <param name="path">The path to the new disk file</param> /// <param name="parentPath">The path to the parent disk file</param> /// <returns>An object that accesses the new file as a Disk</returns> public static Disk InitializeDifferencing(string path, string parentPath) { LocalFileLocator parentLocator = new LocalFileLocator(Path.GetDirectoryName(parentPath)); string parentFileName = Path.GetFileName(parentPath); DiskImageFile newFile; using (DiskImageFile parent = new DiskImageFile(parentLocator, parentFileName, FileAccess.Read)) { LocalFileLocator locator = new LocalFileLocator(Path.GetDirectoryName(path)); newFile = parent.CreateDifferencing(locator, Path.GetFileName(path)); } return new Disk(newFile, Ownership.Dispose, parentLocator, parentFileName); }
/// <summary> /// Initializes a stream as a differencing disk VHDX file. /// </summary> /// <param name="stream">The stream to initialize.</param> /// <param name="ownsStream">Indicates if the new instance controls the lifetime of the <paramref name="stream"/>.</param> /// <param name="parent">The disk this file is a different from.</param> /// <param name="ownsParent">Indicates if the new instance controls the lifetime of the <paramref name="parent"/> file.</param> /// <param name="parentAbsolutePath">The full path to the parent disk.</param> /// <param name="parentRelativePath">The relative path from the new disk to the parent disk.</param> /// <param name="parentModificationTime">The time the parent disk's file was last modified (from file system).</param> /// <returns>An object that accesses the stream as a VHDX file</returns> public static Disk InitializeDifferencing( Stream stream, Ownership ownsStream, DiskImageFile parent, Ownership ownsParent, string parentAbsolutePath, string parentRelativePath, DateTime parentModificationTime) { DiskImageFile file = DiskImageFile.InitializeDifferencing(stream, ownsStream, parent, parentAbsolutePath, parentRelativePath, parentModificationTime); return new Disk(file, Ownership.Dispose, parent, ownsParent); }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="file">The file containing the disk</param> /// <param name="ownsFile">Indicates if the new instance should control the lifetime of the file.</param> /// <param name="parentLocator">Object used to locate the parent disk</param> /// <param name="parentPath">Path to the parent disk (if required)</param> private Disk(DiskImageFile file, Ownership ownsFile, FileLocator parentLocator, string parentPath) { _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, ownsFile)); if (file.NeedsParent) { _files.Add( new ThinkAway.Tuple<DiskImageFile, Ownership>( new DiskImageFile(parentLocator, parentPath, FileAccess.Read), Ownership.Dispose)); ResolveFileChain(); } }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="file">The file containing the disk</param> /// <param name="ownsFile">Indicates if the new instance should control the lifetime of the file.</param> /// <param name="parentFile">The file containing the disk's parent</param> /// <param name="ownsParent">Indicates if the new instance should control the lifetime of the parentFile</param> private Disk(DiskImageFile file, Ownership ownsFile, DiskImageFile parentFile, Ownership ownsParent) { _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, ownsFile)); if (file.NeedsParent) { _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(parentFile, ownsParent)); ResolveFileChain(); } else { if (parentFile != null && ownsParent == Ownership.Dispose) { parentFile.Dispose(); } } }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are not supported. /// </summary> /// <param name="file">The file containing the disk</param> /// <param name="ownsFile">Indicates if the new instance should control the lifetime of the file.</param> private Disk(DiskImageFile file, Ownership ownsFile) { _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, ownsFile)); ResolveFileChain(); }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="locator">The locator to access relative files</param> /// <param name="path">The path to the disk image</param> /// <param name="access">The access requested to the disk</param> internal Disk(FileLocator locator, string path, FileAccess access) { DiskImageFile file = new DiskImageFile(locator, path, access); _files = new List<ThinkAway.Tuple<DiskImageFile, Ownership>>(); _files.Add(new ThinkAway.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
private static void InitializeDifferencingInternal(Stream stream, DiskImageFile parent, string parentAbsolutePath, string parentRelativePath, DateTime parentModificationTimeUtc) { throw new NotImplementedException(); }
internal static DiskImageFile InitializeDynamic(FileLocator locator, string path, long capacity, Geometry geometry, long blockSize) { DiskImageFile result = null; Stream stream = locator.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None); try { InitializeDynamicInternal(stream, capacity, geometry, blockSize); result = new DiskImageFile(locator, path, stream, Ownership.Dispose); stream = null; } finally { if (stream != null) { stream.Dispose(); } } return result; }
/// <summary> /// Initializes a stream as a differencing disk VHDX file. /// </summary> /// <param name="stream">The stream to initialize.</param> /// <param name="ownsStream">Indicates if the new instance controls the lifetime of the stream.</param> /// <param name="parent">The disk this file is a different from.</param> /// <param name="parentAbsolutePath">The full path to the parent disk.</param> /// <param name="parentRelativePath">The relative path from the new disk to the parent disk.</param> /// <param name="parentModificationTimeUtc">The time the parent disk's file was last modified (from file system).</param> /// <returns>An object that accesses the stream as a VHDX file</returns> public static DiskImageFile InitializeDifferencing( Stream stream, Ownership ownsStream, DiskImageFile parent, string parentAbsolutePath, string parentRelativePath, DateTime parentModificationTimeUtc) { InitializeDifferencingInternal(stream, parent, parentAbsolutePath, parentRelativePath, parentModificationTimeUtc); return new DiskImageFile(stream, ownsStream); }