Very weird C file-handling anomaly

Posted by KáGé on Stack Overflow See other posts from Stack Overflow or by KáGé
Published on 2010-05-09T16:57:08Z Indexed on 2010/05/09 17:08 UTC
Read the original article Hit count: 266

Filed under:
|
|
|
|

Hello,

I got a very weird issue that I cant figure out in my school project, which is the simulation of a simple filesystem in a human-readable textfile. Unfortunately I don't yet have enough time to translate the comments in my code or make it less gibberish, so if you are bothered by that, you don't have to help, I understand. See the code HERE.

Now in drive.h, at line 574 is this part:

     i = getline();

#ifdef DEBUG

 printf("Free space in all found at %d.\n\n", i);
 if(drive.disk != NULL){
     printf("Disk OK\n\n");
 }

#endif

 //write in data
 state = seekline(i);

Before this it finds place for the allocation database entry in the ALL sector (see the "image files" in the mounts folder, this issue was tested on mount_30.efs-dbf), then gets the line with i = getline() fine (getline is in lglobal.h, line 39), but after that any file manipulation (in this case seekline's fseek, but if I comment that out, then the first fprintf after that) crashes the program straight away. I think the file gets somehow corrupted (though the Disk OK message appears) but can't figure out how.

I've tried putting i = getline(); into comment, but it didn't make any difference. I've also tried asking at local programming forums but they didn't really help either.

The last few lines of the output before it crashes:

Dir written. (drive.h line 562)

Seekline entered: 268 (called at drive.h line 564)

Getline entered. (called at drive.h line 574)

Line got: 268.

Free space in all found at 268. (drive.h line 576)

Seekline entered: 268 (called at drive.h line 582, note that this exact call was run successfully less than 20 lines back. This one should set the pointer to the beginning of the line it is currently in)

After this it crashes.

Does anyone has any idea of what causes this and how could I fix it? Thank you.

© Stack Overflow or respective owner

Related posts about c

    Related posts about file-io