In this experiment we’ll use the Transactdemo.exe tool to create a new file, add some data to it as part of a transaction, and see how nontransacted clients interact with the file while the transaction is active. First, open a Command Prompt window and run Transactdemo.exe:C:\>Transactdemo.exe Transaction Demo v1.0 by Mark Russinovich Transaction created: {5CD5E900-9DA8-11DD-8379-005056C00008} Created C:\TransactionDemo.txt. Pass TransDemo the GUID listed above to see the transacted file. Rollback or commit transaction? (r/c):
Transactdemo creates C:\TransactionDemo.txt within a transaction that it has not committed. Open a second Command Prompt window, and use the
According to this second command prompt, the file doesn’t even exist. Now simulate a nontransacted writer by trying to add data to the file via the
As expected, nontransacted writers are blocked from modifying the file.
The %SystemRoot%\System32\Ktmutil.exe and %SystemRoot%\System32\Fsutil.exe built-in applications can be very useful for dealing with transactional operations on the file system. For example, you can get a list of all current transactions on the system with the following command:C:\>ktmutil tx list TxGuid Description -------------------------------------- ----------------------------------------------- {5cd5e900-9da8-11dd-8379-005056c00008} Demo Transaction?
Note that the GUID matches what Transactdemo returned. With the GUID, you can now use the Fsutil command to query information about the transaction and to commit it or roll it back. For example, here’s how to list the files part of the transaction and the owner account:C:\>fsutil transaction query all {5cd5e900-9da8-11dd-8379-005056c00008} dwOutcome: 1 dwIsolationLevel: 0 dwIsolationFlags: 0 dwTimeout: -1 Owner: BUILTIN\Administrators Number of Files: 1 ---- \TransactionDemo.txt
Although the Transactdemo tool presents you with the option to roll back or commit the current transaction, the Fsutil utility allows commits or rollbacks to any ongoing transaction your account has access to. Go back to the command prompt where you ran Transactdemo and press C to commit the transaction, after which the file becomes a standard nontransacted file.
Transactional APIs
TxF implements transacted versions of the Windows file I/O APIs, which use the suffix
Create APIs
Find APIs
Query APIs
Delete APIs
Copy and Move/Rename APIs
Set APIs
In addition, some APIs automatically participate in transacted operations when the file handle they are passed is part of a transaction, like one created by the
API Name
Change
Transactions will not be committed until all applications close transacted handles to the file.
Modifications to mapped views of a file part of a transaction will be associated with the transaction themselves.
If the file handle is part of a transaction, read-isolation rules will be applied to these operations.
Function will return FILE_SUPPORTS_TRANSACTIONS if the volume supports TxF.
Read and write operations to a transacted file handle will be part of the transaction.