News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Access to HDD...

Started by ArtemESC, April 13, 2006, 03:05:10 PM

Previous topic - Next topic

ArtemESC

 How get all info about HDD (size of disc, sector count on track and etc) using ports (ATA interface)...
     Thanks all :wink


Tedd

No snowflake in an avalanche feels responsible.

PBrennick

ArtemESC,
Babek certainly did a nice job when he wrote DriveInfo.  The project is attached to this post.  The only change I made to it is instead of starting with Drive A, it starts with Drive C.


hth,
Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on April 13, 2006, 04:59:41 PM
ArtemESC,
Babek certainly did a nice job when he wrote DriveInfo.  The project is attached to this post.  The only change I made to it is instead of starting with Drive A, it starts with Drive C.


hth,
Paul


It reports 18.6G intead of 19.5G for my hard drive.


MichaelW

ArtemESC,

You will need code to send an Identify Device command to the device and read the 512 bytes that the command returns, and code to interpret and display the data. You should be able to get most or all of the necessary information at the links that hitchhikr and Tedd posted.

Andy,

How did you derive the 19.5GB value? The program is returning essentially the same total space value that Windows (or at least Windows 2000) reports in the disk properties.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      dqFreeBytes       dq 0
      dqTotalBytes      dq 0
      dqTotalFreeBytes  dq 0
      sectorsPerCluster dd 0
      totalGB           REAL8 0.0
      bytesPerSector    dd 0
      freeClusters      dd 0
      totalClusters     dd 0
      rootPath          db "c:\",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetDiskFreeSpace,ADDR rootPath,
                            ADDR sectorsPerCluster,
                            ADDR bytesPerSector,
                            ADDR freeClusters,
                            ADDR totalClusters

    invoke crt_printf,chr$("GetDiskFreeSpace, sectors per cluster: %d%c"),
                      sectorsPerCluster,10

    invoke crt_printf,chr$("GetDiskFreeSpace, bytes per sector: %d%c"),
                      bytesPerSector,10

    invoke crt_printf,chr$("GetDiskFreeSpace, free clusters: %d%c"),
                      freeClusters,10

    invoke crt_printf,chr$("GetDiskFreeSpace, total clusters: %d%c%c"),
                      totalClusters,10,10

    mov   eax, sectorsPerCluster
    mul   bytesPerSector
    mul   totalClusters
    push  edx
    push  eax
    invoke crt_printf,chr$("Calculated total bytes: %I64d%c%c"),
                      edx::eax,10,10
    finit
    fild  QWORD PTR[esp]
    fld8  1073741824.0          ; 1024*1024*1024
    fdiv
    fstp  totalGB

    invoke crt_printf,chr$("Calculated GB: %f%c%c"),
                      totalGB,10,10

    invoke GetDiskFreeSpaceEx,ADDR rootPath,
                              ADDR dqFreeBytes,
                              ADDR dqTotalBytes,
                              ADDR dqTotalFreeBytes

    mov   eax, totalClusters
    cdq
    imul  sectorsPerCluster
    imul  bytesPerSector
    mov   ecx, 1024 * 1024
    idiv  ecx
    cdq
    mov   ecx, 1024
    mov   ebx, 1000
    idiv  ecx
    mov   ecx, eax      ; ecx = Integer, edx = MOD
    mov   eax, edx
    cdq
    imul  ebx
    mov   ebx, 1024
    idiv  ebx           ; eax = Frac
    push  eax
    invoke crt_printf,chr$("Calculated GB (DriveInfo method), %d"),ecx
    pop   eax
    invoke crt_printf,chr$(".%d%c%c"),eax,10,10


    invoke crt_printf,chr$("GetDiskFreeSpaceEx, free bytes: %I64d%c"),
                      dqFreeBytes,10
    invoke crt_printf,chr$("GetDiskFreeSpaceEx, total bytes: %I64d%c"),
                      dqTotalBytes,10
    invoke crt_printf,chr$("GetDiskFreeSpaceEx, total free bytes: %I64d%c%c"),
                      dqTotalFreeBytes,10,10,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

GregL

It's the old thing about hard drive manufacturers using 1,000,000,000 for a Gigabyte and Windows using 1,073,741,824 for a Gigabyte. What the hard drive manufacturers call a 80 GB drive is actually 74.5 GB.  ::)


skywalker

Quote from: MichaelW on April 13, 2006, 11:36:23 PM
ArtemESC,

You will need code to send an Identify Device command to the device and read the 512 bytes that the command returns, and code to interpret and display the data. You should be able to get most or all of the necessary information at the links that hitchhikr and Tedd posted.

Andy,

How did you derive the 19.5GB value? The program is returning essentially the same total space value that Windows (or at least Windows 2000) reports in the disk properties.



There is a difference between Device Manager,chkdsk, and what explorer shows. Explorer does show 18.6 G so I guess that is the true capacity.[/quote]