[vbox-dev] Possibly a way to fix Ticket #6473 Wrong timestamp for files write in shared folders

Eugen Labun labun at gmx.net
Wed Feb 29 18:00:23 GMT 2012


Dear All,

I investigated the bug "#6473 Wrong timestamp for files write in shared folders" [1] a bit.
Hope this info could help to fix it.


One and the same VM (WinXP) has been run on a Windows host (Win7 32bit) and on a Linux host (Ubuntu 
11.10) using VirtualBox 4.1.8. The last guest additions (4.1.8) are installed in the guest OS.


Observations:
- The bug with wrong timestamps only exists on the Linux host, on Windows is all OK!
- If (filesize==0) then the timestamp is correct even on the Linux host (this has been also reported 
by skosner in [1]).

That is, the file will be *created* with proper attribites! Only after its content is written into 
(i.e. if filesize > 0), the timestamp gets resetted to the current one in case of Linux host!



So I looked into the sources and found that VBox uses RTFileWrite for actual file writing [2].

The Windows implementation of RTFileWrite is here [3], the one used by Linux here [4] (please 
correct me if I'm wrong!). The only real difference between is that the Windows impl. calls 
´WriteFile´ [5], and the Linux impl. calls ´write´.


And here IMO is the root of the problem: whereas ´WriteFile´ doesn't alter file attributes (at least 
not in my test environment), the Linux' ´write´ always resets the timestamp!

More specifically, the ´write´ resets the "modified"(st_mtime) and "created"(st_ctime) parts, as 
explicitly stated here [7].



Unfortunately, I'm not experienced in Linux system programming, so cannot provide a patch. The ´cp 
-p´ command or copy with GNOME's Nautilus are known to copy files preserving their attributes.

Perhaps, VirtualBox could also use the same (or similar) technique that it uses for file creation 
(remember, files of 0 bytes have correct timestamps) for correction of attributes *after* applying 
RTFileWrite (here [2])?



Hope this old and very annoying bug will be eventually fixed.



Best regards,
Eugen Labun




[1] https://www.virtualbox.org/ticket/6473
[2] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp#L1451
[3] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/win/fileio-win.cpp#L483
[4] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp#L495
[5] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/win/fileio-win.cpp#L502
[6] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp#L514
[7] Michael Kerrisk. "The Linux programming interface: a Linux and UNIX system programming 
handbook". 2010.
     See "Table 15-2: Effect of various functions on file timestamps" on p. 286.





More information about the vbox-dev mailing list