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

Frank Mehnert frank.mehnert at oracle.com
Wed Feb 29 21:33:27 GMT 2012


Eugen,

actually this was a helpful investigation. Indeed the file modification
time is handled different between a Windows host and a Linux host when
using RTFileWrite and a Windows guest does apparently first open the
file, then sets the modification time and writes to that file afterwards.

The fix is probably to cache the file modification time and set it
before the file is closed (the Microsoft documentation for WriteFile
says that the file must be closed to get the file modification time
correctly applied).

Kind regards,

Frank

On Wednesday 29 February 2012 19:00:23 Eugen Labun wrote:
> 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/Shared
> Folders/vbsf.cpp#L1451 [3]
> https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/win/file
> io-win.cpp#L483 [4]
> https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/posix/fi
> leio-posix.cpp#L495 [5]
> https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/win/file
> io-win.cpp#L502 [6]
> https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Runtime/r3/posix/fi
> leio-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.
> 
> 
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> https://www.virtualbox.org/mailman/listinfo/vbox-dev

-- 
Dr.-Ing. Frank Mehnert
Senior Manager Software Development Desktop Virtualization, VirtualBox
ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | 71384 Weinstadt, Germany

Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
Geschäftsführer: Jürgen Kunz, Marcel van de Molen, Alexander van der Ven
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20120229/b6a20a76/attachment.sig>


More information about the vbox-dev mailing list