|
How to get the used and free space available in a tape media through code.
|
|
|
|
|
I need to know how to load tape from slot to drive in windows through code (cpp or powershell code). I have a VTL setup which has a single library containg 5 tape drives. I created 10 slots in that library through the VTL. I am trying to find how to load tape from that slot to drive in windows. Thanks in Advance
I am using Cristalink's firestreamer to create VTL
I am not sure how a physical tape would look like. In case if a library has 5 drives and 10 slots of media. How to identify each media and how to load and unload each media in to a particular drive.
|
|
|
|
|
"Handle does not support synchronous operations" is fixed by initializing the tape drive.
Setting a tape media parameter block size to "0" after Tape Load accomplished it.
=======================================================================
var mediaInfo = new MediaInfo {BlockSize = 0};
IntPtr paramPtr =
Marshal.AllocCoTaskMem(Marshal.SizeOf(mediaInfo));
Marshal.StructureToPtr(mediaInfo, paramPtr, false);
SetTapeParameters(
m_handleValue,
0, // tape media 0, tape drive 1
paramPtr);
[DllImport("kernel32",
CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int SetTapeParameters(
SafeFileHandle handle,
int operationType,
IntPtr mediaInfo
);
[StructLayout(LayoutKind.Sequential)]
public struct MediaInfo
{
public long Capacity;
public long Remaining;
public uint BlockSize;
public uint PartitionCount;
public byte IsWriteProtected;
}
|
|
|
|
|
hi,I try the Designated position read data or write date in tape,find SetTapePosition function carry out error. errorCode 1104,why?
for example:
I set tape BlockSize is 1MB,from 1000 position began to implement.
SetTapePosition(m_handleValue, TAPE_LOGICAL_BLOCK, 0, 1000, 0, TRUE)
|
|
|
|
|
hi,I try the Designated position read data or write date in tape,find SetTapePosition function carry out error. errorCode 1104,why?
for example:
I set tape BlockSize is 1MB,from 1000 position began to implement.
SetTapePosition(m_handleValue, TAPE_LOGICAL_BLOCK, 0, 1000, 0, TRUE)
|
|
|
|
|
hi dima
The title is mu problem,Have more data can be read.
byte[] buffer = new byte[BlockSize];
SetTapePosition(startPosition);
m_stream.Read(buffer, 0, buffer.Length);
m_stream.Flush();
return buffer;
my default block size is 128kb,Afferent file length7243812
|
|
|
|
|
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
|
|
|
|