Path: blob/master/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
41134 views
/*1* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdio.h>26#include <stdlib.h>27#include <ctype.h>28#include <direct.h>29#include <malloc.h>30#include <io.h>31#include <windows.h>32#include <aclapi.h>33#include <winioctl.h>34#include <Sddl.h>3536#include "jni.h"37#include "jni_util.h"38#include "jlong.h"3940#include "sun_nio_fs_WindowsNativeDispatcher.h"4142/**43* jfieldIDs44*/45static jfieldID findFirst_handle;46static jfieldID findFirst_name;47static jfieldID findFirst_attributes;4849static jfieldID findStream_handle;50static jfieldID findStream_name;5152static jfieldID volumeInfo_fsName;53static jfieldID volumeInfo_volName;54static jfieldID volumeInfo_volSN;55static jfieldID volumeInfo_flags;5657static jfieldID diskSpace_bytesAvailable;58static jfieldID diskSpace_totalBytes;59static jfieldID diskSpace_totalFree;6061static jfieldID diskSpace_bytesPerSector;6263static jfieldID account_domain;64static jfieldID account_name;65static jfieldID account_use;6667static jfieldID aclInfo_aceCount;6869static jfieldID completionStatus_error;70static jfieldID completionStatus_bytesTransferred;71static jfieldID completionStatus_completionKey;7273static void throwWindowsException(JNIEnv* env, DWORD lastError) {74jobject x = JNU_NewObjectByName(env, "sun/nio/fs/WindowsException",75"(I)V", lastError);76if (x != NULL) {77(*env)->Throw(env, x);78}79}8081/**82* Initializes jfieldIDs and get address of Win32 calls that are located83* at runtime.84*/85JNIEXPORT void JNICALL86Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this)87{88jclass clazz;8990clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstFile");91CHECK_NULL(clazz);92findFirst_handle = (*env)->GetFieldID(env, clazz, "handle", "J");93CHECK_NULL(findFirst_handle);94findFirst_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");95CHECK_NULL(findFirst_name);96findFirst_attributes = (*env)->GetFieldID(env, clazz, "attributes", "I");97CHECK_NULL(findFirst_attributes);9899clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstStream");100CHECK_NULL(clazz);101findStream_handle = (*env)->GetFieldID(env, clazz, "handle", "J");102CHECK_NULL(findStream_handle);103findStream_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");104CHECK_NULL(findStream_name);105106clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation");107CHECK_NULL(clazz);108volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;");109CHECK_NULL(volumeInfo_fsName);110volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;");111CHECK_NULL(volumeInfo_volName);112volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I");113CHECK_NULL(volumeInfo_volSN);114volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I");115CHECK_NULL(volumeInfo_flags);116117clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace");118CHECK_NULL(clazz);119diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J");120CHECK_NULL(diskSpace_bytesAvailable);121diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J");122CHECK_NULL(diskSpace_totalBytes);123diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J");124CHECK_NULL(diskSpace_totalFree);125diskSpace_bytesPerSector = (*env)->GetFieldID(env, clazz, "bytesPerSector", "J");126CHECK_NULL(diskSpace_bytesPerSector);127128clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account");129CHECK_NULL(clazz);130account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;");131CHECK_NULL(account_domain);132account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");133CHECK_NULL(account_name);134account_use = (*env)->GetFieldID(env, clazz, "use", "I");135CHECK_NULL(account_use);136137clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation");138CHECK_NULL(clazz);139aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I");140CHECK_NULL(aclInfo_aceCount);141142clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus");143CHECK_NULL(clazz);144completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");145CHECK_NULL(completionStatus_error);146completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");147CHECK_NULL(completionStatus_bytesTransferred);148completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "J");149CHECK_NULL(completionStatus_completionKey);150}151152JNIEXPORT jlong JNICALL153Java_sun_nio_fs_WindowsNativeDispatcher_CreateEvent(JNIEnv* env, jclass this,154jboolean bManualReset, jboolean bInitialState)155{156HANDLE hEvent = CreateEventW(NULL, bManualReset, bInitialState, NULL);157if (hEvent == NULL) {158throwWindowsException(env, GetLastError());159}160return ptr_to_jlong(hEvent);161}162163JNIEXPORT jstring JNICALL164Java_sun_nio_fs_WindowsNativeDispatcher_FormatMessage(JNIEnv* env, jclass this, jint errorCode) {165WCHAR message[255];166167DWORD len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,168NULL,169(DWORD)errorCode,1700,171&message[0],172255,173NULL);174175176if (len == 0) {177return NULL;178} else {179if (len > 3) {180// Drop final '.', CR, LF181if (message[len - 1] == L'\n') len--;182if (message[len - 1] == L'\r') len--;183if (message[len - 1] == L'.') len--;184message[len] = L'\0';185}186187return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));188}189}190191JNIEXPORT void JNICALL192Java_sun_nio_fs_WindowsNativeDispatcher_LocalFree(JNIEnv* env, jclass this, jlong address)193{194HLOCAL hMem = (HLOCAL)jlong_to_ptr(address);195LocalFree(hMem);196}197198JNIEXPORT jlong JNICALL199Java_sun_nio_fs_WindowsNativeDispatcher_CreateFile0(JNIEnv* env, jclass this,200jlong address, jint dwDesiredAccess, jint dwShareMode, jlong sdAddress,201jint dwCreationDisposition, jint dwFlagsAndAttributes)202{203HANDLE handle;204LPCWSTR lpFileName = jlong_to_ptr(address);205206SECURITY_ATTRIBUTES securityAttributes;207LPSECURITY_ATTRIBUTES lpSecurityAttributes;208PSECURITY_DESCRIPTOR lpSecurityDescriptor = jlong_to_ptr(sdAddress);209210211if (lpSecurityDescriptor == NULL) {212lpSecurityAttributes = NULL;213} else {214securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);215securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor;216securityAttributes.bInheritHandle = FALSE;217lpSecurityAttributes = &securityAttributes;218}219220handle = CreateFileW(lpFileName,221(DWORD)dwDesiredAccess,222(DWORD)dwShareMode,223lpSecurityAttributes,224(DWORD)dwCreationDisposition,225(DWORD)dwFlagsAndAttributes,226NULL);227if (handle == INVALID_HANDLE_VALUE) {228throwWindowsException(env, GetLastError());229}230return ptr_to_jlong(handle);231}232233234JNIEXPORT void JNICALL235Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlSetSparse(JNIEnv* env, jclass this,236jlong handle)237{238DWORD bytesReturned;239HANDLE h = (HANDLE)jlong_to_ptr(handle);240if (DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytesReturned, NULL) == 0) {241throwWindowsException(env, GetLastError());242}243}244245JNIEXPORT void JNICALL246Java_sun_nio_fs_WindowsNativeDispatcher_DeviceIoControlGetReparsePoint(JNIEnv* env, jclass this,247jlong handle, jlong bufferAddress, jint bufferSize)248{249DWORD bytesReturned;250HANDLE h = (HANDLE)jlong_to_ptr(handle);251LPVOID outBuffer = (LPVOID)jlong_to_ptr(bufferAddress);252253if (DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, NULL, 0, outBuffer, (DWORD)bufferSize,254&bytesReturned, NULL) == 0)255{256throwWindowsException(env, GetLastError());257}258}259260JNIEXPORT void JNICALL261Java_sun_nio_fs_WindowsNativeDispatcher_DeleteFile0(JNIEnv* env, jclass this, jlong address)262{263LPCWSTR lpFileName = jlong_to_ptr(address);264if (DeleteFileW(lpFileName) == 0) {265throwWindowsException(env, GetLastError());266}267}268269JNIEXPORT void JNICALL270Java_sun_nio_fs_WindowsNativeDispatcher_CreateDirectory0(JNIEnv* env, jclass this,271jlong address, jlong sdAddress)272{273LPCWSTR lpFileName = jlong_to_ptr(address);274275SECURITY_ATTRIBUTES securityAttributes;276LPSECURITY_ATTRIBUTES lpSecurityAttributes;277PSECURITY_DESCRIPTOR lpSecurityDescriptor = jlong_to_ptr(sdAddress);278279280if (lpSecurityDescriptor == NULL) {281lpSecurityAttributes = NULL;282} else {283securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);284securityAttributes.lpSecurityDescriptor = lpSecurityDescriptor;285securityAttributes.bInheritHandle = FALSE;286lpSecurityAttributes = &securityAttributes;287}288289if (CreateDirectoryW(lpFileName, lpSecurityAttributes) == 0) {290throwWindowsException(env, GetLastError());291}292}293294JNIEXPORT void JNICALL295Java_sun_nio_fs_WindowsNativeDispatcher_RemoveDirectory0(JNIEnv* env, jclass this, jlong address)296{297LPCWSTR lpFileName = jlong_to_ptr(address);298if (RemoveDirectoryW(lpFileName) == 0) {299throwWindowsException(env, GetLastError());300}301}302303JNIEXPORT void JNICALL304Java_sun_nio_fs_WindowsNativeDispatcher_CloseHandle(JNIEnv* env, jclass this,305jlong handle)306{307HANDLE h = (HANDLE)jlong_to_ptr(handle);308CloseHandle(h);309}310311JNIEXPORT jlong JNICALL312Java_sun_nio_fs_WindowsNativeDispatcher_GetFileSizeEx(JNIEnv *env,313jclass this, jlong handle)314{315HANDLE h = (HANDLE)jlong_to_ptr(handle);316LARGE_INTEGER size;317if (GetFileSizeEx(h, &size) == 0) {318throwWindowsException(env, GetLastError());319}320return long_to_jlong(size.QuadPart);321}322323JNIEXPORT void JNICALL324Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile0(JNIEnv* env, jclass this,325jlong address, jobject obj)326{327WIN32_FIND_DATAW data;328LPCWSTR lpFileName = jlong_to_ptr(address);329330HANDLE handle = FindFirstFileW(lpFileName, &data);331if (handle != INVALID_HANDLE_VALUE) {332jstring name = (*env)->NewString(env, data.cFileName, (jsize)wcslen(data.cFileName));333if (name == NULL) {334FindClose(handle);335return;336}337(*env)->SetLongField(env, obj, findFirst_handle, ptr_to_jlong(handle));338(*env)->SetObjectField(env, obj, findFirst_name, name);339(*env)->SetIntField(env, obj, findFirst_attributes, data.dwFileAttributes);340} else {341throwWindowsException(env, GetLastError());342}343}344345JNIEXPORT jlong JNICALL346Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstFile1(JNIEnv* env, jclass this,347jlong pathAddress, jlong dataAddress)348{349LPCWSTR lpFileName = jlong_to_ptr(pathAddress);350WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);351352HANDLE handle = FindFirstFileW(lpFileName, data);353if (handle == INVALID_HANDLE_VALUE) {354throwWindowsException(env, GetLastError());355}356return ptr_to_jlong(handle);357}358359JNIEXPORT jstring JNICALL360Java_sun_nio_fs_WindowsNativeDispatcher_FindNextFile(JNIEnv* env, jclass this,361jlong handle, jlong dataAddress)362{363HANDLE h = (HANDLE)jlong_to_ptr(handle);364WIN32_FIND_DATAW* data = (WIN32_FIND_DATAW*)jlong_to_ptr(dataAddress);365366if (FindNextFileW(h, data) != 0) {367return (*env)->NewString(env, data->cFileName, (jsize)wcslen(data->cFileName));368} else {369if (GetLastError() != ERROR_NO_MORE_FILES)370throwWindowsException(env, GetLastError());371return NULL;372}373}374375JNIEXPORT void JNICALL376Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0(JNIEnv* env, jclass this,377jlong address, jobject obj)378{379WIN32_FIND_STREAM_DATA data;380LPCWSTR lpFileName = jlong_to_ptr(address);381HANDLE handle;382383handle = FindFirstStreamW(lpFileName, FindStreamInfoStandard, &data, 0);384if (handle != INVALID_HANDLE_VALUE) {385jstring name = (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));386if (name == NULL) {387FindClose(handle);388return;389}390(*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));391(*env)->SetObjectField(env, obj, findStream_name, name);392} else {393if (GetLastError() == ERROR_HANDLE_EOF) {394(*env)->SetLongField(env, obj, findStream_handle, ptr_to_jlong(handle));395} else {396throwWindowsException(env, GetLastError());397}398}399400}401402JNIEXPORT jstring JNICALL403Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream(JNIEnv* env, jclass this,404jlong handle)405{406WIN32_FIND_STREAM_DATA data;407HANDLE h = (HANDLE)jlong_to_ptr(handle);408409if (FindNextStreamW(h, &data) != 0) {410return (*env)->NewString(env, data.cStreamName, (jsize)wcslen(data.cStreamName));411} else {412if (GetLastError() != ERROR_HANDLE_EOF)413throwWindowsException(env, GetLastError());414return NULL;415}416}417418419JNIEXPORT void JNICALL420Java_sun_nio_fs_WindowsNativeDispatcher_FindClose(JNIEnv* env, jclass this,421jlong handle)422{423HANDLE h = (HANDLE)jlong_to_ptr(handle);424if (FindClose(h) == 0) {425throwWindowsException(env, GetLastError());426}427}428429430JNIEXPORT void JNICALL431Java_sun_nio_fs_WindowsNativeDispatcher_GetFileInformationByHandle(JNIEnv* env, jclass this,432jlong handle, jlong address)433{434HANDLE h = (HANDLE)jlong_to_ptr(handle);435BY_HANDLE_FILE_INFORMATION* info =436(BY_HANDLE_FILE_INFORMATION*)jlong_to_ptr(address);437if (GetFileInformationByHandle(h, info) == 0) {438throwWindowsException(env, GetLastError());439}440}441442443JNIEXPORT void JNICALL444Java_sun_nio_fs_WindowsNativeDispatcher_CopyFileEx0(JNIEnv* env, jclass this,445jlong existingAddress, jlong newAddress, jint flags, jlong cancelAddress)446{447LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress);448LPCWSTR lpNewFileName = jlong_to_ptr(newAddress);449LPBOOL cancel = (LPBOOL)jlong_to_ptr(cancelAddress);450if (CopyFileExW(lpExistingFileName, lpNewFileName, NULL, NULL, cancel,451(DWORD)flags) == 0)452{453throwWindowsException(env, GetLastError());454}455}456457JNIEXPORT void JNICALL458Java_sun_nio_fs_WindowsNativeDispatcher_MoveFileEx0(JNIEnv* env, jclass this,459jlong existingAddress, jlong newAddress, jint flags)460{461LPCWSTR lpExistingFileName = jlong_to_ptr(existingAddress);462LPCWSTR lpNewFileName = jlong_to_ptr(newAddress);463if (MoveFileExW(lpExistingFileName, lpNewFileName, (DWORD)flags) == 0) {464throwWindowsException(env, GetLastError());465}466}467468JNIEXPORT jint JNICALL469Java_sun_nio_fs_WindowsNativeDispatcher_GetLogicalDrives(JNIEnv* env, jclass this)470{471DWORD res = GetLogicalDrives();472if (res == 0) {473throwWindowsException(env, GetLastError());474}475return (jint)res;476}477478JNIEXPORT jint JNICALL479Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributes0(JNIEnv* env, jclass this,480jlong address)481{482LPCWSTR lpFileName = jlong_to_ptr(address);483DWORD value = GetFileAttributesW(lpFileName);484485if (value == INVALID_FILE_ATTRIBUTES) {486throwWindowsException(env, GetLastError());487}488return (jint)value;489}490491JNIEXPORT void JNICALL492Java_sun_nio_fs_WindowsNativeDispatcher_SetFileAttributes0(JNIEnv* env, jclass this,493jlong address, jint value)494{495LPCWSTR lpFileName = jlong_to_ptr(address);496if (SetFileAttributesW(lpFileName, (DWORD)value) == 0) {497throwWindowsException(env, GetLastError());498}499}500501JNIEXPORT void JNICALL502Java_sun_nio_fs_WindowsNativeDispatcher_GetFileAttributesEx0(JNIEnv* env, jclass this,503jlong pathAddress, jlong dataAddress)504{505LPCWSTR lpFileName = jlong_to_ptr(pathAddress);506WIN32_FILE_ATTRIBUTE_DATA* data = (WIN32_FILE_ATTRIBUTE_DATA*)jlong_to_ptr(dataAddress);507508BOOL res = GetFileAttributesExW(lpFileName, GetFileExInfoStandard, (LPVOID)data);509if (res == 0)510throwWindowsException(env, GetLastError());511}512513514JNIEXPORT void JNICALL515Java_sun_nio_fs_WindowsNativeDispatcher_SetFileTime(JNIEnv* env, jclass this,516jlong handle, jlong createTime, jlong lastAccessTime, jlong lastWriteTime)517{518HANDLE h = (HANDLE)jlong_to_ptr(handle);519520if (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{525throwWindowsException(env, GetLastError());526}527}528529JNIEXPORT void JNICALL530Java_sun_nio_fs_WindowsNativeDispatcher_SetEndOfFile(JNIEnv* env, jclass this,531jlong handle)532{533HANDLE h = (HANDLE)jlong_to_ptr(handle);534535if (SetEndOfFile(h) == 0)536throwWindowsException(env, GetLastError());537}538539540JNIEXPORT void JNICALL541Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumeInformation0(JNIEnv* env, jclass this,542jlong address, jobject obj)543{544WCHAR volumeName[MAX_PATH+1];545DWORD volumeSerialNumber;546DWORD maxComponentLength;547DWORD flags;548WCHAR fileSystemName[MAX_PATH+1];549LPCWSTR lpFileName = jlong_to_ptr(address);550jstring str;551552BOOL res = GetVolumeInformationW(lpFileName,553&volumeName[0],554MAX_PATH+1,555&volumeSerialNumber,556&maxComponentLength,557&flags,558&fileSystemName[0],559MAX_PATH+1);560if (res == 0) {561throwWindowsException(env, GetLastError());562return;563}564565str = (*env)->NewString(env, (const jchar *)fileSystemName, (jsize)wcslen(fileSystemName));566if (str == NULL) return;567(*env)->SetObjectField(env, obj, volumeInfo_fsName, str);568569str = (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName));570if (str == NULL) return;571(*env)->SetObjectField(env, obj, volumeInfo_volName, str);572573(*env)->SetIntField(env, obj, volumeInfo_volSN, (jint)volumeSerialNumber);574(*env)->SetIntField(env, obj, volumeInfo_flags, (jint)flags);575}576577578JNIEXPORT jint JNICALL579Java_sun_nio_fs_WindowsNativeDispatcher_GetDriveType0(JNIEnv* env, jclass this, jlong address) {580LPCWSTR lpRootPathName = jlong_to_ptr(address);581return (jint)GetDriveTypeW(lpRootPathName);582}583584585JNIEXPORT void JNICALL586Java_sun_nio_fs_WindowsNativeDispatcher_GetDiskFreeSpaceEx0(JNIEnv* env, jclass this,587jlong address, jobject obj)588{589ULARGE_INTEGER freeBytesAvailable;590ULARGE_INTEGER totalNumberOfBytes;591ULARGE_INTEGER totalNumberOfFreeBytes;592LPCWSTR lpDirName = jlong_to_ptr(address);593594595BOOL res = GetDiskFreeSpaceExW(lpDirName,596&freeBytesAvailable,597&totalNumberOfBytes,598&totalNumberOfFreeBytes);599if (res == 0) {600throwWindowsException(env, GetLastError());601return;602}603604(*env)->SetLongField(env, obj, diskSpace_bytesAvailable,605long_to_jlong(freeBytesAvailable.QuadPart));606(*env)->SetLongField(env, obj, diskSpace_totalBytes,607long_to_jlong(totalNumberOfBytes.QuadPart));608(*env)->SetLongField(env, obj, diskSpace_totalFree,609long_to_jlong(totalNumberOfFreeBytes.QuadPart));610}611612JNIEXPORT void JNICALL613Java_sun_nio_fs_WindowsNativeDispatcher_GetDiskFreeSpace0(JNIEnv* env, jclass this,614jlong address, jobject obj)615{616DWORD sectorsPerCluster;617DWORD bytesPerSector;618DWORD numberOfFreeClusters;619DWORD totalNumberOfClusters;620LPCWSTR lpRootPathName = jlong_to_ptr(address);621622623BOOL res = GetDiskFreeSpaceW(lpRootPathName,624§orsPerCluster,625&bytesPerSector,626&numberOfFreeClusters,627&totalNumberOfClusters);628if (res == 0) {629throwWindowsException(env, GetLastError());630return;631}632633(*env)->SetLongField(env, obj, diskSpace_bytesPerSector,634long_to_jlong(bytesPerSector));635}636637JNIEXPORT jstring JNICALL638Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumePathName0(JNIEnv* env, jclass this,639jlong address)640{641WCHAR volumeName[MAX_PATH+1];642LPCWSTR lpFileName = jlong_to_ptr(address);643644645BOOL res = GetVolumePathNameW(lpFileName,646&volumeName[0],647MAX_PATH+1);648if (res == 0) {649throwWindowsException(env, GetLastError());650return NULL;651} else {652return (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName));653}654}655656JNIEXPORT void JNICALL657Java_sun_nio_fs_WindowsNativeDispatcher_InitializeSecurityDescriptor(JNIEnv* env, jclass this,658jlong address)659{660PSECURITY_DESCRIPTOR pSecurityDescriptor =661(PSECURITY_DESCRIPTOR)jlong_to_ptr(address);662663if (InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION) == 0) {664throwWindowsException(env, GetLastError());665}666}667668JNIEXPORT void JNICALL669Java_sun_nio_fs_WindowsNativeDispatcher_InitializeAcl(JNIEnv* env, jclass this,670jlong address, jint size)671{672PACL pAcl = (PACL)jlong_to_ptr(address);673674if (InitializeAcl(pAcl, (DWORD)size, ACL_REVISION) == 0) {675throwWindowsException(env, GetLastError());676}677}678679680JNIEXPORT void JNICALL681Java_sun_nio_fs_WindowsNativeDispatcher_SetFileSecurity0(JNIEnv* env, jclass this,682jlong pathAddress, jint requestedInformation, jlong descAddress)683{684LPCWSTR lpFileName = jlong_to_ptr(pathAddress);685PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress);686DWORD lengthNeeded = 0;687688BOOL res = SetFileSecurityW(lpFileName,689(SECURITY_INFORMATION)requestedInformation,690pSecurityDescriptor);691692if (res == 0) {693throwWindowsException(env, GetLastError());694}695}696697JNIEXPORT jint JNICALL698Java_sun_nio_fs_WindowsNativeDispatcher_GetFileSecurity0(JNIEnv* env, jclass this,699jlong pathAddress, jint requestedInformation, jlong descAddress, jint nLength)700{701LPCWSTR lpFileName = jlong_to_ptr(pathAddress);702PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress);703DWORD lengthNeeded = 0;704705BOOL res = GetFileSecurityW(lpFileName,706(SECURITY_INFORMATION)requestedInformation,707pSecurityDescriptor,708(DWORD)nLength,709&lengthNeeded);710711if (res == 0) {712if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {713return (jint)lengthNeeded;714} else {715throwWindowsException(env, GetLastError());716return 0;717}718} else {719return (jint)nLength;720}721}722723JNIEXPORT jlong JNICALL724Java_sun_nio_fs_WindowsNativeDispatcher_GetSecurityDescriptorOwner(JNIEnv* env,725jclass this, jlong address)726{727PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(address);728PSID pOwner;729BOOL bOwnerDefaulted;730731732if (GetSecurityDescriptorOwner(pSecurityDescriptor, &pOwner, &bOwnerDefaulted) == 0) {733throwWindowsException(env, GetLastError());734}735return ptr_to_jlong(pOwner);736}737738JNIEXPORT void JNICALL739Java_sun_nio_fs_WindowsNativeDispatcher_SetSecurityDescriptorOwner(JNIEnv* env,740jclass this, jlong descAddress, jlong ownerAddress)741{742PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(descAddress);743PSID pOwner = jlong_to_ptr(ownerAddress);744745if (SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, FALSE) == 0) {746throwWindowsException(env, GetLastError());747}748}749750751JNIEXPORT jlong JNICALL752Java_sun_nio_fs_WindowsNativeDispatcher_GetSecurityDescriptorDacl(JNIEnv* env,753jclass this, jlong address)754{755PSECURITY_DESCRIPTOR pSecurityDescriptor = jlong_to_ptr(address);756BOOL bDaclPresent;757PACL pDacl;758BOOL bDaclDefaulted;759760if (GetSecurityDescriptorDacl(pSecurityDescriptor, &bDaclPresent, &pDacl, &bDaclDefaulted) == 0) {761throwWindowsException(env, GetLastError());762return (jlong)0;763} else {764return (bDaclPresent) ? ptr_to_jlong(pDacl) : (jlong)0;765}766}767768JNIEXPORT void JNICALL769Java_sun_nio_fs_WindowsNativeDispatcher_SetSecurityDescriptorDacl(JNIEnv* env,770jclass this, jlong descAddress, jlong aclAddress)771{772PSECURITY_DESCRIPTOR pSecurityDescriptor = (PSECURITY_DESCRIPTOR)jlong_to_ptr(descAddress);773PACL pAcl = (PACL)jlong_to_ptr(aclAddress);774775if (SetSecurityDescriptorDacl(pSecurityDescriptor, TRUE, pAcl, FALSE) == 0) {776throwWindowsException(env, GetLastError());777}778}779780781JNIEXPORT void JNICALL782Java_sun_nio_fs_WindowsNativeDispatcher_GetAclInformation0(JNIEnv* env,783jclass this, jlong address, jobject obj)784{785PACL pAcl = (PACL)jlong_to_ptr(address);786ACL_SIZE_INFORMATION acl_size_info;787788if (GetAclInformation(pAcl, (void *) &acl_size_info, sizeof(acl_size_info), AclSizeInformation) == 0) {789throwWindowsException(env, GetLastError());790} else {791(*env)->SetIntField(env, obj, aclInfo_aceCount, (jint)acl_size_info.AceCount);792}793}794795JNIEXPORT jlong JNICALL796Java_sun_nio_fs_WindowsNativeDispatcher_GetAce(JNIEnv* env, jclass this, jlong address,797jint aceIndex)798{799PACL pAcl = (PACL)jlong_to_ptr(address);800LPVOID pAce;801802if (GetAce(pAcl, (DWORD)aceIndex, &pAce) == 0) {803throwWindowsException(env, GetLastError());804return (jlong)0;805} else {806return ptr_to_jlong(pAce);807}808}809810JNIEXPORT void JNICALL811Java_sun_nio_fs_WindowsNativeDispatcher_AddAccessAllowedAceEx(JNIEnv* env,812jclass this, jlong aclAddress, jint flags, jint mask, jlong sidAddress)813{814PACL pAcl = (PACL)jlong_to_ptr(aclAddress);815PSID pSid = (PSID)jlong_to_ptr(sidAddress);816817if (AddAccessAllowedAceEx(pAcl, ACL_REVISION, (DWORD)flags, (DWORD)mask, pSid) == 0) {818throwWindowsException(env, GetLastError());819}820}821822JNIEXPORT void JNICALL823Java_sun_nio_fs_WindowsNativeDispatcher_AddAccessDeniedAceEx(JNIEnv* env,824jclass this, jlong aclAddress, jint flags, jint mask, jlong sidAddress)825{826PACL pAcl = (PACL)jlong_to_ptr(aclAddress);827PSID pSid = (PSID)jlong_to_ptr(sidAddress);828829if (AddAccessDeniedAceEx(pAcl, ACL_REVISION, (DWORD)flags, (DWORD)mask, pSid) == 0) {830throwWindowsException(env, GetLastError());831}832}833834835JNIEXPORT void JNICALL836Java_sun_nio_fs_WindowsNativeDispatcher_LookupAccountSid0(JNIEnv* env,837jclass this, jlong address, jobject obj)838{839WCHAR domain[255];840WCHAR name[255];841DWORD domainLen = sizeof(domain);842DWORD nameLen = sizeof(name);843SID_NAME_USE use;844PSID sid = jlong_to_ptr(address);845jstring s;846847if (LookupAccountSidW(NULL, sid, &name[0], &nameLen, &domain[0], &domainLen, &use) == 0) {848throwWindowsException(env, GetLastError());849return;850}851852s = (*env)->NewString(env, (const jchar *)domain, (jsize)wcslen(domain));853if (s == NULL)854return;855(*env)->SetObjectField(env, obj, account_domain, s);856857s = (*env)->NewString(env, (const jchar *)name, (jsize)wcslen(name));858if (s == NULL)859return;860(*env)->SetObjectField(env, obj, account_name, s);861(*env)->SetIntField(env, obj, account_use, (jint)use);862}863864JNIEXPORT jint JNICALL865Java_sun_nio_fs_WindowsNativeDispatcher_LookupAccountName0(JNIEnv* env,866jclass this, jlong nameAddress, jlong sidAddress, jint cbSid)867{868869LPCWSTR accountName = jlong_to_ptr(nameAddress);870PSID sid = jlong_to_ptr(sidAddress);871WCHAR domain[255];872DWORD domainLen = sizeof(domain);873SID_NAME_USE use;874875if (LookupAccountNameW(NULL, accountName, sid, (LPDWORD)&cbSid,876&domain[0], &domainLen, &use) == 0)877{878if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {879throwWindowsException(env, GetLastError());880}881}882883return cbSid;884}885886JNIEXPORT jint JNICALL887Java_sun_nio_fs_WindowsNativeDispatcher_GetLengthSid(JNIEnv* env,888jclass this, jlong address)889{890PSID sid = jlong_to_ptr(address);891return (jint)GetLengthSid(sid);892}893894895JNIEXPORT jstring JNICALL896Java_sun_nio_fs_WindowsNativeDispatcher_ConvertSidToStringSid(JNIEnv* env,897jclass this, jlong address)898{899PSID sid = jlong_to_ptr(address);900LPWSTR string;901if (ConvertSidToStringSidW(sid, &string) == 0) {902throwWindowsException(env, GetLastError());903return NULL;904} else {905jstring s = (*env)->NewString(env, (const jchar *)string,906(jsize)wcslen(string));907LocalFree(string);908return s;909}910}911912JNIEXPORT jlong JNICALL913Java_sun_nio_fs_WindowsNativeDispatcher_ConvertStringSidToSid0(JNIEnv* env,914jclass this, jlong address)915{916LPWSTR lpStringSid = jlong_to_ptr(address);917PSID pSid;918if (ConvertStringSidToSidW(lpStringSid, &pSid) == 0)919throwWindowsException(env, GetLastError());920return ptr_to_jlong(pSid);921}922923JNIEXPORT jlong JNICALL924Java_sun_nio_fs_WindowsNativeDispatcher_GetCurrentProcess(JNIEnv* env, jclass this) {925HANDLE hProcess = GetCurrentProcess();926return ptr_to_jlong(hProcess);927}928929JNIEXPORT jlong JNICALL930Java_sun_nio_fs_WindowsNativeDispatcher_GetCurrentThread(JNIEnv* env, jclass this) {931HANDLE hThread = GetCurrentThread();932return ptr_to_jlong(hThread);933}934935JNIEXPORT jlong JNICALL936Java_sun_nio_fs_WindowsNativeDispatcher_OpenProcessToken(JNIEnv* env,937jclass this, jlong process, jint desiredAccess)938{939HANDLE hProcess = (HANDLE)jlong_to_ptr(process);940HANDLE hToken;941942if (OpenProcessToken(hProcess, (DWORD)desiredAccess, &hToken) == 0)943throwWindowsException(env, GetLastError());944return ptr_to_jlong(hToken);945}946947JNIEXPORT jlong JNICALL948Java_sun_nio_fs_WindowsNativeDispatcher_OpenThreadToken(JNIEnv* env,949jclass this, jlong thread, jint desiredAccess, jboolean openAsSelf)950{951HANDLE hThread = (HANDLE)jlong_to_ptr(thread);952HANDLE hToken;953BOOL bOpenAsSelf = (openAsSelf == JNI_TRUE) ? TRUE : FALSE;954955if (OpenThreadToken(hThread, (DWORD)desiredAccess, bOpenAsSelf, &hToken) == 0) {956if (GetLastError() == ERROR_NO_TOKEN)957return (jlong)0;958throwWindowsException(env, GetLastError());959}960return ptr_to_jlong(hToken);961}962963JNIEXPORT jlong JNICALL964Java_sun_nio_fs_WindowsNativeDispatcher_DuplicateTokenEx(JNIEnv* env,965jclass this, jlong token, jint desiredAccess)966{967HANDLE hToken = (HANDLE)jlong_to_ptr(token);968HANDLE resultToken;969BOOL res;970971res = DuplicateTokenEx(hToken,972(DWORD)desiredAccess,973NULL,974SecurityImpersonation,975TokenImpersonation,976&resultToken);977if (res == 0)978throwWindowsException(env, GetLastError());979return ptr_to_jlong(resultToken);980}981982JNIEXPORT void JNICALL983Java_sun_nio_fs_WindowsNativeDispatcher_SetThreadToken(JNIEnv* env,984jclass this, jlong thread, jlong token)985{986HANDLE hThread = (HANDLE)jlong_to_ptr(thread);987HANDLE hToken = (HANDLE)jlong_to_ptr(token);988989if (SetThreadToken(hThread, hToken) == 0)990throwWindowsException(env, GetLastError());991}992993JNIEXPORT jint JNICALL994Java_sun_nio_fs_WindowsNativeDispatcher_GetTokenInformation(JNIEnv* env,995jclass this, jlong token, jint tokenInfoClass, jlong tokenInfo, jint tokenInfoLength)996{997BOOL res;998DWORD lengthNeeded;999HANDLE hToken = (HANDLE)jlong_to_ptr(token);1000LPVOID result = (LPVOID)jlong_to_ptr(tokenInfo);10011002res = GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)tokenInfoClass, (LPVOID)result,1003tokenInfoLength, &lengthNeeded);1004if (res == 0) {1005if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {1006return (jint)lengthNeeded;1007} else {1008throwWindowsException(env, GetLastError());1009return 0;1010}1011} else {1012return tokenInfoLength;1013}1014}10151016JNIEXPORT void JNICALL1017Java_sun_nio_fs_WindowsNativeDispatcher_AdjustTokenPrivileges(JNIEnv* env,1018jclass this, jlong token, jlong luid, jint attributes)1019{1020TOKEN_PRIVILEGES privs[1];1021HANDLE hToken = (HANDLE)jlong_to_ptr(token);1022PLUID pLuid = (PLUID)jlong_to_ptr(luid);10231024privs[0].PrivilegeCount = 1;1025privs[0].Privileges[0].Luid = *pLuid;1026privs[0].Privileges[0].Attributes = (DWORD)attributes;10271028if (AdjustTokenPrivileges(hToken, FALSE, &privs[0], 1, NULL, NULL) == 0)1029throwWindowsException(env, GetLastError());1030}10311032JNIEXPORT jboolean JNICALL1033Java_sun_nio_fs_WindowsNativeDispatcher_AccessCheck(JNIEnv* env,1034jclass this, jlong token, jlong securityInfo, jint accessMask,1035jint genericRead, jint genericWrite, jint genericExecute, jint genericAll)1036{1037HANDLE hImpersonatedToken = (HANDLE)jlong_to_ptr(token);1038PSECURITY_DESCRIPTOR security = (PSECURITY_DESCRIPTOR)jlong_to_ptr(securityInfo);1039DWORD checkAccessRights = (DWORD)accessMask;1040GENERIC_MAPPING mapping = {1041genericRead,1042genericWrite,1043genericExecute,1044genericAll};1045PRIVILEGE_SET privileges = {0};1046DWORD privilegesLength = sizeof(privileges);1047DWORD grantedAccess = 0;1048BOOL result = FALSE;10491050/* checkAccessRights is in-out parameter */1051MapGenericMask(&checkAccessRights, &mapping);1052if (AccessCheck(security, hImpersonatedToken, checkAccessRights,1053&mapping, &privileges, &privilegesLength, &grantedAccess, &result) == 0)1054throwWindowsException(env, GetLastError());10551056return (result == FALSE) ? JNI_FALSE : JNI_TRUE;1057}10581059JNIEXPORT jlong JNICALL1060Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env,1061jclass this, jlong name)1062{1063LPCWSTR lpName = (LPCWSTR)jlong_to_ptr(name);1064PLUID pLuid = LocalAlloc(0, sizeof(LUID));10651066if (pLuid == NULL) {1067JNU_ThrowInternalError(env, "Unable to allocate LUID structure");1068} else {1069if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) {1070LocalFree(pLuid);1071throwWindowsException(env, GetLastError());1072return (jlong)0;1073}1074}1075return ptr_to_jlong(pLuid);1076}10771078JNIEXPORT void JNICALL1079Java_sun_nio_fs_WindowsNativeDispatcher_CreateSymbolicLink0(JNIEnv* env,1080jclass this, jlong linkAddress, jlong targetAddress, jint flags)1081{1082LPCWSTR link = jlong_to_ptr(linkAddress);1083LPCWSTR target = jlong_to_ptr(targetAddress);10841085if (CreateSymbolicLinkW(link, target, (DWORD)flags) == 0)1086throwWindowsException(env, GetLastError());1087}10881089JNIEXPORT void JNICALL1090Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env,1091jclass this, jlong newFileAddress, jlong existingFileAddress)1092{1093LPCWSTR newFile = jlong_to_ptr(newFileAddress);1094LPCWSTR existingFile = jlong_to_ptr(existingFileAddress);10951096if (CreateHardLinkW(newFile, existingFile, NULL) == 0)1097throwWindowsException(env, GetLastError());1098}10991100JNIEXPORT jstring JNICALL1101Java_sun_nio_fs_WindowsNativeDispatcher_GetFullPathName0(JNIEnv *env,1102jclass clz,1103jlong pathAddress)1104{1105jstring rv = NULL;1106WCHAR *lpBuf = NULL;1107WCHAR buf[MAX_PATH];1108DWORD len;1109LPCWSTR lpFileName = jlong_to_ptr(pathAddress);11101111len = GetFullPathNameW(lpFileName, MAX_PATH, buf, NULL);1112if (len > 0) {1113if (len < MAX_PATH) {1114rv = (*env)->NewString(env, buf, len);1115} else {1116len += 1; /* return length does not include terminator */1117lpBuf = (WCHAR*)malloc(len * sizeof(WCHAR));1118if (lpBuf != NULL) {1119len = GetFullPathNameW(lpFileName, len, lpBuf, NULL);1120if (len > 0) {1121rv = (*env)->NewString(env, lpBuf, len);1122} else {1123JNU_ThrowInternalError(env, "GetFullPathNameW failed");1124}1125free(lpBuf);1126} else {1127JNU_ThrowOutOfMemoryError(env, "native memory allocation failure");1128}1129}1130} else {1131throwWindowsException(env, GetLastError());1132}11331134return rv;1135}11361137JNIEXPORT jstring JNICALL1138Java_sun_nio_fs_WindowsNativeDispatcher_GetFinalPathNameByHandle(JNIEnv* env,1139jclass this, jlong handle)1140{1141jstring rv = NULL;1142WCHAR *lpBuf = NULL;1143WCHAR path[MAX_PATH];1144HANDLE h = (HANDLE)jlong_to_ptr(handle);1145DWORD len;11461147len = GetFinalPathNameByHandleW(h, path, MAX_PATH, 0);1148if (len > 0) {1149if (len < MAX_PATH) {1150rv = (*env)->NewString(env, (const jchar *)path, (jsize)len);1151} else {1152len += 1; /* return length does not include terminator */1153lpBuf = (WCHAR*)malloc(len * sizeof(WCHAR));1154if (lpBuf != NULL) {1155len = GetFinalPathNameByHandleW(h, lpBuf, len, 0);1156if (len > 0) {1157rv = (*env)->NewString(env, (const jchar *)lpBuf, (jsize)len);1158} else {1159JNU_ThrowInternalError(env, "GetFinalPathNameByHandleW failed");1160}1161free(lpBuf);1162} else {1163JNU_ThrowOutOfMemoryError(env, "native memory allocation failure");1164}1165}1166} else {1167throwWindowsException(env, GetLastError());1168}1169return rv;1170}11711172JNIEXPORT jlong JNICALL1173Java_sun_nio_fs_WindowsNativeDispatcher_CreateIoCompletionPort(JNIEnv* env, jclass this,1174jlong fileHandle, jlong existingPort, jlong completionKey)1175{1176HANDLE port = CreateIoCompletionPort((HANDLE)jlong_to_ptr(fileHandle),1177(HANDLE)jlong_to_ptr(existingPort),1178(ULONG_PTR)completionKey,11790);1180if (port == NULL) {1181throwWindowsException(env, GetLastError());1182}1183return ptr_to_jlong(port);1184}11851186JNIEXPORT void JNICALL1187Java_sun_nio_fs_WindowsNativeDispatcher_GetQueuedCompletionStatus0(JNIEnv* env, jclass this,1188jlong completionPort, jobject obj)1189{1190DWORD bytesTransferred;1191ULONG_PTR completionKey;1192OVERLAPPED *lpOverlapped;1193BOOL res;11941195res = GetQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),1196&bytesTransferred,1197&completionKey,1198&lpOverlapped,1199INFINITE);1200if (res == 0 && lpOverlapped == NULL) {1201throwWindowsException(env, GetLastError());1202} else {1203DWORD ioResult = (res == 0) ? GetLastError() : 0;1204(*env)->SetIntField(env, obj, completionStatus_error, ioResult);1205(*env)->SetIntField(env, obj, completionStatus_bytesTransferred,1206(jint)bytesTransferred);1207(*env)->SetLongField(env, obj, completionStatus_completionKey,1208(jlong)completionKey);1209}1210}12111212JNIEXPORT void JNICALL1213Java_sun_nio_fs_WindowsNativeDispatcher_PostQueuedCompletionStatus(JNIEnv* env, jclass this,1214jlong completionPort, jlong completionKey)1215{1216BOOL res;12171218res = PostQueuedCompletionStatus((HANDLE)jlong_to_ptr(completionPort),1219(DWORD)0, /* dwNumberOfBytesTransferred */1220(ULONG_PTR)completionKey,1221NULL); /* lpOverlapped */1222if (res == 0) {1223throwWindowsException(env, GetLastError());1224}1225}12261227JNIEXPORT void JNICALL1228Java_sun_nio_fs_WindowsNativeDispatcher_CancelIo(JNIEnv* env, jclass this, jlong hFile) {1229if (CancelIo((HANDLE)jlong_to_ptr(hFile)) == 0) {1230throwWindowsException(env, GetLastError());1231}1232}12331234JNIEXPORT jint JNICALL1235Java_sun_nio_fs_WindowsNativeDispatcher_GetOverlappedResult(JNIEnv *env, jclass this,1236jlong hFile, jlong lpOverlapped)1237{1238BOOL res;1239DWORD bytesTransferred = -1;12401241res = GetOverlappedResult((HANDLE)jlong_to_ptr(hFile),1242(LPOVERLAPPED)jlong_to_ptr(lpOverlapped),1243&bytesTransferred,1244TRUE);1245if (res == 0) {1246throwWindowsException(env, GetLastError());1247}12481249return (jint)bytesTransferred;1250}12511252JNIEXPORT void JNICALL1253Java_sun_nio_fs_WindowsNativeDispatcher_ReadDirectoryChangesW(JNIEnv* env, jclass this,1254jlong hDirectory, jlong bufferAddress, jint bufferLength, jboolean watchSubTree, jint filter,1255jlong bytesReturnedAddress, jlong pOverlapped)1256{1257BOOL res;1258BOOL subtree = (watchSubTree == JNI_TRUE) ? TRUE : FALSE;1259LPOVERLAPPED ov = (LPOVERLAPPED)jlong_to_ptr(pOverlapped);12601261res = ReadDirectoryChangesW((HANDLE)jlong_to_ptr(hDirectory),1262(LPVOID)jlong_to_ptr(bufferAddress),1263(DWORD)bufferLength,1264subtree,1265(DWORD)filter,1266(LPDWORD)jlong_to_ptr(bytesReturnedAddress),1267(LPOVERLAPPED)jlong_to_ptr(pOverlapped),1268NULL);1269if (res == 0) {1270throwWindowsException(env, GetLastError());1271}1272}127312741275