Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unlocking a Volume with FSCTL_UNLOCK_VOLUME

537 views
Skip to first unread message

Sashi Asokarajan

unread,
Apr 20, 2001, 9:35:32 AM4/20/01
to
Hello there,

I'm trying to unlock a MO-Drive with DeviceIOControl & FSCTL_UNLOCK_VOLUME.
But I always get an error.
GetLastError() says 6 = The handle is invalid (ERROR_INVALID_HANDLE) !

I'm getting the handle with the CreateFile() funciton like this:
h=CreateFile(argv[1],0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0
,NULL);

I tried these values for argv[1]:
\\.\F:
\\\\.\\F:
\\.\\PhysicalDrive0
\\.\PHYSICALDRIVE0
\\\\.\\PhysicalDrive0
and so on.... :(

The Example
(http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/fil
esio_7wmd.htm) from the Microsoft-Site runs good, but mine isn't :( !
Why is the volumename described on the MSDN-Site (
lpFileName=\\.\PHYSICALDRIVEn) is other than in the Example
above(lpFileName=\\\\.\\PhysicalDrive0) ?

I also tried to lock the drive with FSCTL_LOCK_VOLUME before unlocking, but
that fails with the same errorcode!
Why do I always get an error ? Can somebody PLEASE help me ????

Thank you.

Bye,
Sashi


Jarmo Muukka

unread,
Apr 20, 2001, 12:42:42 PM4/20/01
to
The volume name is "\\.\F:". When you write it in C/C++, you have to prepend
every \ with \ because \ is a control character. e.g.
reateFile( "\\\\.\\F:", ... ). When entering it from command line, it's just
\\.\F:

Does CreateFile succeed? What is the value of h? If it's
INVALID_HANDLE_VALUE, it failed. Then check error code. You may have to open
volume with GENERIC_READ and GENERIC_WRITE access.

--
JMu

"Sashi Asokarajan" <sa...@gmx.de> wrote in message
news:987773692.328094@sisapint06...

Sashi Asokarajan

unread,
Apr 23, 2001, 3:18:10 AM4/23/01
to
Hello Jarmo,

first of all, thank you for your reply!
the value of h is !INVALID_HANDLE_VALUE. createfile succeeds!
But all my calls to the deviceioctrol fails with the invalid handle error !

this is my code:
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
int main(int argc, char *argv[])
{
HANDLE h;
BOOL b;
DWORD dw=0;
OVERLAPPED ov;
printf("Opening %s...\n",argv[1]);

h=CreateFile(argv[1],0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0
,NULL);

b=DeviceIoControl(h,FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0,&dw,&ov);
if (b)
printf("UNLOCKED!");
else
{
printf("DeviceIoControl(FSCTL_UNLOCK_VOLUME) ERROR: %d",GetLastError());
CloseHandle(h);
return 1;
}
CloseHandle(h);
return 0;
}

Jarmo Muukka

unread,
Apr 24, 2001, 4:30:19 PM4/24/01
to
Thanks for showing the code, because it tells me where the problem is. The
last parameter of DeviceIoControl is an OVERLAPPED structure. Since you
haven't CreateFile with overlapped and haven't CreateEvent for overlapped
operation, you don't need it. Just replace &ov with 0 and you can go on.

--
JMu

"Sashi Asokarajan" <sa...@gmx.de> wrote in message

news:988010315.654197@sisapint06...

Sashi Asokarajan

unread,
Apr 25, 2001, 3:53:28 AM4/25/01
to
Hi Jarmo,

first of all thank you very much for your support!
I tried to replace &ov with 0 then (OVERLAPPED)NULL, NULL and
I always get the Errorcode:87 (ERROR_INVALID_PARAMETER) !

Do you have any idea ?

Thanks again for your support!

Bye,
Sashi


Joe Hagen

unread,
Apr 26, 2001, 12:22:08 PM4/26/01
to
Sashi,

Try calling CreateFile with an access of at least
GENERIC_READ (instead of 0) or use
GENERIC_READ|GENERIC_WRITE
access.
.

Joe


Sashi Asokarajan

unread,
Apr 27, 2001, 4:29:51 AM4/27/01
to
Hi Joe,

> Try calling CreateFile with an access of at least
> GENERIC_READ (instead of 0) or use
> GENERIC_READ|GENERIC_WRITE

that also fails!

bye


0 new messages