BTW, see also http://msdn.microsoft.com/
Main Topics
Browse All TopicsI am trying to perform some pass-through SCSI programming on my Windows-based Tape susbystem. I want to open the tape in read-only mode so I can issue some CDBs to it. Everything works fine unless the tape drive is running the microsoft backup program.
(Note, I have never had similar problems doing this under other operating systems, and I am performing pass-through SCSI commands that read log & mode pages. I am not trying to read media. I know that the same tape drive has no problems doing this properly under other operating systems)
Here is my stripped down code
if (ReadWriteOpenRequired)
handle = CreateFile("\\\\.\\TAPE0",
else
handle = CreateFile("\\\\.\\TAPE0",
The problem is that handle returns a -1.
I am running everything As administrator, and the code works fine if the tape is not busy.
I know that there is a function, GetTapeStatus() that can tell me if the tape is somehow locked in exclusive mode, but that function also needs to invoke CreateFile. Am I missing something? I am using VS2008.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
BTW, see also http://msdn.microsoft.com/
GetLastError returns 20h, ERROR_SHARING_VIOLATION
jkr: I tried your suggestion, handle = CreateFile(DriverDev,GENER
got same error (when tape was streaming, of course. Never a problem when the windows backup isn't running. I can't imagine that MSFT created a situation where exclusive access is prevented for pass-through, this would break the O/S, and defeat the purpose of running something like GetTapeStatus to see if the tape is busy in the first place!
If another application has opened the tape drive, and has locked access to it, then I'd expect the OS to refuse your request to open it, particularly if you've set the GENERIC_WRITE flag. What happens if you just open it using GENERIC_READ?
If it still fails to open you may be able to access the drive by talking to the controller, and getting it to pass your SCSI requests through to the drive.
Not that I've ever tried it ;-)
PS, I don't think GetTapeStatus will return lock status... according to my documentation, the only statii it will return are:
ERROR_BEGINNING_OF_MEDIA
ERROR_BUS_RESET
ERROR_END_OF_MEDIA
ERROR_FILEMARK_DETECTED
ERROR_SETMARK_DETECTED
ERROR_NO_DATA_DETECTED
ERROR_PARTITION_FAILURE
ERROR_INVALID_BLOCK_LENGTH
ERROR_DEVICE_NOT_PARTITION
ERROR_MEDIA_CHANGED
ERROR_NO_MEDIA_IN_DRIVE
ERROR_NOT_SUPPORTED
ERROR_UNABLE_TO_LOCK_MEDIA
ERROR_UNABLE_TO_UNLOAD_MED
ERROR_WRITE_PROTECT
Can you try ProcessExplorer (http://technet.microsoft.
Hi TapeDude, My original logic was CreateFile("\\\\.\\TAPE0",
I've pretty much tried every combination trying GENERIC_READ|GENERIC_WRITE
I am doing everything as administrator, and verified that I am logged into administrator. I used sysinternals' process monitor and confirmed ntbackup is using \device\tape0, and looked at permissions, just to see if anything weird added.
GetTapeStatus won't work anyway because it is useless unless you can get a handle via the CreateFile.
Even if I did know how to talk to controller directly it would be vendor/product specific, so can't go down that path. Perhaps there is a mechanism to use an alias for \\.\TAPE0 ? Is the O/S incapable of opening a tape drive that is using NTBACKUP for pass-through?
This is why I used to use the ASPI layer! You could do whatever you liked to a drive, independent of the OS. But Adaptec stopped supporting ASPI after XP.
The only thing I can think of is to run a process at boot time that opens a handle to the drive and then just sits in memory, fielding your requests to/from the drive. But if NTBackup tries to lock the drive, it may fall over if Windows refuses to lock it; and if Windows DOES allow NTBackup to lock the drive, your process may not be able to access the drive.
You could try writing a dirty little command-line program that opens a handle to the drive, and then sits awaiting keyboard input. Meanwhile, run NTBackup and see what happens. If NTBackup runs, then try getting your command-line program to do a GetTapeStatus.
"Sorry, it's not a good idea to access a device that is in use by any means"
True. Particularly to read or write! But assuming dlethe knows the dangers and is not actually setting tape modes or requesting/writing blocks, it shouldn't be a problem.
Be a good idea to ensure the "verify" setting is on in NTBackup though :-)
Respectfully, I've been writing storage diagnostics since the 90s, and know exactly what is safe. What I am doing is safe.
I am sending SCSI inquires, LOG SENSE & MODE SENSE. These are entirely safe. The code works on a dozen other operating systems as well, just got the one stupid problem with windows locking me out on a tape while NTBACKUP is accessing it. But I do want to say that I appreciate your comments. If I was the expert in this particular case, I would have posted the same response as you :)
The technique works just fine, BTW, on \\.\PHYSICALDISK, SES/SAFTE enclosures, CDROMS/DVDs, and even certain RAID controllers. Just have the issue with windows tape drives & ntbackup.
Sorry, don't have meeting of minds on if i open the tape handler first and keep it open, then run ntbackup ...
If I attempt this ,then NTBackup says "There is no free media available with the selected type. Ad unused media or click cancel to end the operation". Note: It may take up to 60 seconds to recognize new media".
So NTBACKUP also has a problem, but the message it returns is misleading.
The windows event log recorded RSM cannot manage library Tape0. Failed to communicate with device or obtain device setup information. The Event ID is 168. Category None, Type: Error. / Remote Storage Manager.
After googlin' RSM error 168, I found a promising link to "Qlogic Support Solution 12362". This is what the qlogic site said:
==========================
Tape backups are failing in Windows when the Removable Service Manager (RSM) is enabled. The server may be receiving Event ID: 168 errors.
Cause
This event occurs because Removable Storage Management (RSM) and some backup software applications are both trying to control the management of the robotic library.
Action
To correct this issue, disable the Removable Storage service, as described in the following paragraphs.
1. Enter Computer Management by right-clicking My Computer and selecting Manage.
2. Expand Services and Applications, then highlight Services.
3. Right-click on the Removable Storage Service and click Stop.
4. Double-click Removable Storage, and set the Startup type to Disabled. Click OK.
5. Exit Computer Management.
=====
My system had it as Manual.
Rebooting system now & will let you know after experimenting...
It's looking like passing SRBs via the controller is the only way you're going to get this done.
It may not be as device/oem specific as you fear - check out http://karuppuswamy.com/wo
I will reluctantly have to go with passing SRBs, but was hoping there was a more elegant solution that would have let the standard device-level pass-through to work. For what it is worth, I'll probably log a support incident to MSFT to see if there is a simpler way, but TapeDude did provide a technique that will certainly do the job.
THanks - If I figure out an easier method, I will revisit this and let you know.
Business Accounts
Answer for Membership
by: jkrPosted on 2009-11-03 at 10:27:52ID: 25731879
What does 'GetLastError()' report after 'CreateFile()' fails?