Note that there are some explanatory texts on larger screens.

plurals
  1. POOpening a file handle with a specific block size
    primarykey
    data
    text
    <p>I am trying to write some data to a tape drive - I am using a class found here: <a href="http://www.codeproject.com/Articles/15487/Magnetic-Tape-Data-Storage-Part-1-Tape-Drive-IO-Co" rel="nofollow">http://www.codeproject.com/Articles/15487/Magnetic-Tape-Data-Storage-Part-1-Tape-Drive-IO-Co</a></p> <p>I can load the tape drive using the "Load" method fine, although when I attempt to write to the tape I get the following error:</p> <blockquote> <p>IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations.</p> </blockquote> <p>I believe this problem is due to the file handle using an incorrect block size. I know the block size for the device is: 32768 - although how can I open a file handle using this block size?</p> <pre><code>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)) &gt; 0) { ms.Write(buffer, 0, read); } return ms.ToArray(); } } </code></pre> <p>The Write method in the class I am using is below:</p> <pre><code> /// &lt;summary&gt; /// Writes to the tape given stream starting from given postion /// &lt;/summary&gt; /// &lt;param name="startPos"&gt;&lt;/param&gt; /// &lt;param name="stream"&gt;&lt;/param&gt; 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(); } </code></pre> <p>Thanks</p> <ul> <li>David</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload