Re: How to read the data from the first sector of HDD
- From: "Nutty" <nutty.sawant@xxxxxxxxx>
- Date: 5 Nov 2006 20:11:46 -0800
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
.
- Follow-Ups:
- Re: How to read the data from the first sector of HDD
- From: Michael Schnell
- Re: How to read the data from the first sector of HDD
- From: Michael Schnell
- Re: How to read the data from the first sector of HDD
- From: Wolfgang Mües
- Re: How to read the data from the first sector of HDD
- Prev by Date: Re: Porting Linux
- Next by Date: Re: Porting Linux
- Previous by thread: Porting Linux
- Next by thread: Re: How to read the data from the first sector of HDD
- Index(es):
Relevant Pages
|