FS#5452 - Some file creation operations fail in the simulators

Attached to Project: Rockbox
Opened by Malcolm Tyrrell (Malcohol) - Sunday, 28 May 2006, 13:56 GMT
Task Type Bugs
Category Simulator
Status Closed
Assigned To Dan Everton (safetydan)
Operating System All players
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


I'm running the siulator in Debian GNU/Linux with a 2.6.16 kernel. I've
got simulators set up for several of the devices, and the bug exists in
all of them. I'm phyically running rockbox on an iAudio X5L (not that
that matters much for this bug report).

Example of problem:
Brickmania highscores, eq settings, etc are not being saved properly
in the simulator.

Files are being created in the wrong mode. Looking through the sources, I
see that the creat function (and correspondingly sim_creat in the
simulator) are usually called with the mode O_WRONLY. This works fine in
both simulator and on my X5.

However, at the places listed below the numeric constant 0 is used as the
mode. For the instances I've been able to try, they work on the X5, but
fail in the simulator.

apps/eq_menu.c: fd = creat(filename,0);
apps/plugins/battery_test.c: f = rb->creat("/battery.dummy", 0);
apps/plugins/calendar.c: fq = rb->creat("/.rockbox/~temp", 0);
apps/plugins/calendar.c: fp = rb->creat("/.rockbox/.memo", 0);
apps/plugins/configfile.c: fd = cfg_rb->creat(buf, 0);
apps/plugins/iriverify.c: fd = rb->creat(tmpfilename, 0);
apps/plugins/search.c: fdw = rb->creat(resultfile,0);
apps/plugins/sort.c: fd = rb->creat(tmpfilename, 0);
apps/settings.c: fd = creat(filename,0);
apps/tree.c: fd = creat(filename,0);
firmware/font.c: glyph_file = creat(GLYPH_CACHE_FILE, 0);

It seems likely that changing 0 to O_WRONLY in the above would fix the
problem in the short term. I won't submit a patch for this, as I don't yet
feel that I fully understanding the issues.

A little more exploring suggests that there's a weirdness about how the
simulator views file modes. In uisimulator/common/io.c, the function
rockbox2sim is clearly intended to converts a mode_t for a real device
into a mode_t for the simulator. The code shows that the simulator expects
1 to correspond to a WRONLY mode, not 0.

I can't find a place where these mode values are documented (which doesn't
mean there isn't one). However, if the logic of the modes really is
different between the versions, then perhaps Rockbox should define it's
own modes which get #defined one way for the simulators and another way
for the device. (Of course, this may already be what's happening, since
O_WRONLY works on both simulator and device.)
This task depends upon

Closed by  Dan Everton (safetydan)
Tuesday, 30 May 2006, 11:32 GMT
Reason for closing:  Fixed
Additional comments about closing:  This should now be fixed in CVS builds.
Comment by Dan Everton (safetydan) - Tuesday, 30 May 2006, 11:26 GMT
0 is actually O_RDONLY so the rockbox2sim function is working correctly. It's all those creat() calls that are wrong.