Exemple #1
0
        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);
            }
        }
        private bool CreateVhd()
        {
            using (var stream = new FileStream(this.FileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 1, FileOptions.WriteThrough)) {
                ReFS.RemoveIntegrityStream(stream.SafeFileHandle);

                var footer = new HardDiskFooter();
                footer.BeginUpdate();
                footer.CreatorApplication = VhdCreatorApplication.JosipMedvedVhdAttach;
                footer.CreatorVersion     = Medo.Reflection.EntryAssembly.Version;
                footer.SetSize((UInt64)this.SizeInBytes);
                footer.OriginalSize = footer.CurrentSize;
                footer.DiskType     = VhdDiskType.FixedHardDisk;

                footer.EndUpdate();

                var    lastReport = DateTime.UtcNow;
                byte[] buffer     = new byte[Settings.WriteBufferSize];
                ulong  remaining  = footer.CurrentSize;
                while (remaining > 0)
                {
                    if (bgw.CancellationPending)
                    {
                        stream.Dispose();
                        File.Delete(this.FileName);
                        return(false);
                    }
                    ulong count = (ulong)buffer.Length;
                    if ((ulong)count > remaining)
                    {
                        count = remaining;
                    }
                    stream.Write(buffer, 0, (int)count);
                    remaining -= count;
                    if (lastReport.AddSeconds(1) < DateTime.UtcNow)
                    {
                        bgw.ReportProgress(100 - (int)(remaining * 100 / footer.CurrentSize));
                        lastReport = DateTime.UtcNow;
                    }
                }
                buffer = footer.Bytes;
                stream.Write(buffer, 0, buffer.Length);
            }
            return(true);
        }
Exemple #3
0
        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);
                }
            }
        }
 private void bwAction_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     ReFS.RemoveIntegrityStream(this.File);
 }