0012-Make-HgfsConvertFromNtTimeNsec-aware-of-64-bit-time_.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From 3f0580f2546de8be7acf1bc78a55a257bc638ebe Mon Sep 17 00:00:00 2001
  2. From: Bartosz Brachaczek <b.brachaczek@gmail.com>
  3. Date: Tue, 12 Nov 2019 14:31:08 +0100
  4. Subject: [PATCH] Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386
  5. I verified that this function behaves as expected on x86_64, i386 with
  6. 32-bit time_t, and i386 with 64-bit time_t for the following values of
  7. ntTtime:
  8. UNIX_EPOCH-1, UNIX_EPOCH, UNIX_EPOCH+1, UNIX_S32_MAX-1, UNIX_S32_MAX,
  9. UNIX_S32_MAX+1, UNIX_S32_MAX*2+1
  10. I did not verify whether the use of Div643264 is optimal, performance
  11. wise.
  12. Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
  13. ---
  14. lib/hgfs/hgfsUtil.c | 34 +++++++++++++++++++---------------
  15. 1 file changed, 19 insertions(+), 15 deletions(-)
  16. diff --git a/lib/hgfs/hgfsUtil.c b/lib/hgfs/hgfsUtil.c
  17. index cc580ab8..49b10040 100644
  18. --- a/lib/hgfs/hgfsUtil.c
  19. +++ b/lib/hgfs/hgfsUtil.c
  20. @@ -110,23 +110,21 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
  21. uint64 ntTime) // IN: Time in Windows NT format
  22. {
  23. #ifdef __i386__
  24. - uint32 sec;
  25. - uint32 nsec;
  26. + uint64 sec64;
  27. + uint32 sec32, nsec;
  28. +#endif
  29. ASSERT(unixTime);
  30. - /* We assume that time_t is 32bit */
  31. - ASSERT_ON_COMPILE(sizeof (unixTime->tv_sec) == 4);
  32. - /* Cap NT time values that are outside of Unix time's range */
  33. + if (sizeof (unixTime->tv_sec) == 4) {
  34. + /* Cap NT time values that are outside of Unix time's range */
  35. - if (ntTime >= UNIX_S32_MAX) {
  36. - unixTime->tv_sec = 0x7FFFFFFF;
  37. - unixTime->tv_nsec = 0;
  38. - return 1;
  39. + if (ntTime >= UNIX_S32_MAX) {
  40. + unixTime->tv_sec = 0x7FFFFFFF;
  41. + unixTime->tv_nsec = 0;
  42. + return 1;
  43. + }
  44. }
  45. -#else
  46. - ASSERT(unixTime);
  47. -#endif
  48. if (ntTime < UNIX_EPOCH) {
  49. unixTime->tv_sec = 0;
  50. @@ -135,9 +133,15 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
  51. }
  52. #ifdef __i386__
  53. - Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
  54. - unixTime->tv_sec = sec;
  55. - unixTime->tv_nsec = nsec * 100;
  56. + if (sizeof (unixTime->tv_sec) == 4) {
  57. + Div643232(ntTime - UNIX_EPOCH, 10000000, &sec32, &nsec);
  58. + unixTime->tv_sec = sec32;
  59. + unixTime->tv_nsec = nsec * 100;
  60. + } else {
  61. + Div643264(ntTime - UNIX_EPOCH, 10000000, &sec64, &nsec);
  62. + unixTime->tv_sec = sec64;
  63. + unixTime->tv_nsec = nsec * 100;
  64. + }
  65. #else
  66. unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
  67. unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;
  68. --
  69. 2.25.1