id summary reporter owner description type status priority component version resolution keywords cc guest host
9485 shared folders problem: IO to overwritten file (XP Home host) krthie "Hi
I am using XP Home Edition (fully patched) as host, running Ubuntu 11.4 as guest (but similar problems with Ubuntu 10.4) on VBox 4.1.2.
I encounter problems in a rather specific set of circumstances when using shared folders (a discussion of this problem is on the forum http://forums.virtualbox.org/viewtopic.php?f=3&t=44056&p=198273#p198223)
My program creates a new file, writes to the file, and then reads what it wrote itself. The read then fails if the file already exists (on a shared folder), but works fine if the file didn't exist.
For my latest tests, the shared folder is on d:\tmp (newly created) and permissions set to ""Full Access"" for everyone (set using Safe Mode). VBox runs as normal user ""kris"". I mounted the folder in Ubuntu as follows:
{{{
mkdir /home/kris/tmpmntD
sudo mount -t vboxsf -o uid=1000,gid=1000,rw dtmp /home/kris/tmpmntD
}}}
An example C program showing the problem:
{{{
#include
#include
#include
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;
}
}}}
When I run this program somewhere in a new directory on a shared-folder, the first time it works fine and reports:
{{{
write return (should be 1024): 1024
fseek return (should be 0): 0
fread return (should be 512): 512
}}}
This 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): 0
}}}
It 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.
" defect new major guest additions VirtualBox 4.1.2 shared folder IO Linux Windows