Example #1
0
        public IEnumerable <DiskDrive> GetDiskDrives()
        {
            foreach (var device in _driveEnumerator.GetDrives())
            {
                var devNumber = IoctlQueryer.GetDiskDeviceNumberForDevice(device.Path);

                yield return(new DiskDrive
                {
                    DeviceNumber = (int)devNumber,
                    Name = device.FriendlyName,
                });
            }
        }
Example #2
0
        public static void Wipe(Func <IDataSource> sourceFactory, FileStream destination, IProgress <int> progress, CancellationToken cancelToken)
        {
            progress.Report(0);
            destination.Seek(0, SeekOrigin.Begin);

            var diskSize   = IoctlQueryer.GetDiskLength(destination.SafeFileHandle);
            var sectorSize = GetHighestPowerOf2(diskSize, max: 1024 * 1024);

            var buffer = new byte[sectorSize];

            using (var source = sourceFactory())
            {
                for (long i = 0; i < diskSize; i += sectorSize)
                {
                    cancelToken.ThrowIfCancellationRequested();

                    source.GetBytes(buffer);
                    destination.Write(buffer, 0, buffer.Length);
                    progress.Report(GetPercentage(i, diskSize));
                }
            }
        }