Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C: GetDiskFreeSpaceEx() for default drive 14 107
Where is my core dump file in Ubuntu? 12 449
UPD maximums on Red Hat 6 115
macro vba to pivot table 1 19
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

778 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