< prev index next >

src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c

Print this page

 214     } else {
 215         securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
 216         securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor;
 217         securityAttributes.bInheritHandle = FALSE;
 218         lpSecurityAttributes = &securityAttributes;
 219     }
 220 
 221     handle = CreateFileW(lpFileName,
 222                         (DWORD)dwDesiredAccess,
 223                         (DWORD)dwShareMode,
 224                         lpSecurityAttributes,
 225                         (DWORD)dwCreationDisposition,
 226                         (DWORD)dwFlagsAndAttributes,
 227                         NULL);
 228     if (handle == INVALID_HANDLE_VALUE) {
 229         throwWindowsException(env, GetLastError());
 230     }
 231     return ptr_to_jlong(handle);
 232 }
 233 
 234 
 235 JNIEXPORT void JNICALL
 236 Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlSetSparse(JNIEnv* env, jclass this,
 237     jlong handle)
 238 {
 239     DWORD bytesReturned;
 240     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 241     if (DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytesReturned, NULL) == 0) {
 242         throwWindowsException(env, GetLastError());
 243     }
 244 }
 245 
 246 JNIEXPORT void JNICALL
 247 Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlGetReparsePoint(JNIEnv* env, jclass this,
 248     jlong handle, jlong bufferAddress, jint bufferSize)
 249 {
 250     DWORD bytesReturned;
 251     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 252     LPVOID outBuffer = (LPVOID)jlong_to_ptr(bufferAddress);
 253 
 254     if (DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, NULL, 0, outBuffer, (DWORD)bufferSize,

 341     } else {
 342         throwWindowsException(env, GetLastError());
 343     }
 344 }
 345 
 346 JNIEXPORT jlong JNICALL
 347 Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile1(JNIEnv* env, jclass this,
 348     jlong pathAddress, jlong dataAddress)
 349 {
 350     LPCWSTR lpFileName = jlong_to_ptr(pathAddress);
 351     WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);
 352 
 353     HANDLE handle = FindFirstFileW(lpFileName, data);
 354     if (handle == INVALID_HANDLE_VALUE) {
 355         throwWindowsException(env, GetLastError());
 356     }
 357     return ptr_to_jlong(handle);
 358 }
 359 
 360 JNIEXPORT jstring JNICALL
 361 Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile(JNIEnv* env, jclass this,
 362     jlong handle, jlong dataAddress)
 363 {
 364     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 365     WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);
 366 
 367     if (FindNextFileW(h, data) != 0) {
 368         return (*env)->NewString(env, data->cFileName, (jsize)wcslen(data->cFileName));
 369     } else {
 370     if (GetLastError() != ERROR_NO_MORE_FILES)
 371         throwWindowsException(env, GetLastError());
 372         return NULL;
 373     }
 374 }
 375 
 376 JNIEXPORT void JNICALL
 377 Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass this,
 378     jlong address, jobject obj)
 379 {
 380     WIN32_FIND_STREAM_DATA data;
 381     LPCWSTR lpFileName = jlong_to_ptr(address);

 384     handle = FindFirstStreamW(lpFileName, FindStreamInfoStandard, &data, 0);
 385     if (handle != INVALID_HANDLE_VALUE) {
 386         jstring name = (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
 387         if (name == NULL) {
 388             FindClose(handle);
 389             return;
 390         }
 391         (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
 392         (*env)->SetObjectField(env, obj, findStream_name, name);
 393     } else {
 394         if (GetLastError() == ERROR_HANDLE_EOF) {
 395              (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
 396         } else {
 397             throwWindowsException(env, GetLastError());
 398         }
 399     }
 400 
 401 }
 402 
 403 JNIEXPORT jstring JNICALL
 404 Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream(JNIEnv* env, jclass this,
 405     jlong handle)
 406 {
 407     WIN32_FIND_STREAM_DATA data;
 408     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 409 
 410     if (FindNextStreamW(h, &data) != 0) {
 411         return (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
 412     } else {
 413         if (GetLastError() != ERROR_HANDLE_EOF)
 414             throwWindowsException(env, GetLastError());
 415         return NULL;
 416     }
 417 }
 418 
 419 
 420 JNIEXPORT void JNICALL
 421 Java_sun_nio_fs_WindowsNativeDispatcher_FindClose(JNIEnv* env, jclass this,
 422     jlong handle)
 423 {
 424     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 425     if (FindClose(h) == 0) {
 426         throwWindowsException(env, GetLastError());
 427     }
 428 }
 429 
 430 
 431 JNIEXPORT void JNICALL
 432 Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle(JNIEnv* env, jclass this,
 433     jlong handle, jlong address)
 434 {
 435     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 436     BY_HANDLE_FILE_INFORMATION* info =
 437         (BY_HANDLE_FILE_INFORMATION*)jlong_to_ptr(address);
 438     if (GetFileInformationByHandle(h, info) == 0) {
 439         throwWindowsException(env, GetLastError());
 440     }
 441 }
 442 
 443 
 444 JNIEXPORT void JNICALL
 445 Java_sun_nio_fs_WindowsNativeDispatcher_CopyFileEx0(JNIEnv* env, jclass this,
 446     jlong existingAddress, jlong newAddress, jint flags, jlong cancelAddress)
 447 {
 448     LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress);
 449     LPCWSTR lpNewFileName = jlong_to_ptr(newAddress);
 450     LPBOOL cancel = (LPBOOL)jlong_to_ptr(cancelAddress);
 451     if (CopyFileExW(lpExistingFileName, lpNewFileName, NULL, NULL, cancel,
 452                     (DWORD)flags) == 0)

 496     LPCWSTR lpFileName = jlong_to_ptr(address);
 497     if (SetFileAttributesW(lpFileName, (DWORD)value) == 0) {
 498         throwWindowsException(env, GetLastError());
 499     }
 500 }
 501 
 502 JNIEXPORT void JNICALL
 503 Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributesEx0(JNIEnv* env, jclass this,
 504     jlong pathAddress, jlong dataAddress)
 505 {
 506     LPCWSTR lpFileName = jlong_to_ptr(pathAddress);
 507     WIN32_FILE_ATTRIBUTE_DATA* data = (WIN32_FILE_ATTRIBUTE_DATA*)jlong_to_ptr(dataAddress);
 508 
 509     BOOL res = GetFileAttributesExW(lpFileName, GetFileExInfoStandard, (LPVOID)data);
 510     if (res == 0)
 511         throwWindowsException(env, GetLastError());
 512 }
 513 
 514 
 515 JNIEXPORT void JNICALL
 516 Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime(JNIEnv* env, jclass this,
 517     jlong handle, jlong createTime, jlong lastAccessTime, jlong lastWriteTime)
 518 {
 519     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 520 
 521     if (SetFileTime(h,
 522         (createTime == (jlong)-1) ? NULL : (CONST FILETIME *)&createTime,
 523         (lastAccessTime == (jlong)-1) ? NULL : (CONST FILETIME *)&lastAccessTime,
 524         (lastWriteTime == (jlong)-1) ? NULL : (CONST FILETIME *)&lastWriteTime) == 0)
 525     {
 526         throwWindowsException(env, GetLastError());
 527     }
 528 }
 529 
 530 JNIEXPORT void JNICALL
 531 Java_sun_nio_fs_WindowsNativeDispatcher_SetEndOfFile(JNIEnv* env, jclass this,
 532     jlong handle)
 533 {
 534     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 535 
 536     if (SetEndOfFile(h) == 0)

 214     } else {
 215         securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
 216         securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor;
 217         securityAttributes.bInheritHandle = FALSE;
 218         lpSecurityAttributes = &securityAttributes;
 219     }
 220 
 221     handle = CreateFileW(lpFileName,
 222                         (DWORD)dwDesiredAccess,
 223                         (DWORD)dwShareMode,
 224                         lpSecurityAttributes,
 225                         (DWORD)dwCreationDisposition,
 226                         (DWORD)dwFlagsAndAttributes,
 227                         NULL);
 228     if (handle == INVALID_HANDLE_VALUE) {
 229         throwWindowsException(env, GetLastError());
 230     }
 231     return ptr_to_jlong(handle);
 232 }
 233 

 234 JNIEXPORT void JNICALL
 235 Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlSetSparse(JNIEnv* env, jclass this,
 236     jlong handle)
 237 {
 238     DWORD bytesReturned;
 239     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 240     if (DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytesReturned, NULL) == 0) {
 241         throwWindowsException(env, GetLastError());
 242     }
 243 }
 244 
 245 JNIEXPORT void JNICALL
 246 Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlGetReparsePoint(JNIEnv* env, jclass this,
 247     jlong handle, jlong bufferAddress, jint bufferSize)
 248 {
 249     DWORD bytesReturned;
 250     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 251     LPVOID outBuffer = (LPVOID)jlong_to_ptr(bufferAddress);
 252 
 253     if (DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, NULL, 0, outBuffer, (DWORD)bufferSize,

 340     } else {
 341         throwWindowsException(env, GetLastError());
 342     }
 343 }
 344 
 345 JNIEXPORT jlong JNICALL
 346 Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile1(JNIEnv* env, jclass this,
 347     jlong pathAddress, jlong dataAddress)
 348 {
 349     LPCWSTR lpFileName = jlong_to_ptr(pathAddress);
 350     WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);
 351 
 352     HANDLE handle = FindFirstFileW(lpFileName, data);
 353     if (handle == INVALID_HANDLE_VALUE) {
 354         throwWindowsException(env, GetLastError());
 355     }
 356     return ptr_to_jlong(handle);
 357 }
 358 
 359 JNIEXPORT jstring JNICALL
 360 Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile0(JNIEnv* env, jclass this,
 361     jlong handle, jlong dataAddress)
 362 {
 363     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 364     WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);
 365 
 366     if (FindNextFileW(h, data) != 0) {
 367         return (*env)->NewString(env, data->cFileName, (jsize)wcslen(data->cFileName));
 368     } else {
 369     if (GetLastError() != ERROR_NO_MORE_FILES)
 370         throwWindowsException(env, GetLastError());
 371         return NULL;
 372     }
 373 }
 374 
 375 JNIEXPORT void JNICALL
 376 Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass this,
 377     jlong address, jobject obj)
 378 {
 379     WIN32_FIND_STREAM_DATA data;
 380     LPCWSTR lpFileName = jlong_to_ptr(address);

 383     handle = FindFirstStreamW(lpFileName, FindStreamInfoStandard, &data, 0);
 384     if (handle != INVALID_HANDLE_VALUE) {
 385         jstring name = (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
 386         if (name == NULL) {
 387             FindClose(handle);
 388             return;
 389         }
 390         (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
 391         (*env)->SetObjectField(env, obj, findStream_name, name);
 392     } else {
 393         if (GetLastError() == ERROR_HANDLE_EOF) {
 394              (*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));
 395         } else {
 396             throwWindowsException(env, GetLastError());
 397         }
 398     }
 399 
 400 }
 401 
 402 JNIEXPORT jstring JNICALL
 403 Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream0(JNIEnv* env, jclass this,
 404     jlong handle)
 405 {
 406     WIN32_FIND_STREAM_DATA data;
 407     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 408 
 409     if (FindNextStreamW(h, &data) != 0) {
 410         return (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));
 411     } else {
 412         if (GetLastError() != ERROR_HANDLE_EOF)
 413             throwWindowsException(env, GetLastError());
 414         return NULL;
 415     }
 416 }
 417 
 418 
 419 JNIEXPORT void JNICALL
 420 Java_sun_nio_fs_WindowsNativeDispatcher_FindClose(JNIEnv* env, jclass this,
 421     jlong handle)
 422 {
 423     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 424     if (FindClose(h) == 0) {
 425         throwWindowsException(env, GetLastError());
 426     }
 427 }
 428 
 429 
 430 JNIEXPORT void JNICALL
 431 Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle0(JNIEnv* env, jclass this,
 432     jlong handle, jlong address)
 433 {
 434     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 435     BY_HANDLE_FILE_INFORMATION* info =
 436         (BY_HANDLE_FILE_INFORMATION*)jlong_to_ptr(address);
 437     if (GetFileInformationByHandle(h, info) == 0) {
 438         throwWindowsException(env, GetLastError());
 439     }
 440 }
 441 
 442 
 443 JNIEXPORT void JNICALL
 444 Java_sun_nio_fs_WindowsNativeDispatcher_CopyFileEx0(JNIEnv* env, jclass this,
 445     jlong existingAddress, jlong newAddress, jint flags, jlong cancelAddress)
 446 {
 447     LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress);
 448     LPCWSTR lpNewFileName = jlong_to_ptr(newAddress);
 449     LPBOOL cancel = (LPBOOL)jlong_to_ptr(cancelAddress);
 450     if (CopyFileExW(lpExistingFileName, lpNewFileName, NULL, NULL, cancel,
 451                     (DWORD)flags) == 0)

 495     LPCWSTR lpFileName = jlong_to_ptr(address);
 496     if (SetFileAttributesW(lpFileName, (DWORD)value) == 0) {
 497         throwWindowsException(env, GetLastError());
 498     }
 499 }
 500 
 501 JNIEXPORT void JNICALL
 502 Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributesEx0(JNIEnv* env, jclass this,
 503     jlong pathAddress, jlong dataAddress)
 504 {
 505     LPCWSTR lpFileName = jlong_to_ptr(pathAddress);
 506     WIN32_FILE_ATTRIBUTE_DATA* data = (WIN32_FILE_ATTRIBUTE_DATA*)jlong_to_ptr(dataAddress);
 507 
 508     BOOL res = GetFileAttributesExW(lpFileName, GetFileExInfoStandard, (LPVOID)data);
 509     if (res == 0)
 510         throwWindowsException(env, GetLastError());
 511 }
 512 
 513 
 514 JNIEXPORT void JNICALL
 515 Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime0(JNIEnv* env, jclass this,
 516     jlong handle, jlong createTime, jlong lastAccessTime, jlong lastWriteTime)
 517 {
 518     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 519 
 520     if (SetFileTime(h,
 521         (createTime == (jlong)-1) ? NULL : (CONST FILETIME *)&createTime,
 522         (lastAccessTime == (jlong)-1) ? NULL : (CONST FILETIME *)&lastAccessTime,
 523         (lastWriteTime == (jlong)-1) ? NULL : (CONST FILETIME *)&lastWriteTime) == 0)
 524     {
 525         throwWindowsException(env, GetLastError());
 526     }
 527 }
 528 
 529 JNIEXPORT void JNICALL
 530 Java_sun_nio_fs_WindowsNativeDispatcher_SetEndOfFile(JNIEnv* env, jclass this,
 531     jlong handle)
 532 {
 533     HANDLE h = (HANDLE)jlong_to_ptr(handle);
 534 
 535     if (SetEndOfFile(h) == 0)
< prev index next >