How do I copy a locked file directly from the disk and make sure that the file is intact?
The application I am writing needs to be able to copy files that are locked. We attempted to use Volume Shadow Copy, and while it was successful in copying the file, the application that had the lock on the file crashed because it could not acquire a lock while we were copying the file.
I am left to believe that my only option is to bypass the OS and read directly from the disk. The problem is that if I read directly to the disk I cannot be sure of the integrity of the file, if it is in the m开发者_运维技巧iddle of a write the file will be in a damaged state.
After hours of searching I was able to find one utility that copied the file directly from the disk and used a file system driver to cache writes while copying so that it could make sure that the file was in an intact state. However, that utility is extraordinarily expensive, 100k+ for the license I would likely need to use.
Does anyone have any ideas on how to accomplish what I am trying to?
We are planning on restricting the system to NTFS volumes only.
I ended up using a C program called DirectCopy written by Napalm. It works rather well.
http://www.rohitab.com/discuss/topic/24252-ntfs-directcopy-method-from-napalm/
Can you grab the process ID of the application that has a lock on it and suspend its thread while you perform the copy? Something like this http://www.codeproject.com/KB/threads/pausep.aspx
This description of "layered drivers" might be useful. I know nothing about it though.
Also, if the file is locked then can you just 'watch' it and wait for it to be unlocked and then quickly copy it?
精彩评论