FS#1481 - Possible bug in fat.c

Attached to Project: Rockbox
Opened by Craig Sather (rb_dev) - Sunday, 29 June 2003, 05:58 GMT
Last edited by Linus Nielsen Feltzing (linusnielsen) - Friday, 05 November 2004, 07:00 GMT
Task Type Bugs
Status Closed
Assigned To No-one
Operating System
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


I posted this to the mailing list for comment but got
no response, so I am turning it into an official bug


At line 406 of fat.c, inside of function fat_mount()
is this bit of code :

/* calculate freecount if unset */
if ( fat_bpb.fsinfo.freecount == 0xffffffff )

There seems to be something wrong with calling
fat_recalc_free() from this point. When I modified the
if statement so that fat_recalc_free() was always
called, something is amiss.

When fat_recalc_free() gets called during the disk
mount at bootup, the lcd backlight goes off while the
fat recalc is taking place and then comes back on. I
have a long backlight timeout so it's not the normal
backlight timeout.

When fat_recalc_free() is called during the disk mount
at the end of a USB session it's even worse. Rockbox
crashes with the following display:

at 0002FDA0

Even in the case when it doesn't crash, the fact that
the lcd backlight goes off and on indicates that
something isn't right with either execution of this

I know that fat_recalc_free() works when called from
other places because it works OK when it is called
from the debug menu and I also added a call to it from
elsewhere in the code that works OK.

I'm guessing that either this piece of code has never
been exercised and that for some reason there is a
problem with calling fat_recalc_free() from inside
fat_mount() (stack overflow maybe?), or possibly that
I have some strange timing issue with my hardware that
causes the buggy behavior only when called from this
one place in the code.
This task depends upon

Closed by  Linus Nielsen Feltzing (linusnielsen)
Friday, 05 November 2004, 07:00 GMT
Reason for closing:  Fixed
Comment by Linus Nielsen Feltzing (linusnielsen) - Thursday, 25 March 2004, 14:19 GMT

The settings aren't read from RTC/disk until after the disk
initialization, hence the short backlight timeout. The crash
when fat_mount() was called from the USB thread was a stack
overflow, as you suspected. I have fixed the crash in CVS,
but I'll leave the backlight issue for now.