/usr/src/open-vm-tools-10.0.7/vmhgfs/hgfsUtil.c is in open-vm-tools-dkms 2:10.0.7-3227872-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | /*********************************************************
* Copyright (C) 1998-2015 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
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/*********************************************************
* The contents of this file are subject to the terms of the Common
* Development and Distribution License (the "License") version 1.0
* and no later version. You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* http://www.opensource.org/licenses/cddl1.php
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
*********************************************************/
/*
* hgfsUtil.c --
*
* Utility routines used by both HGFS servers and clients, such as
* conversion routines between Unix time and Windows NT time.
* The former is in units of seconds since midnight 1/1/1970, while the
* latter is in units of 100 nanoseconds since midnight 1/1/1601.
*/
/*
* hgfsUtil.h must be included before vm_basic_asm.h, as hgfsUtil.h
* includes kernel headers on Linux. That is, vmware.h must come after
* hgfsUtil.h.
*/
#include "hgfsUtil.h"
#include "vmware.h"
#include "vm_basic_asm.h"
#ifndef _WIN32
/*
* NT time of the Unix epoch:
* midnight January 1, 1970 UTC
*/
#define UNIX_EPOCH ((((uint64)369 * 365) + 89) * 24 * 3600 * 10000000)
/*
* NT time of the Unix 32 bit signed time_t wraparound:
* 03:14:07 January 19, 2038 UTC
*/
#define UNIX_S32_MAX (UNIX_EPOCH + (uint64)0x80000000 * 10000000)
/*
*-----------------------------------------------------------------------------
*
* HgfsConvertToNtTime --
*
* Convert from Unix time to Windows NT time.
*
* Results:
* The time in Windows NT format.
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
uint64
HgfsConvertToNtTime(time_t unixTime, // IN: Time in Unix format (seconds)
long nsec) // IN: nanoseconds
{
return (uint64)unixTime * 10000000 + nsec / 100 + UNIX_EPOCH;
}
/*
*-----------------------------------------------------------------------------
*
* HgfsConvertFromNtTimeNsec --
*
* Convert from Windows NT time to Unix time. If NT time is outside of
* UNIX time range (1970-2038), returned time is nearest time valid in
* UNIX.
*
* Results:
* 0 on success
* non-zero if NT time is outside of valid range for UNIX
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
int
HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
uint64 ntTime) // IN: Time in Windows NT format
{
#if !defined(VM_X86_64) && !defined(__arm__)
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;
unixTime->tv_nsec = 0;
return -1;
}
#if !defined(VM_X86_64) && !defined(__arm__)
Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
unixTime->tv_sec = sec;
unixTime->tv_nsec = nsec * 100;
#else
unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;
#endif
return 0;
}
/*
*-----------------------------------------------------------------------------
*
* HgfsConvertFromNtTime --
*
* Convert from Windows NT time to Unix time.
*
* Results:
* 0 on success
* nonzero if time is not representable on UNIX
*
* Side effects:
* None
*
*-----------------------------------------------------------------------------
*/
int
HgfsConvertFromNtTime(time_t *unixTime, // OUT: Time in UNIX format
uint64 ntTime) // IN: Time in Windows NT format
{
struct timespec tm;
int ret;
ret = HgfsConvertFromNtTimeNsec(&tm, ntTime);
*unixTime = tm.tv_sec;
return ret;
}
#endif /* !def(_WIN32) */
#undef UNIX_EPOCH
#undef UNIX_S32_MAX
/*
*-----------------------------------------------------------------------------
*
* HgfsConvertFromInternalStatus --
*
* This function converts between a platform-specific status code and a
* cross-platform status code to be sent down the wire.
*
* Results:
* Converted status code.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
#ifdef _WIN32
HgfsStatus
HgfsConvertFromInternalStatus(HgfsInternalStatus status) // IN
{
switch(status) {
case ERROR_SUCCESS:
return HGFS_STATUS_SUCCESS;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
return HGFS_STATUS_NO_SUCH_FILE_OR_DIR;
case ERROR_INVALID_HANDLE:
return HGFS_STATUS_INVALID_HANDLE;
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
return HGFS_STATUS_FILE_EXISTS;
case ERROR_DIR_NOT_EMPTY:
return HGFS_STATUS_DIR_NOT_EMPTY;
case RPC_S_PROTOCOL_ERROR:
return HGFS_STATUS_PROTOCOL_ERROR;
case ERROR_ACCESS_DENIED:
return HGFS_STATUS_ACCESS_DENIED;
case ERROR_INVALID_NAME:
return HGFS_STATUS_INVALID_NAME;
case ERROR_SHARING_VIOLATION:
return HGFS_STATUS_SHARING_VIOLATION;
case ERROR_DISK_FULL:
case ERROR_HANDLE_DISK_FULL:
return HGFS_STATUS_NO_SPACE;
case ERROR_NOT_SUPPORTED:
return HGFS_STATUS_OPERATION_NOT_SUPPORTED;
case ERROR_INVALID_PARAMETER:
return HGFS_STATUS_INVALID_PARAMETER;
case ERROR_NOT_SAME_DEVICE:
return HGFS_STATUS_NOT_SAME_DEVICE;
case ERROR_FILENAME_EXCED_RANGE:
return HGFS_STATUS_NAME_TOO_LONG;
case ERROR_CONNECTION_INVALID: // HGFS_ERROR_STALE_SESSION
return HGFS_STATUS_STALE_SESSION;
case ERROR_MAX_SESSIONS_REACHED:
return HGFS_STATUS_TOO_MANY_SESSIONS;
case ERROR_INTERNAL_ERROR:
case HGFS_INTERNAL_STATUS_ERROR:
default:
return HGFS_STATUS_GENERIC_ERROR;
}
}
#else /* Win32 */
HgfsStatus
HgfsConvertFromInternalStatus(HgfsInternalStatus status) // IN
{
switch(status) {
case 0:
return HGFS_STATUS_SUCCESS;
case ENOENT:
return HGFS_STATUS_NO_SUCH_FILE_OR_DIR;
case EBADF:
return HGFS_STATUS_INVALID_HANDLE;
case EPERM:
return HGFS_STATUS_OPERATION_NOT_PERMITTED;
case EISDIR:
case EEXIST:
return HGFS_STATUS_FILE_EXISTS;
case ENOTDIR:
return HGFS_STATUS_NOT_DIRECTORY;
case ENOTEMPTY:
return HGFS_STATUS_DIR_NOT_EMPTY;
case EPROTO:
return HGFS_STATUS_PROTOCOL_ERROR;
case EACCES:
return HGFS_STATUS_ACCESS_DENIED;
case EINVAL:
return HGFS_STATUS_INVALID_NAME;
case ENOSPC:
return HGFS_STATUS_NO_SPACE;
case EOPNOTSUPP:
return HGFS_STATUS_OPERATION_NOT_SUPPORTED;
case ENAMETOOLONG:
return HGFS_STATUS_NAME_TOO_LONG;
case EPARAMETERNOTSUPPORTED:
return HGFS_STATUS_INVALID_PARAMETER;
case EXDEV:
return HGFS_STATUS_NOT_SAME_DEVICE;
case ENETRESET: // HGFS_ERROR_STALE_SESSION
return HGFS_STATUS_STALE_SESSION;
case ECONNREFUSED:
return HGFS_STATUS_TOO_MANY_SESSIONS;
case EINTERNAL:
case HGFS_INTERNAL_STATUS_ERROR:
default:
return HGFS_STATUS_GENERIC_ERROR;
}
}
#endif
|