Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386 #387

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions open-vm-tools/lib/hgfs/hgfsUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,21 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
uint64 ntTime) // IN: Time in Windows NT format
{
#ifdef __i386__
uint32 sec;
uint32 nsec;
uint64 sec64;
uint32 sec32, nsec;
#endif

ASSERT(unixTime);
/* We assume that time_t is 32bit */
ASSERT_ON_COMPILE(sizeof (unixTime->tv_sec) == 4);

/* Cap NT time values that are outside of Unix time's range */
if (sizeof (unixTime->tv_sec) == 4) {
/* Cap NT time values that are outside of Unix time's range */

if (ntTime >= UNIX_S32_MAX) {
unixTime->tv_sec = 0x7FFFFFFF;
unixTime->tv_nsec = 0;
return 1;
if (ntTime >= UNIX_S32_MAX) {
unixTime->tv_sec = 0x7FFFFFFF;
unixTime->tv_nsec = 0;
return 1;
}
}
#else
ASSERT(unixTime);
#endif

if (ntTime < UNIX_EPOCH) {
unixTime->tv_sec = 0;
Expand All @@ -135,9 +133,15 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
}

#ifdef __i386__
Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
unixTime->tv_sec = sec;
unixTime->tv_nsec = nsec * 100;
if (sizeof (unixTime->tv_sec) == 4) {
Div643232(ntTime - UNIX_EPOCH, 10000000, &sec32, &nsec);
unixTime->tv_sec = sec32;
unixTime->tv_nsec = nsec * 100;
} else {
Div643264(ntTime - UNIX_EPOCH, 10000000, &sec64, &nsec);
unixTime->tv_sec = sec64;
unixTime->tv_nsec = nsec * 100;
}
#else
unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;
Expand Down