Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reproduce ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 error code from ReplaceFile

I am using the ReplaceFile Win32 function as part of an operation to get atomic behaviour.

Of the three special error codes for that function, I've been able to reproduce and recover (rollback) from two: ERROR_UNABLE_TO_MOVE_REPLACEMENT and ERROR_UNABLE_TO_REMOVE_REPLACED.

My questions relate to the third error code: ERROR_UNABLE_TO_MOVE_REPLACEMENT_2.

  1. Has anybody seen this error code returned? Under what conditions is it possible?
  2. Any ideas on how to repoduce this error so that I can test the path in my code that recovers from it?
  3. I gather from the documentation that to recover (rollback) from this error, I will need to rename the replaced file back to its original name, because ReplaceFile will have left it with the backup file name. Can anybody verify this is in fact the state that ReplaceFile leaves the files in?

Some more details in case it helps:

  • ReplaceFile is called with a non-NULL backup file name (in fact ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 cannot occur if a NULL backup name is given).
  • I also pass the REPLACEFILE_WRITE_THROUGH flag.
  • The files all exist on the same NTFS volume.
like image 727
Wesley Hill Avatar asked Nov 13 '22 20:11

Wesley Hill


1 Answers

ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 occurs when the attributes and secondary data streams have been attached to the replacement file, but the primary file itself cannot be replaced.

Your assumption about recovery is correct.

like image 96
Eric Brown Avatar answered Dec 24 '22 17:12

Eric Brown