]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386.
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 19 Apr 2022 21:30:54 +0000 (14:30 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 19 Apr 2022 21:30:54 +0000 (14:30 -0700)
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

open-vm-tools/AUTHORS
open-vm-tools/lib/hgfs/hgfsUtil.c
open-vm-tools/lib/misc/timeutil.c

index bb6d0c663c3bb305f34bede4dab7d2db16785ad9..402512d093940c58742c4d2c86faa9605bd34065 100644 (file)
@@ -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
index cc580ab86ef3c967ce7bbc870a7ed6f5a65579ef..d6eddf4c0baeb0e4fe9c87c76c3bd15460891f4f 100644 (file)
@@ -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;
 }
index 55d597788cce404c6df56d52019c838b931e48f3..3e611cf89aacdb3e5f2784d7d1962aa1e9a4b40b 100644 (file)
@@ -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;
 }