Reputation: 4822
I have this C code:
struct ATAInfo* data;
data = (struct ATAInfo*)malloc(512);
Then I call a function, which fills the struct. This is a bit difficult to explain, because i call a function, making a syscall through an interrupt, which reads information form my cd-rom device. I call it this way:
ata_identify(0, data)
And the Function is defined like this:
bool ataIdentify(int device, struct ATAInfo *ataInfo){
Now i fill it with this:
uint16_t pointer = ataInfo;
uint16_t word;
for (int i = 0; i < 256; i++)
{
word = inw(DATA_PORT);
*(uint16_t *) pointer = word;
pointer ++;
}
Now I want to read one attribute out of the struct, which is declared like this:
uint8_t ModelNumber[40];
I did this:
printf("name: %s\n", data->ModelNumber);
But I get "name: (null)".
Upvotes: 0
Views: 99
Reputation: 206607
This block of code does not seem right:
uint16_t pointer = ataInfo;
uint16_t word;
for (int i = 0; i < 256; i++)
{
word = inw(DATA_PORT);
*(uint16_t *) pointer = word;
pointer ++;
}
Did you mean:
uint16_t* pointer = (unit16_t*)ataInfo;
uint16_t word;
for (int i = 0; i < 256; i++)
{
word = inw(DATA_PORT);
*pointer = word;
pointer ++;
}
Upvotes: 1