Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTFSD

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


About win7 background defragmentation

HaiboHaibo Member Posts: 188
edited October 14 in NTFSD
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
Post edited by Scott_Noone_(OSR) on

Comments

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    Re: [ntfsd] About win7 background defragmentation




    Hi, i`m not sure we use almost right solution, we also returning ACCESS_DENIED on all MJ_CREATE IRP`s 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.


    I`m not sure it`s 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 



  • Sergei_VorobievSergei_Vorobiev Member Posts: 44
    Since you can hang around and deny creates, I suggest you use a less-lethal weapon. Check out MSDN for MARK_HANDLE_PROTECT_CLUSTERS.
  • koko02koko02 Member Posts: 1

    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

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,650

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

    -scott
    OSR

This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online