I have a strange behaviour when writing files to shared folders on the host system.
The configuration is:
host: Windows-XP
guest: Linux, Debian, 2.6.22 (lenny / testing)
gcc on guest: 4.2.3
When using this simple test program, compiled on the guest linux system:
#include <iostream>
#include <iomanip>
#include <fstream>
int main(int argc, char *argv[])
{
char buf[5000];
for (int i=0;i<5000;i++) buf[i]=1;
std::ofstream os("out", std::ios::binary | std::ios::out);
os.write(buf, 1024);
os << "end" << std::endl;
}
The program writes only 'zeros' instead of 'ones' when the output is a shared
host folder (ntfs, mount options: "rw,exec,suid,dev"). This happens when the number
of bytes written is >=1024. For chunks smaller than 1023, it works ok. It also
works ok, if the output is on the guest file-system.
If the last line is removed (the file output is not flushed), no output is written
at all (zero-length file). The ios::bad flag is not set after writing, claiming
that everything went ok.
Replacing the ofstream output with fwrite-based code works ok for all sizes.
Not sure, if this is a stdc++ problem or a VirtualBox problem, but since the
problem occurs with several gcc versions and only appears when writing to the
host filesystem, it seems to be related to VirtualBox.