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,
®s, sizeof(regs), ®s, 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.
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,
®s, sizeof(regs), ®s, 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.