public void Create(long maximumSize, long allocationDelta) { var creationData = new CREATE_USN_JOURNAL_DATA { AllocationDelta = allocationDelta, MaximumSize = maximumSize }; Win32DeviceControl.ControlWithInput(ChangeJournalHandle, Win32ControlCode.CreateUsnJournal, ref creationData, 0); ReadJournalData(); }
public void Delete() { var deletionData = new DELETE_USN_JOURNAL_DATA { UsnJournalID = Data.ID, DeleteFlags = DeletionFlag.WaitUntilDeleteCompletes, }; Win32DeviceControl.ControlWithInput(ChangeJournalHandle, Win32ControlCode.CreateUsnJournal, ref deletionData, 0); ReadJournalData(); }
private JournalData ReadJournalDataImpl() { try { var journalData = new USN_JOURNAL_DATA(); Win32DeviceControl.ControlWithOutput(ChangeJournalHandle, Win32ControlCode.QueryUsnJournal, ref journalData); return(new JournalData(journalData)); } catch (Win32Exception ex) when(ex.NativeErrorCode == (int)Win32ErrorCode.ERROR_JOURNAL_NOT_ACTIVE) { return(new JournalData()); } }
private bool Read() { const int CurrentUSNLength = sizeof(long); var readData = new READ_USN_JOURNAL_DATA_V0 { StartUsn = _currentUSN, ReasonMask = Options.ReasonFilter, UsnJournalID = ChangeJournal.Data.ID, ReturnOnlyOnClose = Options.ReturnOnlyOnClose ? (uint)1 : 0, Timeout = (ulong)Options.Timeout.TotalSeconds, }; var handle = ChangeJournal.ChangeJournalHandle; var entryData = Win32DeviceControl.ControlWithInput(handle, Win32ControlCode.ReadUsnJournal, ref readData, BufferSize); if (entryData.Length > CurrentUSNLength) // There are more data than just data currentUSN. { var bufferHandle = GCHandle.Alloc(entryData, GCHandleType.Pinned); var bufferPointer = bufferHandle.AddrOfPinnedObject(); _currentUSN = Marshal.ReadInt64(entryData, 0); // Enumerate entries _entries.Clear(); var offset = CurrentUSNLength; // Skip currentUSN field while (offset < entryData.Length) { var entry = GetBufferedEntry(bufferPointer, offset); offset += entry.Length; _entries.Add(entry); } bufferHandle.Free(); _currentIndex = 0; return(true); } else { _eof = true; return(false); } }