The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ArtemESC on April 13, 2006, 03:05:10 PM

Title: Access to HDD...
Post by: ArtemESC on April 13, 2006, 03:05:10 PM
 How get all info about HDD (size of disc, sector count on track and etc) using ports (ATA interface)...
     Thanks all :wink
Title: Re: Access to HDD...
Post by: hitchhikr on April 13, 2006, 03:28:10 PM
I suggest you to take a careful look at these sites:

http://www.nondot.org/sabre/os/articles
http://www.azillionmonkeys.com/qed/os.html
http://www.osdev.org/
Title: Re: Access to HDD...
Post by: Tedd on April 13, 2006, 04:46:14 PM
http://www.t13.org/
Title: Re: Access to HDD...
Post by: 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.

(http://www.pbrennick.com/DriveInfo.jpg)

hth,
Paul


[attachment deleted by admin]
Title: Re: Access to HDD...
Post by: skywalker on April 13, 2006, 05:28:36 PM
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.

(http://www.pbrennick.com/DriveInfo.jpg)

hth,
Paul


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

Title: Re: Access to HDD...
Post by: 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.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    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

Title: Re: Access to HDD...
Post by: GregL on April 14, 2006, 01:40:04 AM
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.  ::)

Title: Re: Access to HDD...
Post by: skywalker on April 14, 2006, 03:32:41 AM
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]