Hello, I am working on a testing task.
In the task I am using this code that I have written:
Code:
void HDD_Write(UINT16 lintSector,UINT32 lintHddOffset, UINT8 * lintData, UINT32 lintDataLen)
{
printf("HDD_Write(): lintSector=%u lintHddOffset=%u lintDataLen=%u\n",lintSector,lintHddOffset,lintDataLen);
//HDD_Write(AllocatedSector, HDD_SectorSize-sizeof(psel->NextElement), psel->NextElement, sizeof(psel->NextElement));
FILE *ptr;
ptr = fopen("HDD.bin","r+b");
if(ptr!=NULL)
{
printf("HDD_Write(): Debug1\n");
fflush(stdout);
printf("fseek ..");
fflush(stdout);
fseek(ptr, lintSector*HDD_SectorSize+lintHddOffset, SEEK_SET );
printf("ok fwrite..");
fflush(stdout);
//--- segfault when called for second time
size_t res = fwrite(lintData,sizeof(lintData[0]),lintDataLen,ptr);
//fwrite(lintData,1,lintDataLen,ptr);
//----------------------
printf("ok\n");
fflush(stdout);
}
else printf("HDD_Write(): ptr is NULL\n");
fclose(ptr);
printf("HDD_Write() complete. \n\n");
}
The function is then called two times.
First for a block of 1022 bytes, which is performed successfully, then for a block of 2 bytes, which ends with segmentation fault.
I am trying to find the error cause for a few days now.. Can you give me a hint?