public static void RemoveIntegrityStream(FileInfo file) { if (!ReFS.HasIntegrityStream(file)) { return; } //cancel if file has no integrity stream using (var handle = NativeMethods.CreateFile(file.FullName, NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE, FileShare.None, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero)) { RemoveIntegrityStream(handle); } }
public static void RemoveIntegrityStream(SafeFileHandle handle) { if (!ReFS.HasIntegrityStream(handle)) { return; } //cancel if file has no integrity stream var oldInfo = new NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION_BUFFER(); var oldInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_GET_INTEGRITY_INFORMATION, IntPtr.Zero, 0, ref oldInfo, Marshal.SizeOf(oldInfo), out oldInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } if (oldInfo.ChecksumAlgorithm == NativeMethods.CHECKSUM_TYPE_NONE) { return; } //already done var newInfo = new NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION_BUFFER() { ChecksumAlgorithm = NativeMethods.CHECKSUM_TYPE_NONE, Flags = oldInfo.Flags }; var newInfoSizeReturn = 0; if (!NativeMethods.DeviceIoControl(handle, NativeMethods.FSCTL_SET_INTEGRITY_INFORMATION, ref newInfo, Marshal.SizeOf(newInfo), IntPtr.Zero, 0, out newInfoSizeReturn, IntPtr.Zero)) { try { throw new Win32Exception(); } catch (Win32Exception ex) { throw new InvalidOperationException(ex.Message, ex); } } }