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

Print this page




 178 
 179     // get handle to kernel32
 180     if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
 181                             GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT),
 182                            (LPCWSTR)&CreateFileW, &h) != 0)
 183     {
 184         // requires Windows Server 2003 or newer
 185         FindFirstStream_func =
 186             (FindFirstStream_Proc)GetProcAddress(h, "FindFirstStreamW");
 187         FindNextStream_func =
 188             (FindNextStream_Proc)GetProcAddress(h, "FindNextStreamW");
 189 
 190         // requires Windows Vista or newer
 191         CreateSymbolicLink_func =
 192             (CreateSymbolicLinkProc)GetProcAddress(h, "CreateSymbolicLinkW");
 193         GetFinalPathNameByHandle_func =
 194             (GetFinalPathNameByHandleProc)GetProcAddress(h, "GetFinalPathNameByHandleW");
 195     }
 196 }
 197 











 198 JNIEXPORT jstring JNICALL
 199 Java_sun_nio_fs_WindowsNativeDispatcher_FormatMessage(JNIEnv* env, jclass this, jint errorCode) {
 200     WCHAR message[255];
 201 
 202     DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
 203                                NULL,
 204                                (DWORD)errorCode,
 205                                0,
 206                                &message[0],
 207                                255,
 208                                NULL);
 209 
 210 
 211     if (len == 0) {
 212         return NULL;
 213     } else {
 214         return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));
 215     }
 216 }
 217 


1213             (jlong)completionKey);
1214     }
1215 }
1216 
1217 JNIEXPORT void JNICALL
1218 Java_sun_nio_fs_WindowsNativeDispatcher_PostQueuedCompletionStatus(JNIEnv* env, jclass this,
1219     jlong completionPort, jlong completionKey)
1220 {
1221     BOOL res;
1222 
1223     res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),
1224                                      (DWORD)0,  /* dwNumberOfBytesTransferred */
1225                                      (ULONG_PTR)completionKey,
1226                                      NULL);  /* lpOverlapped */
1227     if (res == 0) {
1228         throwWindowsException(env, GetLastError());
1229     }
1230 }
1231 
1232 JNIEXPORT void JNICALL

























1233 Java_sun_nio_fs_WindowsNativeDispatcher_ReadDirectoryChangesW(JNIEnv* env, jclass this,
1234     jlong hDirectory, jlong bufferAddress, jint bufferLength, jboolean watchSubTree, jint filter,
1235     jlong bytesReturnedAddress, jlong pOverlapped)
1236 {
1237     BOOL res;
1238     BOOL subtree = (watchSubTree == JNI_TRUE) ? TRUE : FALSE;
1239 
1240     /* Any unused members of [OVERLAPPED] structure should always be initialized to zero
1241        before the structure is used in a function call.
1242        Otherwise, the function may fail and return ERROR_INVALID_PARAMETER.
1243        http://msdn.microsoft.com/en-us/library/windows/desktop/ms684342%28v=vs.85%29.aspx
1244 
1245        The [Offset] and [OffsetHigh] members of this structure are not used.
1246        http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v=vs.85%29.aspx
1247 
1248        [hEvent] should be zero, other fields are the return values. */
1249     ZeroMemory((LPOVERLAPPED)jlong_to_ptr(pOverlapped), sizeof(OVERLAPPED));
1250 
1251     res = ReadDirectoryChangesW((HANDLE)jlong_to_ptr(hDirectory),
1252                                 (LPVOID)jlong_to_ptr(bufferAddress),
1253                                 (DWORD)bufferLength,
1254                                 subtree,
1255                                 (DWORD)filter,
1256                                 (LPDWORD)jlong_to_ptr(bytesReturnedAddress),
1257                                 (LPOVERLAPPED)jlong_to_ptr(pOverlapped),
1258                                 NULL);
1259     if (res == 0) {
1260         throwWindowsException(env, GetLastError());
1261     }
1262 }
1263 
1264 JNIEXPORT void JNICALL
1265 Java_sun_nio_fs_WindowsNativeDispatcher_BackupRead0(JNIEnv* env, jclass this,
1266     jlong hFile, jlong bufferAddress, jint bufferSize, jboolean abort,
1267     jlong context, jobject obj)
1268 {
1269     BOOL res;




 178 
 179     // get handle to kernel32
 180     if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
 181                             GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT),
 182                            (LPCWSTR)&CreateFileW, &h) != 0)
 183     {
 184         // requires Windows Server 2003 or newer
 185         FindFirstStream_func =
 186             (FindFirstStream_Proc)GetProcAddress(h, "FindFirstStreamW");
 187         FindNextStream_func =
 188             (FindNextStream_Proc)GetProcAddress(h, "FindNextStreamW");
 189 
 190         // requires Windows Vista or newer
 191         CreateSymbolicLink_func =
 192             (CreateSymbolicLinkProc)GetProcAddress(h, "CreateSymbolicLinkW");
 193         GetFinalPathNameByHandle_func =
 194             (GetFinalPathNameByHandleProc)GetProcAddress(h, "GetFinalPathNameByHandleW");
 195     }
 196 }
 197 
 198 JNIEXPORT jlong JNICALL
 199 Java_sun_nio_fs_WindowsNativeDispatcher_CreateEvent(JNIEnv* env, jclass this,
 200     jboolean bManualReset, jboolean bInitialState)
 201 {
 202     HANDLE hEvent = CreateEventW(NULL, bManualReset, bInitialState, NULL);
 203     if (hEvent == NULL) {
 204         throwWindowsException(env, GetLastError());
 205     }
 206     return ptr_to_jlong(hEvent);
 207 }
 208 
 209 JNIEXPORT jstring JNICALL
 210 Java_sun_nio_fs_WindowsNativeDispatcher_FormatMessage(JNIEnv* env, jclass this, jint errorCode) {
 211     WCHAR message[255];
 212 
 213     DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
 214                                NULL,
 215                                (DWORD)errorCode,
 216                                0,
 217                                &message[0],
 218                                255,
 219                                NULL);
 220 
 221 
 222     if (len == 0) {
 223         return NULL;
 224     } else {
 225         return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));
 226     }
 227 }
 228 


1224             (jlong)completionKey);
1225     }
1226 }
1227 
1228 JNIEXPORT void JNICALL
1229 Java_sun_nio_fs_WindowsNativeDispatcher_PostQueuedCompletionStatus(JNIEnv* env, jclass this,
1230     jlong completionPort, jlong completionKey)
1231 {
1232     BOOL res;
1233 
1234     res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),
1235                                      (DWORD)0,  /* dwNumberOfBytesTransferred */
1236                                      (ULONG_PTR)completionKey,
1237                                      NULL);  /* lpOverlapped */
1238     if (res == 0) {
1239         throwWindowsException(env, GetLastError());
1240     }
1241 }
1242 
1243 JNIEXPORT void JNICALL
1244 Java_sun_nio_fs_WindowsNativeDispatcher_CancelIo(JNIEnv* env, jclass this, jlong hFile) {
1245     if (CancelIo((HANDLE)jlong_to_ptr(hFile)) == 0) {
1246         throwWindowsException(env, GetLastError());
1247     }
1248 }
1249 
1250 JNIEXPORT jint JNICALL
1251 Java_sun_nio_fs_WindowsNativeDispatcher_GetOverlappedResult(JNIEnv *env, jclass this,
1252     jlong hFile, jlong lpOverlapped)
1253 {
1254     BOOL res;
1255     DWORD bytesTransferred = -1;
1256 
1257     res = GetOverlappedResult((HANDLE)jlong_to_ptr(hFile),
1258                               (LPOVERLAPPED)jlong_to_ptr(lpOverlapped),
1259                               &bytesTransferred,
1260                               TRUE);
1261     if (res == 0) {
1262         throwWindowsException(env, GetLastError());
1263     }
1264 
1265     return (jint)bytesTransferred;
1266 }
1267 
1268 JNIEXPORT void JNICALL
1269 Java_sun_nio_fs_WindowsNativeDispatcher_ReadDirectoryChangesW(JNIEnv* env, jclass this,
1270     jlong hDirectory, jlong bufferAddress, jint bufferLength, jboolean watchSubTree, jint filter,
1271     jlong bytesReturnedAddress, jlong pOverlapped)
1272 {
1273     BOOL res;
1274     BOOL subtree = (watchSubTree == JNI_TRUE) ? TRUE : FALSE;
1275     LPOVERLAPPED ov = (LPOVERLAPPED)jlong_to_ptr(pOverlapped);










1276 
1277     res = ReadDirectoryChangesW((HANDLE)jlong_to_ptr(hDirectory),
1278                                 (LPVOID)jlong_to_ptr(bufferAddress),
1279                                 (DWORD)bufferLength,
1280                                 subtree,
1281                                 (DWORD)filter,
1282                                 (LPDWORD)jlong_to_ptr(bytesReturnedAddress),
1283                                 (LPOVERLAPPED)jlong_to_ptr(pOverlapped),
1284                                 NULL);
1285     if (res == 0) {
1286         throwWindowsException(env, GetLastError());
1287     }
1288 }
1289 
1290 JNIEXPORT void JNICALL
1291 Java_sun_nio_fs_WindowsNativeDispatcher_BackupRead0(JNIEnv* env, jclass this,
1292     jlong hFile, jlong bufferAddress, jint bufferSize, jboolean abort,
1293     jlong context, jobject obj)
1294 {
1295     BOOL res;