Re: How to read the data from the first sector of HDD




Michael Schnell wrote:

Where to find the the dd source code ??

I have no link right here (at home), but searching the Internet should
come up with many locations. (I'd recommend _using_ dd, anyway)


Can i use the bios_disk() function in the linux. The corresponding
Header Flie is Bios.h

No. Linux is 32 bit and the PCBIOS calls need to be done in a 16 way.
Moreover this will not help with the corruption problem at all

How to "call" command line utilities in a C program??

Using the appropriate API via the standard C libraries.

Sorry, I have no link right here (at home), but searching the Internet
should come up with many locations. Maybe someone else might jump in.

-Michael


Hello Michael,

Sorry for the delay, actually inbetween, i was working on the serial
port diagnostic.

Well, now i again switch over to HDD.
On net i got one document related to the IDE controller. specifying the
different registers.From that document, i think it is possible to read
and write the perticular sector by writing and reading the contents of
the registers using the commands "inb" and "outb"


#define HDD_STATUS_REGISTER 0x1F7
#define HDD_SECTOR_NUMBER_REGISTER 0x1F3
#define HDD_SECTOR_COUNT_REGISTER 0x1F2
#define HDD_CYLINDER_HIGH_REGISTER 0x1F5
#define HDD_CYLINDER_LOW_REGISTER 0x1F4
#define HDD_HEAD_REGISTER 0x1F6
#define COMMAND_READ_SECTOR 0x20
/*20H Read sector with retry. NB: 21H = read sector
without retry. For this command you have to load
the complete circus of cylinder/head/sector
first. When the command completes (DRQ goes
active) you can read 256 words (16-bits) from the
disk's data register.
*/

#define HDD_DATA_REGISTER 0x1F0
#define HDD_DATA_READY 0x08 /*3rd bit
of HDD_STATUS_REG*/
#define HDD_BUSY 0x80 /*
7th bit of HDD_STATUS_REG*/
unsigned int lbaAddress;
short numSectors;
void readSectors( )
{
int i,j;
unsigned short buff[256];

ioperm(HDD_DATA_REGISTER,7,0);

while((inportb(HDD_STATUS_REGISTER) & HDD_BUSY));
/*Before doing anything with a device you have to wait till it
indicates that it is ready (RDY bit in the status register)*/


outportb(HDD_SECTOR_NUMBER_REGISTER,lbaAddress & 0xff );
outportb(HDD_SECTOR_COUNT_REGISTER,numSectors);
outportb(HDD_CYLINDER_HIGH_REGISTER,(lbaAddress>>16) & 0xff );
outportb(HDD_CYLINDER_LOW_REGISTER,(lbaAddress>>8) & 0xff );
outportb(HDD_HEAD_REGISTER, 0xE0 | ((lbaAddress>>24) & 0x0f) );
outportb(HDD_CONTROL_REGISTER,COMMAND_READ_SECTOR);
for(i=0;i<numSectors;i++)
{
/*This is because i want to be able to read multiple sectors
and interrupts aren't working cuz of some reason*/
while(!(inportb(HDD_STATUS_REGISTER)& HDD_DATA_READY));
/*You wait till the device signals that it is ready for data
transfer (DRQ in the status register).*/

for(j=0;j<sizeof(buff);j++)
buff[i]=inport(HDD_DATA_REGISTER);
}

but after executing the line
outportb(HDD_CONTROL_REGISTER,COMMAND_READ_SECTOR);
i m getting the o/p as "segmentation fault"

Could u lease tell me if i m on the right track, why i m gtting such a
type of error?

Please help me....

Thanks and regards,
Nutty

.



Relevant Pages

  • Re: New Home Page, task bar, and history
    ... and a virus protection software that i had x-ed out ... | Internet Security scan, and delete everything that it found. ... | get to my mail from searching on google, but not the regular home page. ... On Win9x/ME platforms the report will not be shown in your bowser ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: People Online
    ... Today almost everybody in the world has access to the internet. ... People online use the internet for many needs such as searching for ... "Usenet Filters - Learn to shut yourself the fuck up!" ... "Those who record history are those who control history." ...
    (alt.2600)
  • Re: Indecent pics of children and possession
    ... IMO, based on over a decade of Internet use, I would estimate that the ... there *is* child pornography ... If you spent only 1 hour by yourself searching for these ... Are you networking with others who may ...
    (uk.legal)
  • Re: Arabic and other languages
    ... The explanation comes from experimenting with Word. ... comments were picked up from searching the internet and may be wrong. ... Mac first, Mac only: ...
    (microsoft.public.mac.office.word)