예제 #1
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose));
     ResolveFileChain();
 }
예제 #2
0
        /// <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));
        }
예제 #3
0
        /// <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));
        }
예제 #4
0
        /// <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));
        }
예제 #5
0
 /// <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 <Tuple <DiskImageFile, Ownership> >();
     _files.Add(new Tuple <DiskImageFile, Ownership>(file, ownsFile));
     if (file.NeedsParent)
     {
         _files.Add(new Tuple <DiskImageFile, Ownership>(parentFile, ownsParent));
         ResolveFileChain();
     }
     else
     {
         if (parentFile != null && ownsParent == Ownership.Dispose)
         {
             parentFile.Dispose();
         }
     }
 }
예제 #6
0
        internal static DiskImageFile InitializeDynamic(FileLocator locator, string path, long capacity, long blockSize)
        {
            DiskImageFile result = null;
            Stream        stream = locator.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

            try
            {
                InitializeDynamicInternal(stream, capacity, blockSize);
                result = new DiskImageFile(locator, path, stream, Ownership.Dispose);
                stream = null;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            return(result);
        }
예제 #7
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, ownsFile));
     if (file.NeedsParent)
     {
         _files.Add(
             new DiscUtils.Tuple<DiskImageFile, Ownership>(
                 new DiskImageFile(parentLocator, parentPath, FileAccess.Read),
                 Ownership.Dispose));
         ResolveFileChain();
     }
 }
예제 #8
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, ownsFile));
     ResolveFileChain();
 }
예제 #9
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose));
     ResolveFileChain();
 }
예제 #10
0
 internal static Disk InitializeDynamic(FileLocator fileLocator, string path, long capacity, long blockSize)
 {
     return(new Disk(DiskImageFile.InitializeDynamic(fileLocator, path, capacity, blockSize), Ownership.Dispose));
 }
예제 #11
0
 public DiskExtent(DiskImageFile file)
 {
     _file = file;
 }
        internal static DiskImageFile InitializeFixed(FileLocator locator, string path, long capacity, Geometry geometry)
        {
            DiskImageFile result = null;
            Stream stream = locator.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            try
            {
                InitializeFixedInternal(stream, capacity, geometry);
                result = new DiskImageFile(locator, path, stream, Ownership.Dispose);
                stream = null;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            return result;
        }
예제 #13
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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);
 }
예제 #14
0
 /// <summary>
 /// Initializes a stream as a dynamically-sized 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="capacity">The desired capacity of the new disk.</param>
 /// <param name="blockSize">The size of each block (unit of allocation).</param>
 /// <returns>An object that accesses the stream as a VHDX file.</returns>
 public static Disk InitializeDynamic(Stream stream, Ownership ownsStream, long capacity, long blockSize)
 {
     return(new Disk(DiskImageFile.InitializeDynamic(stream, ownsStream, capacity, blockSize), Ownership.Dispose));
 }
예제 #15
0
 /// <summary>
 /// Initializes a stream as a fixed-sized 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="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>
 /// <returns>An object that accesses the stream as a VHDX file.</returns>
 public static Disk InitializeFixed(Stream stream, Ownership ownsStream, long capacity, Geometry geometry)
 {
     return(new Disk(DiskImageFile.InitializeFixed(stream, ownsStream, capacity, geometry), Ownership.Dispose));
 }
예제 #16
0
 /// <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 <Tuple <DiskImageFile, Ownership> >();
     _files.Add(new Tuple <DiskImageFile, Ownership>(file, ownsFile));
     ResolveFileChain();
 }
예제 #17
0
 private static void InitializeDifferencingInternal(Stream stream, DiskImageFile parent, string parentAbsolutePath, string parentRelativePath, DateTime parentModificationTimeUtc)
 {
     throw new NotImplementedException();
 }
예제 #18
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, ownsFile));
     if (file.NeedsParent)
     {
         _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(parentFile, ownsParent));
         ResolveFileChain();
     }
     else
     {
         if (parentFile != null && ownsParent == Ownership.Dispose)
         {
             parentFile.Dispose();
         }
     }
 }
        /// <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);
        }
예제 #20
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
        /// <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);
        }
 private static void InitializeDifferencingInternal(Stream stream, DiskImageFile parent, string parentAbsolutePath, string parentRelativePath, DateTime parentModificationTimeUtc)
 {
     throw new NotImplementedException();
 }
예제 #22
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
        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 DiscUtils.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));
                }
            }
        }
예제 #23
0
 internal static Disk InitializeFixed(FileLocator fileLocator, string path, long capacity, Geometry geometry)
 {
     return(new Disk(DiskImageFile.InitializeFixed(fileLocator, path, capacity, geometry), Ownership.Dispose));
 }
예제 #24
0
파일: Disk.cs 프로젝트: JGTM2016/discutils
 /// <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<DiscUtils.Tuple<DiskImageFile, Ownership>>();
     _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose));
     ResolveFileChain();
 }
예제 #25
0
        protected override void DoRun()
        {
            using (DiskImageFile vhdxFile = new DiskImageFile(_vhdxFile.Value, FileAccess.Read))
            {
                DiskImageFileInfo info = vhdxFile.Information;

                FileInfo fileInfo = new FileInfo(_vhdxFile.Value);

                Console.WriteLine("File Info");
                Console.WriteLine("---------");
                Console.WriteLine("           File Name: {0}", fileInfo.FullName);
                Console.WriteLine("           File Size: {0} ({1} bytes)", Utilities.ApproximateDiskSize(fileInfo.Length), fileInfo.Length);
                Console.WriteLine("  File Creation Time: {0} (UTC)", fileInfo.CreationTimeUtc);
                Console.WriteLine("     File Write Time: {0} (UTC)", fileInfo.LastWriteTimeUtc);
                Console.WriteLine();

                Console.WriteLine("VHDX File Info");
                Console.WriteLine("--------------");
                Console.WriteLine("           Signature: {0:x8}", info.Signature);
                Console.WriteLine("             Creator: {0:x8}", info.Creator);
                Console.WriteLine("          Block Size: {0} (0x{0:X8})", info.BlockSize);
                Console.WriteLine("Leave Blocks Alloced: {0}", info.LeaveBlocksAllocated);
                Console.WriteLine("          Has Parent: {0}", info.HasParent);
                Console.WriteLine("           Disk Size: {0} ({1} (0x{1:X8}))", Utilities.ApproximateDiskSize(info.DiskSize), info.DiskSize);
                Console.WriteLine(" Logical Sector Size: {0} (0x{0:X8})", info.LogicalSectorSize);
                Console.WriteLine("Physical Sector Size: {0} (0x{0:X8})", info.PhysicalSectorSize);
                Console.WriteLine(" Parent Locator Type: {0}", info.ParentLocatorType);
                WriteParentLocations(info);
                Console.WriteLine();

                WriteHeaderInfo(info.FirstHeader);
                WriteHeaderInfo(info.SecondHeader);

                if (info.ActiveHeader.LogGuid != Guid.Empty)
                {
                    Console.WriteLine("Log Info (Active Sequence)");
                    Console.WriteLine("--------------------------");

                    foreach (var entry in info.ActiveLogSequence)
                    {
                        Console.WriteLine("   Log Entry");
                        Console.WriteLine("   ---------");
                        Console.WriteLine("         Sequence Number: {0}", entry.SequenceNumber);
                        Console.WriteLine("                    Tail: {0}", entry.Tail);
                        Console.WriteLine("     Flushed File Offset: {0} (0x{0:X8})", entry.FlushedFileOffset);
                        Console.WriteLine("        Last File Offset: {0} (0x{0:X8})", entry.LastFileOffset);
                        Console.WriteLine("            File Extents: {0}", entry.IsEmpty ? "<none>" : "");
                        foreach (var extent in entry.ModifiedExtents)
                        {
                            Console.WriteLine("                          {0} +{1}  (0x{0:X8} +0x{1:X8})", extent.Offset, extent.Count);
                        }
                        Console.WriteLine();
                    }
                }

                RegionTableInfo regionTable = info.RegionTable;
                Console.WriteLine("Region Table Info");
                Console.WriteLine("-----------------");
                Console.WriteLine("           Signature: {0}", regionTable.Signature);
                Console.WriteLine("            Checksum: {0:x8}", regionTable.Checksum);
                Console.WriteLine("         Entry Count: {0}", regionTable.Count);
                Console.WriteLine();

                foreach (var entry in regionTable)
                {
                    Console.WriteLine("Region Table Entry Info");
                    Console.WriteLine("-----------------------");
                    Console.WriteLine("                Guid: {0}", entry.Guid);
                    Console.WriteLine("     Well-Known Name: {0}", entry.WellKnownName);
                    Console.WriteLine("         File Offset: {0} (0x{0:X8})", entry.FileOffset);
                    Console.WriteLine("              Length: {0} (0x{0:X8})", entry.Length);
                    Console.WriteLine("         Is Required: {0}", entry.IsRequired);
                    Console.WriteLine();
                }

                MetadataTableInfo metadataTable = info.MetadataTable;
                Console.WriteLine("Metadata Table Info");
                Console.WriteLine("-------------------");
                Console.WriteLine("           Signature: {0}", metadataTable.Signature);
                Console.WriteLine("         Entry Count: {0}", metadataTable.Count);
                Console.WriteLine();

                foreach (var entry in metadataTable)
                {
                    Console.WriteLine("Metadata Table Entry Info");
                    Console.WriteLine("-------------------------");
                    Console.WriteLine("             Item Id: {0}", entry.ItemId);
                    Console.WriteLine("     Well-Known Name: {0}", entry.WellKnownName);
                    Console.WriteLine("              Offset: {0} (0x{0:X8})", entry.Offset);
                    Console.WriteLine("              Length: {0} (0x{0:X8})", entry.Length);
                    Console.WriteLine("             Is User: {0}", entry.IsUser);
                    Console.WriteLine("         Is Required: {0}", entry.IsRequired);
                    Console.WriteLine("     Is Virtual Disk: {0}", entry.IsVirtualDisk);
                    Console.WriteLine();
                }
            }
        }