I encounter problems in a rather specific set of circumstances:
My program creates a new file, writes to the file, and then reads what it wrote itself. This fails if the file already exists (on a shared folder), but works fine if the file didn't exist. This is probably best illustrated with an example C program:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char buffer[1024];
int ret;
/* Open file test.txt in current dir as "read-write new binary file" */
FILE *fptr= fopen("test.txt","wb+");
if (fptr==NULL)
{
fprintf(stderr, "Error opening file\n");
exit(1);
}
memset(buffer,'a',1024);
ret = fwrite(buffer, 1, 1024, fptr);
printf("fwrite return (should be 1024): %d\n", ret);
ret=fseek(fptr, 512, 0);
printf("fseek return (should be 0): %d\n", ret);
ret=fread(buffer, 1, 512, fptr);
printf("fread return (should be 512): %d\n", ret);
/* return from main checking if fread did read 512 bytes */
return ret==512 ? 0 : 1;
}
write return (should be 1024): 1024 fseek return (should be 0): 0 fread return (should be 512): 512This creates a file test.txt (of size 1024). Rerunning the program now fails as test.txt already exists:
fwrite return (should be 1024): 1024 fseek return (should be 0): 0 fread return (should be 512): 0It works fine again once I remove test.txt, or of course if I run this program creating a file in a folder in the disk image. (It also fails if the existing file test.txt has zero size).
Note that the use of the "w+" flag for fopen is crucial for the bug to appear. If I use "r+", the program always succeeds.
System details: host Windows XP3, guest Ubuntu 10.4 and 11.4 (same behaviour), virtualbox 2.1.4
Contents of /etc/fstab to mount the shared folders on my ubuntu 11.4 guest:
Code: Select all
krisaaaaaa /home/kris/WINFILS vboxsf uid=1000,gid=1000 0 0
Thanks!
Kris