1

我正在尝试将一些数据写入磁带驱动器 - 我正在使用在这里找到的一个类:http: //www.codeproject.com/Articles/15487/Magnetic-Tape-Data-Storage-Part-1-Tape-Drive- IO-Co

我可以很好地使用“加载”方法加载磁带驱动器,尽管当我尝试写入磁带时出现以下错误:

IO 操作将不起作用。文件很可能会变得太长或句柄未打开以支持同步 IO 操作。

我相信这个问题是由于文件句柄使用了不正确的块大小。我知道设备的块大小是:32768 - 虽然我怎样才能使用这个块大小打开文件句柄?

TapeOperator TapeOperatorObject = new TapeOperator();

// Load tape 1
TapeOperatorObject.Load(@"\\.\Tape1");

// Write to tape drive
Console.WriteLine("Writing");
FileStream inputFile = new FileStream("test.txt", FileMode.Open);
TapeOperatorObject.Write(0, ReadFully(inputFile));

   public static byte[] ReadFully(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

我正在使用的类中的 Write 方法如下:

  /// <summary>
        /// Writes to the tape given stream starting from given postion
        /// </summary>
        /// <param name="startPos"></param>
        /// <param name="stream"></param>
        public void Write( long startPos, byte[] stream )
        {
            // Get number of blocks that will be nned to perform write
            uint numberOfBlocks = GetBlocksNumber( stream.Length );

            // Updates tape's current position
            SetTapePosition( startPos );

            byte[] arrayToWrite = new byte[ numberOfBlocks * BlockSize ];
            Array.Copy( stream, arrayToWrite, stream.Length );

            // Write data to the device
            m_stream.Write( stream, 0, stream.Length );
            m_stream.Flush();
        }

谢谢

  • 大卫
4

0 回答 0