Geeks With Blogs

WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Inside and Out... An attempt to understand technology better...

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);

Technorati : , , , , , , , , , : , , , , , , , , ,
Ice Rocket : , , , , , , , , ,

Posted on Thursday, March 1, 2007 11:37 PM Windows Vista , Tools/Applications , Downloads , Development | Back to top

Comments on this post: Programming the Transactional NTFS (TxF)

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Gaurav Khanna | Powered by: