Inside and Out…

An attempt to understand technology better…

Programming the Transactional NTFS (TxF)

Posted by Gaurav Khanna on March 1, 2007

One of the key new features of Windows Vista is a component called the Kernel Transaction Manager (KTM) that brings inherent support for transactional development in not just the kernel-mode but also for user mode. Infact, NTFS has been enhanced to use and support transactions such that couple of new APIs (e.g. CopyFileTransacted, MoveFileTransacted just to name a few) have surfaced up. You can get more details on Transactional NTFS here.

To demonstrate the power of the new APIs, I wrote a C++ class library (unmanaged), CTransCopy, that allows you to:

  • Copy files under a transaction
  • Move files under a transaction
  • Commit or Rollback the transaction
  • Let you wire up a callback handler for copy/move progress

You can download it from The zipped archive also contains a sample client source code. BTW, since the .LIB file containing the class was compiled using VC++ 2005 compiler, you will need the same to link against it and write an application. You can use VC++ 2005 Express Edition. Below is an example usage of the same:

CTransCopy tcopy;

if (tcopy.IsOSSupported() == FALSE)
printf(“This application requires Windows Vista or later.”);
return -1;

if (tcopy.Init() == FALSE)
printf(“Init failed with error %08X\n”,tcopy.LastError());
return -1;

// Setup a callback for progress

if (tcopy.CopyFileW(L”D:\\KGK\\Development\\VS\\Windows Vista\\VC\\TransCopy\\debug\\transcopy.pdb”,
L”D:\\transcopy.pdb”,FALSE) == FALSE)
printf(“Copy/move failed with error %08X\n”,tcopy.LastError());
return -1;

if (tcopy.Rollback() == FALSE)
printf(“Rollback failed with error %08X\n”,tcopy.LastError());
return -1;

if (tcopy.Commit() == FALSE)
printf(“Commit failed with error %08X\n”,tcopy.LastError());
return -1;

printf(“Copy/move successful!\n”);

The ProgressCallback function is implemented as shown below:

void ProgressCallback(LARGE_INTEGER total, LARGE_INTEGER transferred)
double percent = (transferred.QuadPart*100.00)/total.QuadPart;
printf(“%f%% over\n”,percent);


One Response to “Programming the Transactional NTFS (TxF)”

  1. […] Blocked 0 spam comments blocked byAkismet « Programming the Transactional NTFS (TxF) Lessons in Exception Handling […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: