< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  42 
  43 /**
  44  * jfieldIDs
  45  */
  46 static jfieldID findFirst_handle;
  47 static jfieldID findFirst_name;
  48 static jfieldID findFirst_attributes;
  49 
  50 static jfieldID findStream_handle;
  51 static jfieldID findStream_name;
  52 
  53 static jfieldID volumeInfo_fsName;
  54 static jfieldID volumeInfo_volName;
  55 static jfieldID volumeInfo_volSN;
  56 static jfieldID volumeInfo_flags;
  57 
  58 static jfieldID diskSpace_bytesAvailable;
  59 static jfieldID diskSpace_totalBytes;
  60 static jfieldID diskSpace_totalFree;
  61 


  62 static jfieldID account_domain;
  63 static jfieldID account_name;
  64 static jfieldID account_use;
  65 
  66 static jfieldID aclInfo_aceCount;
  67 
  68 static jfieldID completionStatus_error;
  69 static jfieldID completionStatus_bytesTransferred;
  70 static jfieldID completionStatus_completionKey;
  71 
  72 static void throwWindowsException(JNIEnv* env, DWORD lastError) {
  73     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/WindowsException",
  74         "(I)V", lastError);
  75     if (x != NULL) {
  76         (*env)->Throw(env, x);
  77     }
  78 }
  79 
  80 /**
  81  * Initializes jfieldIDs and get address of Win32 calls that are located


 104 
 105     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation");
 106     CHECK_NULL(clazz);
 107     volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;");
 108     CHECK_NULL(volumeInfo_fsName);
 109     volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;");
 110     CHECK_NULL(volumeInfo_volName);
 111     volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I");
 112     CHECK_NULL(volumeInfo_volSN);
 113     volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I");
 114     CHECK_NULL(volumeInfo_flags);
 115 
 116     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace");
 117     CHECK_NULL(clazz);
 118     diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J");
 119     CHECK_NULL(diskSpace_bytesAvailable);
 120     diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J");
 121     CHECK_NULL(diskSpace_totalBytes);
 122     diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J");
 123     CHECK_NULL(diskSpace_totalFree);


 124 
 125     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account");
 126     CHECK_NULL(clazz);
 127     account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;");
 128     CHECK_NULL(account_domain);
 129     account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
 130     CHECK_NULL(account_name);
 131     account_use = (*env)->GetFieldID(env, clazz, "use", "I");
 132     CHECK_NULL(account_use);
 133 
 134     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation");
 135     CHECK_NULL(clazz);
 136     aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I");
 137     CHECK_NULL(aclInfo_aceCount);
 138 
 139     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus");
 140     CHECK_NULL(clazz);
 141     completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
 142     CHECK_NULL(completionStatus_error);
 143     completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");


 565     LPCWSTR lpDirName = jlong_to_ptr(address);
 566 
 567 
 568     BOOL res = GetDiskFreeSpaceExW(lpDirName,
 569                                    &freeBytesAvailable,
 570                                    &totalNumberOfBytes,
 571                                    &totalNumberOfFreeBytes);
 572     if (res == 0) {
 573         throwWindowsException(env, GetLastError());
 574         return;
 575     }
 576 
 577     (*env)->SetLongField(env, obj, diskSpace_bytesAvailable,
 578         long_to_jlong(freeBytesAvailable.QuadPart));
 579     (*env)->SetLongField(env, obj, diskSpace_totalBytes,
 580         long_to_jlong(totalNumberOfBytes.QuadPart));
 581     (*env)->SetLongField(env, obj, diskSpace_totalFree,
 582         long_to_jlong(totalNumberOfFreeBytes.QuadPart));
 583 }
 584 
























 585 
 586 JNIEXPORT jstring JNICALL
 587 Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumePathName0(JNIEnv* env, jclass this,
 588     jlong address)
 589 {
 590     WCHAR volumeName[MAX_PATH+1];
 591     LPCWSTR lpFileName = jlong_to_ptr(address);
 592 
 593 
 594     BOOL res = GetVolumePathNameW(lpFileName,
 595                                   &volumeName[0],
 596                                   MAX_PATH+1);
 597     if (res == 0) {
 598         throwWindowsException(env, GetLastError());
 599         return NULL;
 600     } else {
 601         return (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName));
 602     }
 603 }
 604 


   1 /*
   2  * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  42 
  43 /**
  44  * jfieldIDs
  45  */
  46 static jfieldID findFirst_handle;
  47 static jfieldID findFirst_name;
  48 static jfieldID findFirst_attributes;
  49 
  50 static jfieldID findStream_handle;
  51 static jfieldID findStream_name;
  52 
  53 static jfieldID volumeInfo_fsName;
  54 static jfieldID volumeInfo_volName;
  55 static jfieldID volumeInfo_volSN;
  56 static jfieldID volumeInfo_flags;
  57 
  58 static jfieldID diskSpace_bytesAvailable;
  59 static jfieldID diskSpace_totalBytes;
  60 static jfieldID diskSpace_totalFree;
  61 
  62 static jfieldID diskSpace_bytesPerSector;
  63 
  64 static jfieldID account_domain;
  65 static jfieldID account_name;
  66 static jfieldID account_use;
  67 
  68 static jfieldID aclInfo_aceCount;
  69 
  70 static jfieldID completionStatus_error;
  71 static jfieldID completionStatus_bytesTransferred;
  72 static jfieldID completionStatus_completionKey;
  73 
  74 static void throwWindowsException(JNIEnv* env, DWORD lastError) {
  75     jobject x = JNU_NewObjectByName(env, "sun/nio/fs/WindowsException",
  76         "(I)V", lastError);
  77     if (x != NULL) {
  78         (*env)->Throw(env, x);
  79     }
  80 }
  81 
  82 /**
  83  * Initializes jfieldIDs and get address of Win32 calls that are located


 106 
 107     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation");
 108     CHECK_NULL(clazz);
 109     volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;");
 110     CHECK_NULL(volumeInfo_fsName);
 111     volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;");
 112     CHECK_NULL(volumeInfo_volName);
 113     volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I");
 114     CHECK_NULL(volumeInfo_volSN);
 115     volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I");
 116     CHECK_NULL(volumeInfo_flags);
 117 
 118     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace");
 119     CHECK_NULL(clazz);
 120     diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J");
 121     CHECK_NULL(diskSpace_bytesAvailable);
 122     diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J");
 123     CHECK_NULL(diskSpace_totalBytes);
 124     diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J");
 125     CHECK_NULL(diskSpace_totalFree);
 126     diskSpace_bytesPerSector = (*env)->GetFieldID(env, clazz, "bytesPerSector", "J");
 127     CHECK_NULL(diskSpace_bytesPerSector);
 128 
 129     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account");
 130     CHECK_NULL(clazz);
 131     account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;");
 132     CHECK_NULL(account_domain);
 133     account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
 134     CHECK_NULL(account_name);
 135     account_use = (*env)->GetFieldID(env, clazz, "use", "I");
 136     CHECK_NULL(account_use);
 137 
 138     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation");
 139     CHECK_NULL(clazz);
 140     aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I");
 141     CHECK_NULL(aclInfo_aceCount);
 142 
 143     clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus");
 144     CHECK_NULL(clazz);
 145     completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
 146     CHECK_NULL(completionStatus_error);
 147     completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");


 569     LPCWSTR lpDirName = jlong_to_ptr(address);
 570 
 571 
 572     BOOL res = GetDiskFreeSpaceExW(lpDirName,
 573                                    &freeBytesAvailable,
 574                                    &totalNumberOfBytes,
 575                                    &totalNumberOfFreeBytes);
 576     if (res == 0) {
 577         throwWindowsException(env, GetLastError());
 578         return;
 579     }
 580 
 581     (*env)->SetLongField(env, obj, diskSpace_bytesAvailable,
 582         long_to_jlong(freeBytesAvailable.QuadPart));
 583     (*env)->SetLongField(env, obj, diskSpace_totalBytes,
 584         long_to_jlong(totalNumberOfBytes.QuadPart));
 585     (*env)->SetLongField(env, obj, diskSpace_totalFree,
 586         long_to_jlong(totalNumberOfFreeBytes.QuadPart));
 587 }
 588 
 589 JNIEXPORT void JNICALL
 590 Java_sun_nio_fs_WindowsNativeDispatcher_GetDiskFreeSpace0(JNIEnv* env, jclass this,
 591     jlong address, jobject obj)
 592 {
 593     DWORD sectorsPerCluster;
 594     DWORD bytesPerSector;
 595     DWORD numberOfFreeClusters;
 596     DWORD totalNumberOfClusters;
 597     LPCWSTR lpRootPathName = jlong_to_ptr(address);
 598 
 599 
 600     BOOL res = GetDiskFreeSpaceW(lpRootPathName,
 601                                  &sectorsPerCluster,
 602                                  &bytesPerSector,
 603                                  &numberOfFreeClusters,
 604                                  &totalNumberOfClusters);
 605     if (res == 0) {
 606         throwWindowsException(env, GetLastError());
 607         return;
 608     }
 609 
 610     (*env)->SetLongField(env, obj, diskSpace_bytesPerSector,
 611         long_to_jlong(bytesPerSector));
 612 }
 613 
 614 JNIEXPORT jstring JNICALL
 615 Java_sun_nio_fs_WindowsNativeDispatcher_GetVolumePathName0(JNIEnv* env, jclass this,
 616     jlong address)
 617 {
 618     WCHAR volumeName[MAX_PATH+1];
 619     LPCWSTR lpFileName = jlong_to_ptr(address);
 620 
 621 
 622     BOOL res = GetVolumePathNameW(lpFileName,
 623                                   &volumeName[0],
 624                                   MAX_PATH+1);
 625     if (res == 0) {
 626         throwWindowsException(env, GetLastError());
 627         return NULL;
 628     } else {
 629         return (*env)->NewString(env, (const jchar *)volumeName, (jsize)wcslen(volumeName));
 630     }
 631 }
 632 


< prev index next >