Discussion:
How Can I Get Exclusive Lock On Drive / Partition Win-Api 32 ?
(too old to reply)
lokesh mavale
2014-03-11 16:14:06 UTC
Permalink
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
2014-03-11 17:32:20 UTC
Permalink
Post by lokesh mavale
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
Post by lokesh mavale
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.
Post by lokesh mavale
i am not quite sure how lockfile() and lockfileex() works..!!
LockFile() and LockFileEx() operate on files, not drives or
volumes.
Uwe Sieber
2014-03-13 08:09:47 UTC
Permalink
Post by lokesh mavale
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 | :)
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

Loading...