/ Published in: Perl
# A simple example to retrieve disk geometry via Device IO Control.
# I hard coded the disk number to //./PhysicalDrive0
# This script is a read-only operation to your hard disk. It has no influence to your hard disk.
# I hard coded the disk number to //./PhysicalDrive0
# This script is a read-only operation to your hard disk. It has no influence to your hard disk.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/path/to/perl -w # # Vinocui @ 2009.7.3 # A simple example to retrieve disk geometry via Device IO Control. # I hard coded the disk number to //./PhysicalDrive0 # This script is a read-only operation to your hard disk. It has no influence to your hard disk. # # I shoulde use strict here. but i'm lazy... %MediaType = ( 0=>"Format is unknown", 1=>"A 5.25\" floppy, with 1.2MB and 512 bytes/sector.", 2=>"3.5\" floppy, with 1.44MB and 512 bytes/sector.", 3=>"A 3.5\" floppy, with 2.88MB and 512 bytes/sector.", 4=>"A 3.5\" floppy, with 20.8MB and 512 bytes/sector.", 5=>"A 3.5\" floppy, with 720KB and 512 bytes/sector.", 6=>"A 5.25\" floppy, with 360KB and 512 bytes/sector.", 7=>"A 5.25\" floppy, with 320KB and 512 bytes/sector.", 8=>"A 5.25\" floppy, with 320KB and 1024 bytes/sector.", 9=>"A 5.25\" floppy, with 180KB and 512 bytes/sector.", 10=>"A 5.25\" floppy, with 160KB and 512 bytes/sector.", 11=>"Removable media other than floppy.", 12=>"Fixed hard disk media.", 13=>"A 3.5\" floppy, with 120MB and 512 bytes/sector.", 14=>"A 3.5\" floppy, with 640KB and 512 bytes/sector.", 15=>"A 5.25\" floppy, with 640KB and 512 bytes/sector.", 16=>"A 5.25\" floppy, with 720KB and 512 bytes/sector.", 17=>"A 3.5\" floppy, with 1.2MB and 512 bytes/sector.", 18=>"A 3.5\" floppy, with 1.23MB and 1024 bytes/sector.", 19=>"A 5.25\" floppy, with 1.23MB and 1024 bytes/sector.", 20=>"A 3.5\" floppy, with 128MB and 512 bytes/sector.", 21=>"A 3.5\" floppy, with 230MB and 512 bytes/sector.", 22=>"An 8\" floppy, with 256KB and 128 bytes/sector.", 23=>"A 3.5\" floppy, with 200MB and 512 bytes/sector. (HiFD).", 24=>"A 3.5\" floppy, with 240MB and 512 bytes/sector. (HiFD).", 25=>"A 3.5\" floppy, with 32MB and 512 bytes/sector." ); $sPath = "//./PhysicalDrive1"; $uAccess = GENERIC_READ; $uShare = FILE_SHARE_READ | FILE_SHARE_WRITE; $pSecAttr = []; $uCreate = OPEN_EXISTING; $uFlags = FILE_ATTRIBUTE_NORMAL; $hModel = []; $hObject = CreateFile( $sPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel ) or die "can not open $sPath"; $ret = DeviceIoControl( $hObject, IOCTL_DISK_GET_DRIVE_GEOMETRY, [], 0, $opOutBuf, $olRetBytes, CloseHandle($hObject); if ($ret) { ( $ucCylsLow, $ivcCylsHigh, $uMediaType, $uTracksPerCyl, }else{ } 0;