Пример #1
0
        //
        public ulong SeekU(ulong offset, SeekOrigin origin)
        {
            ulong n = 0;

            if (!DeviceIO.SetFilePointerEx(this.fileHandle, offset, out n, (uint)origin))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            return(n);
        }
Пример #2
0
        /// <summary>
        ///  Function to Write Data Pattern that is in buffer to disk sectors
        /// </summary>
        /// <param name="writeBuffer">The buffer that has the pattern of data to write</param>
        /// <param name="writeOffset">The byte offset in writeBuffer from which to begin copying bytes to the stream</param>
        /// <param name="writeCount">The maximum number of bytes to write</param>
        /// <returns></returns>
        public unsafe void Write(byte[] writeBuffer, uint writeOffset, uint writeCount)
        {
            uint   BytesWritten = 0;
            UInt64 newFilePtr   = 0;
            long   sectorStart  = -1;
            long   sectorEnd    = -1;

            while (true)
            {
                Console.WriteLine("Enter start sector to overwrite from : ");
                Wipe.sectorStart = Convert.ToUInt64(Console.ReadLine());
                Console.WriteLine("\nEnter end sector to write till : ");
                Wipe.sectorEnd = Convert.ToUInt64(Console.ReadLine());
                if (sectorStart < sectorEnd)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("\nStart sector cannot be greater than end Sector.....Try again!!!\n");
                }
            }
            long  sectorDiff     = sectorEnd - sectorStart;
            int   size           = Wipe.sectorWriteSize;// ((sectorDiff > 32) ? ((sectorDiff > 1024) ? (512 * 2 * 64) : (512 * 2 * 4)) : 512); //512 * 2 * 1024;
            ulong distanceToMove = (ulong)(sectorStart * size);

            Console.WriteLine("\nWriting entered pattern to disk\n");

            try
            {
                fixed(byte *writeBufferPointer = writeBuffer)
                {
                    DeviceIO.SetFilePointerEx(this.fileHandle, distanceToMove, out newFilePtr, DeviceIO.FILE_BEGIN);

                    for (long i = sectorStart; i <= sectorEnd; i += (size / 512))
                    {
                        if (!DeviceIO.WriteFile(this.fileHandle, writeBufferPointer + writeOffset, (uint)size, &BytesWritten, IntPtr.Zero))
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }

                        //sectorStart += (size / 512);
                        if (i % 100 == 0)
                        {
                            drawTextProgressBar((int)i, (int)sectorEnd);
                        }
                    }
                    Console.WriteLine("After WriteFile");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Function to Read Data into the Buffer from disk
        /// </summary>
        /// <param name="readBuffer">bytes read from the current disk.</param>
        /// <param name="readOffset"> byte offset in readBuffer at which to begin storing the data read from the current stream.</param>
        /// <param name="readCount">The maximum number of bytes to be read from the current stream.</param>
        /// <returns>
        /// Number of bytes read into the buffer.
        /// </returns>
        public unsafe uint Read(byte[] readBuffer, uint readOffset, uint readCount)
        {
            uint   BytesRead      = 0;
            UInt64 newFilePtr     = 0;
            uint   size           = 512;// ((sectorDiff > 32) ? ((sectorDiff > 1024) ? (512 * 2 * 64 ) : (512 * 2 * 4)) : 512);
            ulong  distanceToMove = (ulong)(Wipe.sectorStart * size);

            Console.WriteLine("\nVerifying Write Pattern....\n");

            fixed(byte *readBufferPointer = readBuffer)
            {
                DeviceIO.SetFilePointerEx(this.fileHandle, distanceToMove, out newFilePtr, DeviceIO.FILE_BEGIN);

                for (ulong i = Wipe.sectorStart; i <= Wipe.sectorEnd; i += ((ulong)size / 512))
                {
                    if (!DeviceIO.ReadFile(this.fileHandle, readBufferPointer + readOffset, size, &BytesRead, IntPtr.Zero))
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    if (!readBuffer.SequenceEqual(toWrite))
                    {
                        Wipe.sectorErrorCount++;
                    }

                    /*else
                     * {
                     *  Console.WriteLine("Could not verify");
                     * }*/
                    //Wipe.sectorStart += ((ulong)size / 512);
                }

                Console.WriteLine("Verification Complete.....");
                return(BytesRead);
            }
        }