IFsObjInfo get timestamps

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
sadim
Posts: 4
Joined: 9. Aug 2014, 21:11

IFsObjInfo get timestamps

Post by sadim »

i need help with the IFsObjInfo Interface.
I try to get the timestamps st_atime, st_ctime and st_mtime of a file.

The problem is that the returned timestamps are wrong.

For example the function IFsObjInfo::modificationTime returned the timestamp 140734386631113

If i try to convert the timestamp with datetime.datetime.fromtimestamp(t) i got a ValueError exception "ValueError: timestamp out of range for platform localtime()/gmtime() function"


Is there any bug in the timestamp implementation?

I use Windows 8 64 Bit on the Host and the Guest is a Windows 7 64 Bit OS. I use the latest api version

Code: Select all


from vboxapi import VirtualBoxManager
import time
import os
import datetime

#This is a VirtualBox COM/XPCOM API client, no data needed.
wrapper = VirtualBoxManager(None, None)

#Get the VirtualBox manager
mgr = wrapper.mgr
#Get the global VirtualBox object
vbox = wrapper.vbox

#Getr the constants
vboxConstants = wrapper.constants

mach = vbox.findMachine("ForensicTestVM")

session = mgr.getSessionObject(vbox)

mach.lockMachine(session, vboxConstants.LockType_Shared)

# Acquire the VM's console and guest object

console = session.console
guest = console.guest

guestSession = guest.createSession("Administrator", "Heute0000", "", "vboxshell guest exec")
guestSession.waitFor(1,0)

path = os.path.abspath(r"C:\\bdlog.txt")

obj_info = guestSession.fileQueryInfo(path)

print obj_info.modificationTime

t = obj_info.modificationTime
print datetime.datetime.fromtimestamp(t)

Output:
140734386631113
Traceback (most recent call last):
File "E:/Dropbox/Dropbox/Master-Thesis/PycharmProjects/untitled2/test4.py", line 41, in <module>
print datetime.datetime.fromtimestamp(t)
ValueError: timestamp out of range for platform localtime()/gmtime() function
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: IFsObjInfo get timestamps

Post by noteirak »

Seems to me like the IFsObjInfo is reporting timestamp in nanoseconds/microseconds but that you are expecting the value in seconds or milliseconds in datetime.datetime.fromtimestamp(t)
Double check with the scope on the python side.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply