Error in FAT16 component?

Moderator: Benj

Post Reply
Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Error in FAT16 component?

Post by Eric »

Hello,

I am afraid there still is an error in the FAT16 component when the total number of sektors written to the Media Card exceeds the 65536 boundary.
Awhile ago I created a datalogging system which recorded central heating data over an extended period of time on a 512 Meg SD Card. Each time the datalogger was started or the mediacard was inserted/removed, it created a new datestamped .csv logfile, wrote a fileheader and started logging at a 1 second rate. Every record starts with a Date/time log.
This went well in the beginning until I noticed that after a certain amount of newly created logfiles, the information on the mediacard became disrupted in a way that from a certain point the logger effectively created a new filename but started to overwrite the first file in the root directory instead of filling the new created logfile. The longer this situation lasted, the more logfiles became disrupted until the whole logging became unusable.
Further investigation showed me that it was not the number of created files that triggered the problem, but the total number of bytes written to the card or respectively the total number of sektors.
I tried with another mediacard of 2 gig and was able to reproduce the phenomenon.
Using WinHex noticed that the moment the number of written sektors exceeded 65536, this problem appeared.
I can send you a zipped diskmage made with WinHex of the 512 mediacard by email. ( it is 1 Mega so too big to attach ) There you can see what is goiing on.
You will notice 13 logfiles: the first beeing 081110_2.csv and the last 141110_0.csv.
The first 3 files are already overwritten by the last 3 created files. You can see that because there is no header.
The next 7 files are ok, here the header is still intact. They are not yet overwritten but that will happen if I had waiten longer.
The last 3 files are created, have the correct filesize, but are empty. The contents of these files have overwritten the first 3 files. You can see this if you look at the datestamp wich is recorded at the start of each record.
Also looking at WinHex you can see that as long the total number of sektors does not exceed 65536, there is no problem.
Once this limit is exceeded, the next created file starts overwriting the first one.
And it is reproducable.
I think there is a datatype error in the FAT 16 routine "Move to next sektor"

I hope I have submitted enough information to enable you to investigate the problem.
I haven't tried the FAT32 because of memory limits.

Best regards,

Eric

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in FAT16 component?

Post by Benj »

Hello Eric,

Many thanks for your findings. I will sit down with the code when I next get 10 mins free and see if I can find and solve the problem for you. I take it you are using the latest version of the component code downloaded from this forum topic.

http://www.matrixmultimedia.com/mmforum ... 498#p19450

My guess is that because the wrap around is at 65536 bytes that I have missed a "(long)" from one of the calculations that must be there to force the 32-bit calculation.

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Error in FAT16 component?

Post by Eric »

Hi Ben,

Thanks for your reply.
Yes, I am using the component code mentioned in that post.

Regards,

Eric

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in FAT16 component?

Post by Benj »

Hello Eric,

Please would you give this updated component code file a go and see if this fixes the problem you are having.
Attachments
PIC_FAT16.c
(51.77 KiB) Downloaded 430 times

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Error in FAT16 component?

Post by Eric »

Ok Ben, I will keep you informed. It will take a few days.

Rgds,

Eric

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Error in FAT16 component?

Post by Eric »

Hello Ben,

The problem is still there.
See attachement: were the zero's begin, it continued logging by overwriting the first file.

Best regards,

Eric
Attachments
snap0793.rar
(123.48 KiB) Downloaded 403 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in FAT16 component?

Post by Benj »

Hi Eric,

Ok thanks back to the drawing board then. I will have another look at the c file and see if I can spot any other potential 16-bit calculations that should be 32-bit. From what I have seen so-far the problem lies in the "move to next sector" function.

Post Reply