Solved

retreiving the number of LBA sectors from drives greater than 137.4gb

Posted on 2004-08-05
4
281 Views
Last Modified: 2010-04-15
I am trying to obtain HD info for large drives > 137.4GB

This works well upto 137.4Gb. The Computer bios detects drives greater than 137.4gb correctly

int hddetect(int driveselect) /* drive value 1-4 */
{
           int i,j,err=1;
      unsigned int controller,masterselect,drivectl,readbuff;
 
      if (driveselect==1)
      {
            controller=0x1f7;
            drivectl=0x1f6;
            masterselect=0xa0;
            readbuff=0x1f0;
      }
      if (driveselect==2)
      {
            controller=0x1f7;
            drivectl=0x1f6;
            masterselect=0xb0;
            readbuff=0x1f0;
      }
      if (driveselect==3)
      {
            controller=0x177;
            drivectl=0x176;
            masterselect=0xa0;
            readbuff=0x170;
      }
      if (driveselect==4)
      {
            controller=0x177;
            drivectl=0x176;
            masterselect=0xb0;
            readbuff=0x170;
      }

      for (i=0; i<100000; i++)
      {
                 if (inp(controller) == 0x50)   /* check if controller is ready */
            {
            i=100000;
            }
           }
      
           outp(drivectl, masterselect); /* masterselect 0xa0 master */
           /* select 0xb0 if you have a slave */
           outp(controller, 0xec); /* ask for data */
      for (i=0; i<100000; i++)
      {
                 if (inp(controller) == 0x58)   /* check if data is ready */
            {
            i=100000;
            err=0;
            }
           }
           for (i = 0; i<256; i++) /* Read the data */
                data[i] = inpw(readbuff);

           for(i=0,j=27;j<=46;j++)
           {
                model[i++]=(char)(data[j]/256);
                model[i++]=(char)(data[j]%256);
           }
           model[i]='\0';

           for(i=0,j=10;j<=19;j++)
           {
                serial[i++]=(char)(data[j]/256);
                serial[i++]=(char)(data[j]%256);
           }
           serial[i]='\0';
      

      /* Num of LBA Sectors */
      lbasectors=(data[61]*65536)+data[60];
      
      return err;
}

0
Comment
Question by:nstn2879
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 63 total points
ID: 11727515
Are you working in DOS? If so, consider that int variables are only 16 bits, also 32 bits var can overflow with so big number, o maybe some intermediate operations.
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 62 total points
ID: 11728545
You might be getting sign-bit problems with all that div 256 and mod 256 stuff.  
You could replace all that with   memcpy( model, data[27], (46-27) * 2 ) and
similary for serial.

Also for the lba calculation, be sure "data" is defined as "unsigned int data[ yadda ];"
and cast the calculation into using longs:

 lbasectors = ( ((unsigned long) data[61]) << 16)) + (unsigned long) data[60];

or with memcpy:

memcpy( lbasectors, data[60], sizeof( lbasectors ) )

"lbasectors better be defined as "unsigned long int" and end up as 32 bits!

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now