Advertisement
Advertisement
| 03.25.2008 at 11:09AM PDT, ID: 23267982 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: |
import System.*;
import System.Runtime.InteropServices.*;
public class Test
{
private static final int IOCTL_DISK_GET_DRIVE_GEOMETRY = 0x0070000;
private static final int INVALID_HANDLE_VALUE = -1;
private class DISK_GEOMETRY
{
public long Cylinders;
public int MediaType;
public int TracksPerCylinder;
public int SectorsPerTrack;
public int BytesPerSector;
}
public Test()
{
}
public DISK_GEOMETRY getDriveGeometry(DISK_GEOMETRY pdg)
{
int hDevice;
boolean bResult;
int[] junk = new int[0];
com.ms.win32.OVERLAPPED lpOverlapped = null;
com.ms.win32.SECURITY_ATTRIBUTES lpSecurity = null;
hDevice = com.ms.win32.Kernel32.CreateFile("\\\\.\\PhysicalDrive0", com.ms.win32.wing.GENERIC_READ, com.ms.win32.winf.FILE_SHARE_READ, lpSecurity, com.ms.win32.wino.OPEN_EXISTING, 0, 0);
if (hDevice == INVALID_HANDLE_VALUE)
{
return null;
}
bResult = com.ms.win32.Kernel32.DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, null, 0, pdg, 192, junk, lpOverlapped);
com.ms.win32.Kernel32.CloseHandle(hDevice);
return pdg;
}
public void getDriveGeometryStart()
{
DISK_GEOMETRY pdg = new DISK_GEOMETRY();
boolean bResult;
long DiskSize;
pdg = getDriveGeometry(pdg);
if (pdg != null) {
System.out.println("Cylinders = " + pdg.Cylinders);
System.out.println("Tracks per cylinder = " + (long)pdg.TracksPerCylinder);
System.out.println("Sectors per track = "+ (long)pdg.SectorsPerTrack);
System.out.println("Bytes per sector = " + (long)pdg.BytesPerSector);
DiskSize = pdg.Cylinders * (long)pdg.TracksPerCylinder * (long)pdg.SectorsPerTrack * (long)pdg.BytesPerSector;
System.out.println("Disk size = %I64d (Bytes) = " + DiskSize + " " + DiskSize / (1024 * 1024));
} else {
System.out.println("Attempt to get drive geometry failed.");
}
}
}
public static void main(String[] args)
{
System.out.println("Starting...");
try{
Test test = new Test();
test.getDriveGeometryStart();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("Complete!");
}
}
|