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 http://www.wintoolzone.com/ListWin32.aspx?Listtype=5. 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
tcopy.SetCopyCallback(ProgressCallback);
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());
tcopy.Rollback();
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);
}
[Download] TransNTFS - Managed implementation of Transactional NTFS (TxF) APIs « CPFH… said
[…] Blocked 0 spam comments blocked byAkismet « Programming the Transactional NTFS (TxF) Lessons in Exception Handling […]