Changeset 2196


Ignore:
Timestamp:
6/19/2010 1:29:09 AM (4 years ago)
Author:
lowjoel
Message:

Define the IOCTL_DISK_DELETE_DRIVE_LAYOUT which erases the MBR of the physical drive, allowing us to delete all partitions on the physical drive.

Location:
trunk/eraser/Eraser.Util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Util/NativeMethods/Kernel.cs

    r2187 r2196  
    646646        public const uint FSCTL_LOCK_VOLUME = 0x90018; 
    647647        public const uint FSCTL_UNLOCK_VOLUME = 0x9001C; 
     648        public const uint IOCTL_DISK_DELETE_DRIVE_LAYOUT = 
     649            (0x00000007 << 16) | ((0x01 | 0x02) << 14) | (0x0040 << 2); 
    648650 
    649651        [DllImport("Kernel32.dll", SetLastError = true)] 
  • trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs

    r2191 r2196  
    149149 
    150150        /// <summary> 
     151        /// Destroys all partitioning information on the drive. 
     152        /// </summary> 
     153        public void DeleteDriveLayout() 
     154        { 
     155            //Open the drive for read/write access 
     156            using (SafeFileHandle handle = OpenHandle(FileAccess.ReadWrite, FileShare.ReadWrite, 
     157                FileOptions.None)) 
     158            { 
     159                //Issue the IOCTL_DISK_DELETE_DRIVE_LAYOUT control code 
     160                uint returnSize = 0; 
     161                if (!NativeMethods.DeviceIoControl(handle, 
     162                    NativeMethods.IOCTL_DISK_DELETE_DRIVE_LAYOUT, IntPtr.Zero, 0, IntPtr.Zero, 
     163                    0, out returnSize, IntPtr.Zero)) 
     164                { 
     165                    throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 
     166                } 
     167            } 
     168        } 
     169 
     170        /// <summary> 
    151171        /// Opens a file with read, write, or read/write access. 
    152172        /// </summary> 
Note: See TracChangeset for help on using the changeset viewer.