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

How Can I Get Exclusive Lock On Drive / Partition Win-Api 32 ?

21 views
Skip to first unread message

lokesh mavale

unread,
Mar 11, 2014, 12:14:06 PM3/11/14
to
how to lock lock on specific drive till i perform some operation of drive.
when i have captured lock on drive .. no other process should able to write on that drive till i release lock on that drive..
.
.
i have found one api.. ie. DeviceIoControl()..
but.. i want access on drive my process only.. but above API 'MAY' block access of all the process!!
.
i am not quite sure how lockfile() and lockfileex() works..!!
plz suggest me some way / API/ LOgic to do this!!
thank you !! Smile | :)

Underactive Moth

unread,
Mar 11, 2014, 1:32:20 PM3/11/14
to
lokesh mavale <lokesh...@gmail.com> wrote:
> how to lock lock on specific drive till i perform some operation of drive.
> when i have captured lock on drive .. no other process should able to write on that drive till i release lock on that drive..

It seems to me that FSCTL_LOCK_VOLUME would be the thing to use:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364575.aspx

> i have found one api.. ie. DeviceIoControl()..
> but.. i want access on drive my process only.. but above API 'MAY' block access of all the process!!

That is the point of a lock. It prevents other processes from
accessing the resource.

> i am not quite sure how lockfile() and lockfileex() works..!!

LockFile() and LockFileEx() operate on files, not drives or
volumes.

Uwe Sieber

unread,
Mar 13, 2014, 4:09:47 AM3/13/14
to
The most reliable way is to determine the
volume's location on disk(s) by means of
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, then
"safely remove" the volume by means of
CM_Query_And_Remove_SubTree.
Then you can open the disk device(s) and
write at the volume's location without
hassle.
Afterwards perform a CM_Reenumerate_DevNode
on the root node to bring the volume back
to life.


Uwe
0 new messages