Opened 10 years ago

Last modified 4 years ago

#1118 new defect/bug

WinCE: fflush call does not have effect when cross compiled

Reported by: leonardohamada Owned by:
Priority: minor Milestone: version 0.6.0
Component: port/wince Version: git master
Severity: Keywords: gps, track, files



After a long time I was wondering/pondering why Navit was not saving the contents of the gps track log file, no matter how I set up the configuration parameters.

Try this if you can:

No mater how long Navit is running, if you suddenly cut the power source or remove the battery of the WinCE device without quitting or turning off gracefully, your log file will be incomplete and virtually useless.

I guess one of the developers, who has a WinCE device can find an easier way to replicate this.

The culprit:

Turns out that its a bug/defect/limitation on the fflush implementation used when cross-compiling Navit with arm-mingw32ce.

Then, if one could wrap the correct native OS function call, the problem should be mitigated by using the the code below.

	intptr_t file_handle;
     	file_handle =_get_osfhandle(fileno(file));
	if (INVALID_HANDLE_VALUE!=file_handle)

But in WinCE, you can use _fileno(file) that will return the native OS file handle, so the following is adequate fflush replacement for Navit, wrapped inside macro definitions for added guarantee.


for some discussion about this.

util_flush_os_file_buffer_wrap(FILE *_file)
#if defined(HAVE_API_WIN32_CE) && defined(__COREDLL__)
	FlushFileBuffers((HANDLE) _fileno(_file));

The developer more experienced with WinCE development could review/opine about this issue. Because I'm not experienced.


Certainly, having a usable track log is nice, isn't it?

Expected result:

The patch will give the most usable log data since last call to flush the file buffer. You can try the same procedure for bug replication after applying the patch and compiling Navit for confirmation of effectiveness.



Attachments (1)

wince_fflush_wrap.patch (1.6 KB) - added by leonardohamada 10 years ago.
fflush fix for WinCE

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by leonardohamada

fflush fix for WinCE

comment:1 Changed 10 years ago by tryagain


Actually, there are at least two levels of buffering.

High level buffering is done at FILE* stream level. Flushing it with fflush() simply passes stream level buffers to the write() function.

Data then becomes buffered on the lower level. That level is controlled by the OS kernel.

To write low-level buffer physically to the disk, you should call something like fsync.

FlushFileBuffers? is probably an MS equivalent of the above syscall. If fsync is supported on WINCE cross-compiling environment, we should better be using it.

We should call both fflush and then fsync to have data actually passed to the disk controller hardware.


comment:2 Changed 10 years ago by leonardohamada

Hi tryagain,

I guess then fflush() can be left alone for all platforms as it is currently.

Because valuable data should be written to disk, I think it is reasonable to be followed by a call to fsync() too.

But I after checking the man page for fsync(), it needs the <unistd.h> header.

On WinCE crosscompiler, there is a <unistd.h> but the declaration for fsync() doesn't exists there nor in the other headers after grepping the include directory.

Maybe a #ifdef compile time, platform selective macro is necessary? like to choose FlushFileBuffers?() for WinCE and fsync() for unix-like? What about normal Windows and Android?

I can gladly test, thanks.


comment:3 Changed 10 years ago by usul

  • Keywords gps track files added
  • Milestone set to version 0.5.1

Was there any progress here, or is this issue fixed already in current SVN?

comment:4 Changed 5 years ago by

  • Milestone changed from version 0.5.1 to version 0.5.2

This ticket was pushed back in order to bring 0.5.1 out soon.

comment:5 Changed 4 years ago by

  • Milestone changed from version 0.5.2 to version 0.6.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.