Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

734 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