예제 #1
0
		public static extern bool DeviceIoControl(
			Microsoft.Win32.SafeHandles.SafeFileHandle hDevice,
			uint IoControlCode,
			IntPtr InBuffer,
			uint nInBufferSize,
			ref DiskGeometry OutBuffer,
			int nOutBufferSize,
			out uint pBytesReturned,
			IntPtr Overlapped
		);
예제 #2
0
		public static bool GetDriveGeometry(SafeFileHandle hDevice, ref DiskGeometry pdg)
		{
			uint junk;				   // discard results
			return Native.DeviceIoControl(
				hDevice,  // device to be queried
				Native.IOCTL_DISK_GET_DRIVE_GEOMETRY,  // operation to perform
				IntPtr.Zero, 0, // no input buffer
				ref pdg, Marshal.SizeOf(pdg),	 // output buffer
				out junk,				  // # bytes returned
				IntPtr.Zero);  // synchronous I/O
		}
예제 #3
0
		public static long GetDriveLength(SafeFileHandle hDevice)
		{
			DiskGeometry pdg = new DiskGeometry();
			if (GetDriveGeometry(hDevice, ref pdg))
			{
				Console.WriteLine(pdg.Cylinders + " " + pdg.TracksPerCylinder + " " + pdg.SectorsPerTrack + " " + pdg.BytesPerSector);
			
				return (long)pdg.Cylinders * (long)pdg.TracksPerCylinder *
				(long)pdg.SectorsPerTrack * (long)pdg.BytesPerSector;
			}
			else
				throw new Win32Exception();
		}