Skip to content

Commit

Permalink
Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386.
Browse files Browse the repository at this point in the history
The change incorporates the support of 64 bit time epoch conversion
from Windows NT time to Unix Epoch time on i386.

Addresses pull request:
#387
  • Loading branch information
johnwvmw committed Apr 19, 2022
1 parent 472335e commit 36eea63
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
3 changes: 3 additions & 0 deletions open-vm-tools/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ Miroslav Rezanina Fix issues using GCC 11 with gtk >= 3.20 and glib >=2.66.3

Marco Trevisan Update open-vm-tools to build with either Fuse 3 or Fuse 2
- https://github.com/vmware/open-vm-tools/pull/544

Bartosz Brachaczek Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386
- https://github.com/vmware/open-vm-tools/pull/387
42 changes: 19 additions & 23 deletions open-vm-tools/lib/hgfs/hgfsUtil.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 1998-2016 VMware, Inc. All rights reserved.
* Copyright (C) 1998-2016,2022 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
Expand Down Expand Up @@ -109,24 +109,7 @@ int
HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
uint64 ntTime) // IN: Time in Windows NT format
{
#ifdef __i386__
uint32 sec;
uint32 nsec;

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 (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,13 +118,26 @@ 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;
#else
if (sizeof unixTime->tv_sec == 4) {
uint32 sec,nsec;

/* 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;
}

Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
unixTime->tv_sec = sec;
unixTime->tv_nsec = nsec * 100;

return 0;
}
#endif

unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;
#endif

return 0;
}
Expand Down
34 changes: 15 additions & 19 deletions open-vm-tools/lib/misc/timeutil.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************
* Copyright (C) 1998-2021 VMware, Inc. All rights reserved.
* Copyright (C) 1998-2022 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
Expand Down Expand Up @@ -894,38 +894,34 @@ TimeUtil_NtTimeToUnixTime(struct timespec *unixTime, // OUT: Time in Unix forma
VmTimeType ntTime) // IN: Time in Windows NT format
{
ASSERT(unixTime);
#ifndef VM_64BIT
/* We assume that time_t is 32bit */
ASSERT(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;
}
#endif // ifndef VM_64BIT

if (ntTime < UNIX_EPOCH) {
unixTime->tv_sec = 0;
unixTime->tv_nsec = 0;
return -1;
}

#ifdef __i386__ // only for 32-bit x86
{
uint32 sec;
uint32 nsec;
#ifdef __i386__
if (sizeof unixTime->tv_sec == 4) {
uint32 sec,nsec;

/* 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;
}

Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
unixTime->tv_sec = sec;
unixTime->tv_nsec = nsec * 100;

return 0;
}
#else
#endif

unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;
#endif // __i386__

return 0;
}
Expand Down

0 comments on commit 36eea63

Please sign in to comment.