From: John Wolfe Date: Tue, 19 Apr 2022 21:30:54 +0000 (-0700) Subject: Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386. X-Git-Tag: stable-12.1.0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36eea633611e678f3ea17a913c0990f319135c48;p=thirdparty%2Fopen-vm-tools.git Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386. The change incorporates the support of 64 bit time epoch conversion from Windows NT time to Unix Epoch time on i386. Addresses pull request: https://github.com/vmware/open-vm-tools/pull/387 --- diff --git a/open-vm-tools/AUTHORS b/open-vm-tools/AUTHORS index bb6d0c663..402512d09 100644 --- a/open-vm-tools/AUTHORS +++ b/open-vm-tools/AUTHORS @@ -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 diff --git a/open-vm-tools/lib/hgfs/hgfsUtil.c b/open-vm-tools/lib/hgfs/hgfsUtil.c index cc580ab86..d6eddf4c0 100644 --- a/open-vm-tools/lib/hgfs/hgfsUtil.c +++ b/open-vm-tools/lib/hgfs/hgfsUtil.c @@ -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 @@ -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; @@ -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; } diff --git a/open-vm-tools/lib/misc/timeutil.c b/open-vm-tools/lib/misc/timeutil.c index 55d597788..3e611cf89 100644 --- a/open-vm-tools/lib/misc/timeutil.c +++ b/open-vm-tools/lib/misc/timeutil.c @@ -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 @@ -894,18 +894,6 @@ 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; @@ -913,19 +901,27 @@ TimeUtil_NtTimeToUnixTime(struct timespec *unixTime, // OUT: Time in Unix forma 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; }