Movefile and DeleteFile Win32 APIs

Hi,

As part of crash testing my application, I remove the power cable of my box as soon as my application finishes. I know this because the application is a console app which runs on the cmd shell. Among, the last few APIs called by my application are MoveFile() and DeleteFile() on 2 different files. After the system comes back up I noticed that neither the file got deleted nor renamed. I was referred to ‘Windows Internals 5th edition’ came to know that NTFS maintains a journal and records meta data updates so that it can maintain consistency.

Here is what I got, please correct me if I am wrong.

  1. NTFS logs the change in the journal
  2. NTFS updates the actual volume meta data to reflect rename/delete/etc.
  3. flush the journal to disk
  4. flush the actual volume changes (meta data)

My question is when does the API Movefile() or DeleteFile() return to the caller program. Is it after step2, step3 or step4 above. I was wondering if the Movefile() effect on the metadata succeeded in the event of this crash or not, considering that the machine crashed immediately after my app finished execution.
I am running this test on a windows 2k8 server machine.

Thanks
-Himanshu

Forget NTFS journal and stuff, DeleteFile simply marks the file for deletion
and returns to the caller. There is no guarantee that the file will actually
be deleted eventually. One could simply invert the disposition flag to avoid
deleting a file that has already been marked for deletion ; not to talk
about abrupt system restart.

Regards,
Ayush Gupta
AI Consulting

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-409425-
xxxxx@lists.osr.com] On Behalf Of Himanshu Ashwani
Sent: Monday, April 26, 2010 6:22 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Movefile and DeleteFile Win32 APIs

Hi,

As part of crash testing my application, I remove the power cable of my
box as soon as my application finishes. I know this because the
application is a console app which runs on the cmd shell. Among, the
last few APIs called by my application are MoveFile() and DeleteFile()
on 2 different files. After the system comes back up I noticed that
neither the file got deleted nor renamed. I was referred to ‘Windows
Internals 5th edition’ came to know that NTFS maintains a journal and
records meta data updates so that it can maintain consistency.

Here is what I got, please correct me if I am wrong.

  1. NTFS logs the change in the journal
  2. NTFS updates the actual volume meta data to reflect
    rename/delete/etc.
  3. flush the journal to disk
  4. flush the actual volume changes (meta data)

My question is when does the API Movefile() or DeleteFile() return to
the caller program. Is it after step2, step3 or step4 above. I was
wondering if the Movefile() effect on the metadata succeeded in the
event of this crash or not, considering that the machine crashed
immediately after my app finished execution.
I am running this test on a windows 2k8 server machine.

Thanks
-Himanshu


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

Ayush,

Thanks for your reply. Does something similar hold true for rename (MoveFile) as well. I notice that if I wait 4-5 seconds after my exe finishes and then if I pull the plug everything is fine when I see after the system reboots. However, if I pull immediately after the exe finishes, I do not see the effect of delete and rename APIs.

Thanks
-Himanshu

----- Original Message ----
From: Ayush Gupta
To: Windows File Systems Devs Interest List
Sent: Wed, April 28, 2010 5:43:39 AM
Subject: RE: [ntfsd] Movefile and DeleteFile Win32 APIs

Forget NTFS journal and stuff, DeleteFile simply marks the file for deletion
and returns to the caller. There is no guarantee that the file will actually
be deleted eventually. One could simply invert the disposition flag to avoid
deleting a file that has already been marked for deletion ; not to talk
about abrupt system restart.

Regards,
Ayush Gupta
AI Consulting

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-409425-
> xxxxx@lists.osr.com] On Behalf Of Himanshu Ashwani
> Sent: Monday, April 26, 2010 6:22 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Movefile and DeleteFile Win32 APIs
>
> Hi,
>
> As part of crash testing my application, I remove the power cable of my
> box as soon as my application finishes. I know this because the
> application is a console app which runs on the cmd shell. Among, the
> last few APIs called by my application are MoveFile() and DeleteFile()
> on 2 different files. After the system comes back up I noticed that
> neither the file got deleted nor renamed. I was referred to ‘Windows
> Internals 5th edition’ came to know that NTFS maintains a journal and
> records meta data updates so that it can maintain consistency.
>
> Here is what I got, please correct me if I am wrong.
> 1. NTFS logs the change in the journal
> 2. NTFS updates the actual volume meta data to reflect
> rename/delete/etc.
> 3. flush the journal to disk
> 4. flush the actual volume changes (meta data)
>
> My question is when does the API Movefile() or DeleteFile() return to
> the caller program. Is it after step2, step3 or step4 above. I was
> wondering if the Movefile() effect on the metadata succeeded in the
> event of this crash or not, considering that the machine crashed
> immediately after my app finished execution.
> I am running this test on a windows 2k8 server machine.
>
> Thanks
> -Himanshu
>
>
>
>
>
> —
> 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


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