|
hi dear dima
i use GetTapeMediaParameters to get appropriate blockSize
and my result was (MediaInfo) :
******************************BlockSize = 0
******************************Capacity = 1499999502336
******************************IsWriteProtected = 0
******************************PartitionCount = 0
******************************Remaining = 1499992162304
and i have problem in read and write
where is my problem?
what is appropriate value for blockSize?
what correct SetTapeParameters Win32 API syntax in c#?
please help me my friend
modified 20-May-12 9:28am.
|
|
|
|
|
hi dima
what get block size on media? help me please.
i didnt use read and write method
i need to read and write and exchange methods
please help me
thank you
|
|
|
|
|
I was able to fix the exception when trying to read from the tape drive by adding another call to GetTapeParameters. On the second call, use the MEDIA_PARAMS argument. This seems to initialize the drive. The appearance in device manager will also change after this has been run.
|
|
|
|
|
I get following error when trying to read ( Read(startPosition); where startPosition = 1)
Handle does not support synchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened asynchronously (that is, it was opened explicitly for overlapped I/O)
|
|
|
|
|
Nice code, thanx a lot! I'm new to tape recording... i'm still trying to figure out how to position the tape for reading/writing. Does using this code necessarily imply on using Microsoft Tape Format protocol? I've been reading MTF specification document, but i'm still kinda confused with the whole filemark, PBA and FLA thing. Do you know any better literature regarding this issue?
[]s
Rafael
|
|
|
|
|
Do I need to format a blank tape before I write to it?
If yes, how to do it? Thanks!
|
|
|
|
|
Basically, you can use SetTapeParameters call to configure the blank tape
http://msdn.microsoft.com/en-us/library/aa362534(VS.85).aspx
Also, you can use the tape without initializing it. Default values will be used.
Dima S
|
|
|
|
|
Can you show me how to use SetTapeParameters to set the blocksize to 65536?
|
|
|
|
|
Define C# signature(PINVOKE) of SetTapeParameters and SET_TAPE_MEDIA_INFORMATION and
SET_TAPE_MEDIA_INFORMATION mediaInfo = new SET_TAPE_MEDIA_INFORMATION();
// SETTING BLOCK SIZE
mediaInfo.BlockSize = (uint)blockSize;
int size = Marshal.SizeOf(mediaInfo);
ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(
mediaInfo,
ptr,
false
);
SetTapeParameters(
TapeHandle,
Tape.SET_TAPE_MEDIA_INFORMATION,
ptr));
Dima S
|
|
|
|
|
Thank you for your code, it really helpful.
However, when I try to read a very large file (~80GB), the speed is very slow. Is there any way to fixed it? Thanks in advance.
|
|
|
|
|
To increase the Read speed, do as follows
1) Increase the Block Size to maximum(read specs of your device)
2) Decrease number of seek operations, I mean try to read all data at once.
Reagrds.
Dima S
|
|
|
|
|
Hi,
Has anyone managed to fix the issue that causes the error "IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations." when calling m_stream.flush() in the Write function?
public void Write(long startPos, byte[] stream)
{
uint numberOfBlocks = GetBlocksNumber(stream.Length);
SetTapePosition(startPos);
byte[] arrayToWrite = new byte[numberOfBlocks * BlockSize];
Array.Copy(stream, arrayToWrite, stream.Length);
m_stream.Write(arrayToWrite, 0, arrayToWrite.Length);
m_stream.Flush();
}
PS, I'm compiling with C# 4 in VS 2010...
Cheers,
Blakey
|
|
|
|
|
Hi Blakey,
Seems that you are using wrong BlockSize.
Check BlockSize on the Tape and BlockSize that defined in you code.
Ensure that these values are equal.
Regards,
Dima.
Dima S
|
|
|
|
|
Hi Have you got any luck of this issue..
I am facing the same issue and didn't get any proper response..
any help would be apricated
thanks in advance..
|
|
|
|
|
In the article, it is stated that the write operations to tape have to be in done in multiples of blocksize. However the code in the article contains:
byte[] arrayToWrite = new byte[ numberOfBlocks * BlockSize ];<br />
Array.Copy( stream, arrayToWrite, stream.Length );<br />
<br />
m_stream.Write( stream, 0, stream.Length );<br />
m_stream.Flush();
After the arrayToWrite array is correctly created and filled with the original contents of stream, arrayToWrite is not used.
Shouldn't the code be:
byte[] arrayToWrite = new byte[ numberOfBlocks * BlockSize ];<br />
Array.Copy( stream, arrayToWrite, stream.Length );<br />
<br />
m_stream.Write( arrayToWrite, 0, arrayToWrite.Length );<br />
m_stream.Flush();
The .zip file attached to the article contains the same thing.
Oz
|
|
|
|
|
Thanks Oz,
you are perfectly right.
Dima S
|
|
|
|
|
Hi..
I am presently trying to "Read/write into tape drive".
prsently i am using HP LTO Ultrium 2 drive.
In my System,tape symbolic name is same as specified "Tape0".
but i am unable to load tape using the Tape load(string tapename) function.
I havent found "using Bsw.Types.Logger;" dll to add into the program.
where can i get the dll and how can i access the tape and how can i implement it.
a small support is also a great help for me
|
|
|
|
|
Is there a way to find out the bar code of the tape?
|
|
|
|
|
Hi Venu Tam.
Yes, there is a way to read the barcode.
You can do as follows
if (false == Changer.DeviceIoControl(
ChangerHandle, // handle to device
(uint)Changer.IOCTL_CHANGER_GET_ELEMENT_STATUS, // dwIoControlCode
ptrIn, // lpInBuffer
(uint)Marshal.SizeOf(readStatusIn), // nInBufferSize
ptrOut, // output buffer
(uint)Marshal.SizeOf(driveStatus), // size of output buffer
out readBytes, // number of bytes returned
IntPtr.Zero // OVERLAPPED structure
))
The ptrOut is pointer on CHANGER_ELEMENT_STATUS_EX
(see- http://msdn.microsoft.com/en-us/library/aa363163(v=VS.85).aspx)
it contains the media barcode (Of course barcode reader should be installed on your device)
Regards,
Dima.
Dima S
|
|
|
|
|
Hi Dima,
just came across this nice piece of code some days ago. Thanks for sharing!
At the present moment I am struggeling with "m_stream.Read( buffer, 0, buffer.Length );" which gives me the "Handle does not support synchronous operations" message and " m_stream.Flush();" in method "Write", which pops up the "IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations."-message.
Load method seems to work perfect, as all handels are created propperly.
Hope my problems do not come from my XP 64Bit installation?
Any help on this is highly appreciated.
Regards
Stocki
|
|
|
|
|
Hi Stocki,
check block size on media and block size that you are trying to read.
Regards, Dima.
Dima S
|
|
|
|
|
This code looks very useful but I'm having trouble.
I can open my device and return the blocksize (32768).
I then tried the "read" method picking a random block number of 450, but I get the error "When accessing a new tape of a multivolume partition, the current block size is incorrect".
I saw in the code that the load method seems to try one of 65535 so I changed that to match mine and still get the same (I guess it's not that as the read method seems to call the same as get default block size to work it out...)
Any ideas? In Device Manager both the tape drive blocksize and the media blocksize are both 32768.
--code:
TapeOperator _tape = new TapeOperator();
private void button1_Click(object sender, EventArgs e)
{
_tape.Load(textBox1.Text);
MessageBox.Show("Tape default blocksize is " + _tape.BlockSize.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
byte[] tapeData = _tape.Read(450);
textBox2.Text = ByteArrayToString(tapeData);
_tape.Close();
}
|
|
|
|
|
Try to set the block size programmatically before you are using the device
Dima S
|
|
|
|
|
Hello,
We have a few tape programming projects, I was wondering if you'd be interested in a contracting position? Please contact me dustin@vioplex.com
|
|
|
|
|
Hi, thank you for your useful article.
I want to ask you if this software can make write/read operations also to USB TAPE DEVICES, like HP StorageWorks DAT 40 USB, not only on standard SCSI tape.
|
|
|
|