Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Un)LockLogicalVolume fails

Status
Not open for further replies.

burgdavid

Programmer
Jun 22, 2000
70
DE
Hello,

I'm using the code from Microsoft MSDN at :


To lock volume of CD-Reader under windows 9x plateforms. But, with some CDs and some cd-drives, it fails (return FALSE. Either the locking or the unlocking code, on an external SCSI recorder with a regular iso9660 cd into) and I don't know why. By tracing into this :

/*-----------------------------------------------------------------------
LockLogicalVolume (hVWin32, bDriveNum, bLockLevel, wPermissions)

Purpose:
Takes a logical volume lock on a logical volume.

Parameters:
hVWin32
An open handle to VWIN32.

bDriveNum
The logical drive number to lock. 0 = default, 1 = A:, 2 = B:,
3 = C:, etc.

bLockLevel
Can be 0, 1, 2, or 3. Level 0 is an exclusive lock that can only
be taken when there are no open files on the specified drive.
Levels 1 through 3 form a hierarchy where 1 must be taken before
2, which must be taken before 3.

wPermissions
Specifies how the lock will affect file operations when lock levels
1 through 3 are taken. Also specifies whether a formatting lock
should be taken after a level 0 lock.

Zero is a valid permission.

Return Value:
If successful, returns TRUE. If unsuccessful, returns FALSE.
-----------------------------------------------------------------------*/
BOOL WINAPI LockLogicalVolume (HANDLE hVWin32,
BYTE bDriveNum,
BYTE bLockLevel,
WORD wPermissions)
{
BOOL fResult;
DIOC_REGISTERS regs = {0};
BYTE bDeviceCat; // can be either 0x48 or 0x08
DWORD cb;

/*
Try first with device category 0x48 for FAT32 volumes. If it
doesn't work, try again with device category 0x08. If that
doesn't work, then the lock failed.
*/

bDeviceCat = 0x48;

ATTEMPT_AGAIN:
// Set up the parameters for the call.
regs.reg_EAX = 0x440D;
regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
regs.reg_EDX = wPermissions;

fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
&regs, sizeof(regs), &regs, sizeof(regs),
&cb, 0);

// See if DeviceIoControl and the lock succeeded
fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);

// If DeviceIoControl or the lock failed, and device category 0x08
// hasn't been tried, retry the operation with device category 0x08.
if (!fResult && (bDeviceCat != 0x08))
{
bDeviceCat = 0x08;
goto ATTEMPT_AGAIN;
}

return fResult;
}

I see that DeviceIoControl succeed but the CARRY_FLAG is set. Then the code changes the bDeviceCat but it doesn't help and fails again. (wPermissions is 0)

I have no other application running beside my program and visual studio... Does someone know about theses DeviceIoControl or have link/code/example for volume locking under windows 9x ?

Best regards,

David Burg.
 
(By the way, I'm testing this under windows 98 SE.)
 
With GetLastError and FormatMessage / FORMAT_MESSAGE_FROM_SYSTEM, I have a "The parameter is incorrect" message. Same message when it is failing on unlock only. Any clue ?
 
Even worst : if I launch a copy of a big file from the CD in the windows explorer and then lock with this code, the lock succeed and I got a blue screen "The CD xyz is not accessible, gna gna gna.". But I check the IOCTL code on MSDN online and it should be correct for windows 95, 98 and Me. So what such failures ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top