ChangeJournal Class
- Supported on windows5.1.2600
Provides access to the NTFS change journal (Update Sequence Number journal) for a volume. The change journal records information about file and directory changes on an NTFS volume.
[SupportedOSPlatform("windows5.1.2600")]
public sealed class ChangeJournal : IDisposable- Implements
Properties
| Name | Description |
|---|---|
| Data | Gets the current metadata about the change journal. |
| Entries | Gets a collection of all change journal entries. |
Data
ChangeJournal.csEntries
ChangeJournal.csGets a collection of all change journal entries.
public IEnumerable<ChangeJournalEntry> Entries { get; }Property value
Methods
| Name | Description |
|---|---|
| Create(long, long) | Creates a new change journal or modifies an existing one. |
| Create(ulong, ulong) | Creates a new change journal or modifies an existing one. |
| Delete() | Deletes the change journal and waits for the deletion to complete. |
| Delete(bool) | Deletes the change journal. |
| Dispose() | Releases all resources used by the current instance of the ChangeJournal class. |
| EnableTrackModifiedRanges(ulong, long) | Enables range tracking for the change journal. |
| GetEntries(ChangeReason, bool, TimeSpan) | Gets change journal entries with the specified filter criteria. |
| GetEntries(Usn, ChangeReason, bool, TimeSpan) | Gets change journal entries starting from a specific USN with the specified filter criteria. |
| GetEntry(SafeFileHandle) | Gets the change journal entry for a specific file or directory by handle. |
| GetEntry(string) | Gets the change journal entry for a specific file or directory by path. |
| Open(DriveInfo) | Opens the change journal for the specified drive. |
| Open(DriveInfo, bool) | Opens the change journal for the specified drive. |
| RefreshJournalData() | Refreshes the journal metadata by reading the current state from the change journal. |
Create overloads
Create(long, long)
ChangeJournal.csCreates a new change journal or modifies an existing one.
Parameters
maximumSizelong- The maximum size, in bytes, that the journal can use on the volume.
allocationDeltalong- The size, in bytes, by which the journal grows when needed.
Exceptions
ArgumentOutOfRangeException- Thrown when
maximumSizeorallocationDeltais negative.
Create(ulong, ulong)
ChangeJournal.csDelete overloads
Delete()
ChangeJournal.csDeletes the change journal and waits for the deletion to complete.
public void Delete()Exceptions
Win32Exception- Thrown when the operation fails.
Remarks
Deleting a change journal requires a scan of every file on the volume, so it can take a long time and continues across system restarts.
Delete(bool)
ChangeJournal.csDeletes the change journal.
Parameters
waitForCompletionbool- If
true, waits for the deletion to complete; otherwise, starts the deletion and returns immediately.
Exceptions
Win32Exception- Thrown when the operation fails.
Remarks
Deleting a change journal requires a scan of every file on the volume, so it can take a long time and continues across system restarts. While the deletion is in progress, any attempt to create, modify, delete, or query the change journal fails with ERROR_JOURNAL_DELETE_IN_PROGRESS.
Dispose()
ChangeJournal.csReleases all resources used by the current instance of the ChangeJournal class.
public void Dispose()EnableTrackModifiedRanges(ulong, long)
ChangeJournal.csEnables range tracking for the change journal.
Parameters
chunkSizeulong- The granularity of tracked ranges.
fileSizeThresholdlong- The file size threshold to start tracking ranges for files with equal or larger size.
Remarks
Range tracking is reflected by JournalData.Flags, JournalData.RangeTrackChunkSize and JournalData.RangeTrackFileSizeThreshold on ChangeJournal.Data.
GetEntries overloads
GetEntries(ChangeReason, bool, TimeSpan)
ChangeJournal.csGets change journal entries with the specified filter criteria.
public IEnumerable<ChangeJournalEntry> GetEntries(ChangeReason reasonFilter, bool returnOnlyOnClose, TimeSpan timeout)Parameters
reasonFilterChangeReason- A filter that specifies which types of changes to include.
returnOnlyOnClosebool- If
true, returns only entries with the Close reason flag set. timeoutTimeSpan- The time to wait for new entries once the end of the journal is reached. Use
TimeSpan.Zeroto stop there instead of waiting.
Returns
IEnumerable<ChangeJournalEntry> A collection of change journal entries matching the filter criteria.
Remarks
A non-zero timeout makes the enumeration wait for a matching entry rather than end, so it never completes on its own. The wait happens inside a synchronous call to the driver and cannot be cancelled, which means a thread enumerating with a non-zero timeout stays blocked until an entry matches the filter.
GetEntries(Usn, ChangeReason, bool, TimeSpan)
ChangeJournal.csGets change journal entries starting from a specific USN with the specified filter criteria.
public IEnumerable<ChangeJournalEntry> GetEntries(Usn currentUSN, ChangeReason reasonFilter, bool returnOnlyOnClose, TimeSpan timeout)Parameters
currentUSNUsn- The USN to start reading from.
reasonFilterChangeReason- A filter that specifies which types of changes to include.
returnOnlyOnClosebool- If
true, returns only entries with the Close reason flag set. timeoutTimeSpan- The time to wait for new entries once the end of the journal is reached. Use
TimeSpan.Zeroto stop there instead of waiting.
Returns
IEnumerable<ChangeJournalEntry> A collection of change journal entries matching the filter criteria.
Exceptions
ArgumentOutOfRangeException- Thrown when
currentUSNis outside the valid range.
Remarks
A non-zero timeout makes the enumeration wait for a matching entry rather than end, so it never completes on its own. The wait happens inside a synchronous call to the driver and cannot be cancelled, which means a thread enumerating with a non-zero timeout stays blocked until an entry matches the filter.
GetEntry overloads
GetEntry(SafeFileHandle)
ChangeJournal.csGets the change journal entry for a specific file or directory by handle.
public static ChangeJournalEntryVersion2or3 GetEntry(SafeFileHandle handle)Parameters
handleSafeFileHandle- A handle to the file or directory.
Returns
ChangeJournalEntryVersion2or3 The change journal entry for the specified file or directory.
Exceptions
Win32Exception- Thrown when the operation fails.
GetEntry(string)
ChangeJournal.csGets the change journal entry for a specific file or directory by path.
public static ChangeJournalEntryVersion2or3 GetEntry(string path)Parameters
pathstring- The path to the file or directory.
Returns
ChangeJournalEntryVersion2or3 The change journal entry for the specified file or directory.
Exceptions
ArgumentNullException- Thrown when
pathisnull. Win32Exception- Thrown when the operation fails.
Open overloads
Open(DriveInfo)
ChangeJournal.csOpens the change journal for the specified drive.
public static ChangeJournal Open(DriveInfo driveInfo)Parameters
driveInfoDriveInfo- The drive to open the change journal for.
Returns
ChangeJournal A ChangeJournal instance for accessing the change journal.
Exceptions
ArgumentNullException- Thrown when
driveInfoisnull. Win32Exception- Thrown when the operation fails.
Open(DriveInfo, bool)
ChangeJournal.csOpens the change journal for the specified drive.
public static ChangeJournal Open(DriveInfo driveInfo, bool unprivileged)Parameters
driveInfoDriveInfo- The drive to open the change journal for.
unprivilegedbool- If
true, uses unprivileged access mode; otherwise, uses standard access mode.
Returns
ChangeJournal A ChangeJournal instance for accessing the change journal.
Exceptions
ArgumentNullException- Thrown when
driveInfoisnull. Win32Exception- Thrown when the operation fails.
RefreshJournalData()
ChangeJournal.csRefreshes the journal metadata by reading the current state from the change journal.
public void RefreshJournalData()