Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-05
4
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 252 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 248 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

636 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