292 LARGE_INTEGER modTime; 293 FILETIME t; 294 HANDLE h; 295 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); 296 if (pathbuf == NULL) 297 return rv; 298 h = CreateFileW(pathbuf, 299 /* Device query access */ 300 0, 301 /* Share it */ 302 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 303 /* No security attributes */ 304 NULL, 305 /* Open existing or fail */ 306 OPEN_EXISTING, 307 /* Backup semantics for directories */ 308 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 309 /* No template file */ 310 NULL); 311 if (h != INVALID_HANDLE_VALUE) { 312 GetFileTime(h, NULL, NULL, &t); 313 CloseHandle(h); 314 modTime.LowPart = (DWORD) t.dwLowDateTime; 315 modTime.HighPart = (LONG) t.dwHighDateTime; 316 rv = modTime.QuadPart / 10000; 317 rv -= 11644473600000; 318 } 319 free(pathbuf); 320 return rv; 321 } 322 323 JNIEXPORT jlong JNICALL 324 Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file) 325 { 326 jlong rv = 0; 327 WIN32_FILE_ATTRIBUTE_DATA wfad; 328 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); 329 if (pathbuf == NULL) 330 return rv; 331 if (GetFileAttributesExW(pathbuf, 332 GetFileExInfoStandard, 333 &wfad)) { 334 rv = wfad.nFileSizeHigh * ((jlong)MAXDWORD + 1) + wfad.nFileSizeLow; 335 } else { 336 if (GetLastError() == ERROR_SHARING_VIOLATION) { 337 /* The error is "share violation", which means the file/dir 338 must exists. Try _wstati64, we know this at least works | 292 LARGE_INTEGER modTime; 293 FILETIME t; 294 HANDLE h; 295 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); 296 if (pathbuf == NULL) 297 return rv; 298 h = CreateFileW(pathbuf, 299 /* Device query access */ 300 0, 301 /* Share it */ 302 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 303 /* No security attributes */ 304 NULL, 305 /* Open existing or fail */ 306 OPEN_EXISTING, 307 /* Backup semantics for directories */ 308 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 309 /* No template file */ 310 NULL); 311 if (h != INVALID_HANDLE_VALUE) { 312 if (GetFileTime(h, NULL, NULL, &t)) { 313 modTime.LowPart = (DWORD) t.dwLowDateTime; 314 modTime.HighPart = (LONG) t.dwHighDateTime; 315 rv = modTime.QuadPart / 10000; 316 rv -= 11644473600000; 317 } 318 CloseHandle(h); 319 } 320 free(pathbuf); 321 return rv; 322 } 323 324 JNIEXPORT jlong JNICALL 325 Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file) 326 { 327 jlong rv = 0; 328 WIN32_FILE_ATTRIBUTE_DATA wfad; 329 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); 330 if (pathbuf == NULL) 331 return rv; 332 if (GetFileAttributesExW(pathbuf, 333 GetFileExInfoStandard, 334 &wfad)) { 335 rv = wfad.nFileSizeHigh * ((jlong)MAXDWORD + 1) + wfad.nFileSizeLow; 336 } else { 337 if (GetLastError() == ERROR_SHARING_VIOLATION) { 338 /* The error is "share violation", which means the file/dir 339 must exists. Try _wstati64, we know this at least works |