About win7 background defragmentation

Hi guys. I have several files which should not be defragmented by windows. I
simply deny all IRP_MJ_CREATE to these files because AFAIK file must be
opened before it is defragmented, but sometimes their sector position on
disk still changes in Win7.

Can this be caused by win7 background defragmentation? How can I prevent
windows and other programs from moving my files?

Regards

Haibo

Re: [ntfsd] About win7 background defragmentation

Hi, im not sure we use almost right solution, we also returning ACCESS_DENIED on all MJ_CREATE IRPs pointed to our file as soon as our driver loaded, 

but when system runs our thread in lsass.exe (that is existing all the time while system working) we (from userspace) temprory unlock our-special-defrag-protected file, opening it and sending to it DeviceIoControl FSCTL_MARK_HANDLE with MARK_HANDLE_PROTECT_CLUSTERS option.

               MarkInfo.UsnSourceInfo = USN_SOURCE_AUXILIARY_DATA;

               MarkInfo.VolumeHandle = hVolume;

               MarkInfo.HandleInfo = MARK_HANDLE_PROTECT_CLUSTERS;

               

               rez = DeviceIoControl(hFile,FSCTL_MARK_HANDLE,&MarkInfo,sizeof(MarkInfo),0,0,&dwRet,0);


http://msdn.microsoft.com/en-us/library/aa364576(VS.85).aspx

So “The file is marked as undefragmentable until the handle is closed.”, and of cource we forget to close this handle and someway forget about it. (Our process is lsass, so cleanup of unclosed handles never happens while working), and after that we continue blocking all IRPs at driver level.

Im not sure its the perfect solution, but for us it`s working and at least for half year testing no problems with moving our file happen.

               

               

|

|

Hi guys. I have several files which should not be defragmented by windows. I simply deny all IRP_MJ_CREATE to these files because AFAIK file must be opened before it is defragmented, but sometimes their sector position on disk still changes in Win7. 

Can this be caused by win7 background defragmentation? How can I prevent windows and other programs from moving my files?

 

Regards

Haibo

 

— 

NTFSD is sponsored by OSR 

For our schedule of debugging and file system seminars 

(including our new fs mini-filter seminar) visit: 

http://www.osr.com/seminars 

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer 

|

Since you can hang around and deny creates, I suggest you use a less-lethal weapon. Check out MSDN for MARK_HANDLE_PROTECT_CLUSTERS.

How can I prevent Windows and other programs from moving my files during defragmentation in Windows 7? Please let me know, I know this is an old discussion but the answer to my question is very important I am appealing to the admin. Please approve my post, Thanks

The answer is already there: MARK_HANDLE_PROTECT_CLUSTERS. If you have a specific question or problem open a new thread.