Solved

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

Posted on 2004-08-05
4
283 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

809 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