无法使用DiscUtils C#库从VMDK文件流复制字节

时间:2014-06-02 13:05:23

标签: c#

我使用.NET DiscUtils访问C#中的VMDK光盘。我可以访问文件并获取有关它们的信息,但是当我尝试使用Streams复制它们时,我得到:

System.ArgumentOutOfRangeException: Attempt to move beyond end of stream

调试时,我发现在Stream中设置位置光标时会从SubStream.cs at line 99触发异常。

我无法理解为什么会被解雇...这是我的代码:

using DiscUtils;
using DiscUtils.Fat;
using DiscUtils.Vmdk;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DebugDiscUtils
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\Me\VirtualBox VMs\ECS\myECSDisk-disk2.vmdk";
            VirtualDisk disk = new DiscUtils.Vmdk.Disk(new FileStream(path, FileMode.Open, FileAccess.ReadWrite), Ownership.None);
            FatFileSystem fs2 = new FatFileSystem(disk.Partitions[0].Open());
            Stream s = fs2.OpenFile(fs2.GetFiles(fs2.Root.Name)[0], FileMode.Open);
            Console.WriteLine("L: " + s.Length);
            try
            {
                int val = s.ReadByte(); //******The Exception is fired HERE********//
                int cpt  = 1;
                while (val != -1)
                {
                    Console.WriteLine("Byte " + cpt + ": " + val);
                    val = s.ReadByte();
                    cpt++;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.ReadKey();
        }
    }
}

修改 这是堆栈跟踪:

System.ArgumentOutOfRangeException: Attempt to move beyond end of stream
Parameter name: value

   at DiscUtils.SubStream.set_Position(Int64 value) in c:\Data\Dev\C#\discutils_
f0bb9c34a81e\src\SubStream.cs:line 99

   at DiscUtils.Fat.ClusterReader.ReadCluster(UInt32 cluster, Byte[] buffer, Int
32 offset) in c:\Data\Dev\C#\discutils_f0bb9c34a81e\src\Fat\ClusterReader.cs:lin
e 66

   at DiscUtils.Fat.ClusterStream.TryLoadClusterByPosition(Int64 pos) in c:\Data
\Dev\C#\discutils_f0bb9c34a81e\src\Fat\ClusterStream.cs:line 396

   at DiscUtils.Fat.ClusterStream.TryLoadCurrentCluster() in c:\Data\Dev\C#\disc
utils_f0bb9c34a81e\src\Fat\ClusterStream.cs:line 382

   at DiscUtils.Fat.ClusterStream.Read(Byte[] buffer, Int32 offset, Int32 count)
 in c:\Data\Dev\C#\discutils_f0bb9c34a81e\src\Fat\ClusterStream.cs:line 143

   at DiscUtils.Fat.FatFileStream.Read(Byte[] buffer, Int32 offset, Int32 count)
 in c:\Data\Dev\C#\discutils_f0bb9c34a81e\src\Fat\FatFileStream.cs:line 125

   at System.IO.Stream.ReadByte()

   at DebugDiscUtils.Program.Main(String[] args) in c:\Data\Dev\C#\discutils_f0b
b9c34a81e\DebugDiscUtils\Program.cs:line 26

0 个答案:

没有答案