< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java

Print this page

   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
  23  * questions.
  24  */
  25 
  26 package sun.nio.fs;
  27 

  28 import jdk.internal.misc.Unsafe;
  29 
  30 import static sun.nio.fs.WindowsConstants.*;
  31 
  32 /**
  33  * Win32 and library calls.
  34  */
  35 
  36 class WindowsNativeDispatcher {
  37     private WindowsNativeDispatcher() { }
  38 
  39     /**
  40      * HANDLE CreateEvent(
  41      *   LPSECURITY_ATTRIBUTES lpEventAttributes,
  42      *   BOOL bManualReset,
  43      *   BOOL bInitialState,
  44      *   PCTSTR lpName
  45      * );
  46      */
  47     static native long CreateEvent(boolean bManualReset, boolean bInitialState)

  49 
  50     /**
  51      * HANDLE CreateFile(
  52      *   LPCTSTR lpFileName,
  53      *   DWORD dwDesiredAccess,
  54      *   DWORD dwShareMode,
  55      *   LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  56      *   DWORD dwCreationDisposition,
  57      *   DWORD dwFlagsAndAttributes,
  58      *   HANDLE hTemplateFile
  59      * )
  60      */
  61     static long CreateFile(String path,
  62                            int dwDesiredAccess,
  63                            int dwShareMode,
  64                            long lpSecurityAttributes,
  65                            int dwCreationDisposition,
  66                            int dwFlagsAndAttributes)
  67         throws WindowsException
  68     {
  69         NativeBuffer buffer = asNativeBuffer(path);
  70         try {
  71             return CreateFile0(buffer.address(),
  72                                dwDesiredAccess,
  73                                dwShareMode,
  74                                lpSecurityAttributes,
  75                                dwCreationDisposition,
  76                                dwFlagsAndAttributes);
  77         } finally {
  78             buffer.release();







  79         }
  80     }
  81     static long CreateFile(String path,
  82                            int dwDesiredAccess,
  83                            int dwShareMode,
  84                            int dwCreationDisposition,
  85                            int dwFlagsAndAttributes)
  86         throws WindowsException
  87     {
  88         return CreateFile(path, dwDesiredAccess, dwShareMode, 0L,
  89                           dwCreationDisposition, dwFlagsAndAttributes);
  90     }
  91     private static native long CreateFile0(long lpFileName,
  92                                            int dwDesiredAccess,
  93                                            int dwShareMode,
  94                                            long lpSecurityAttributes,
  95                                            int dwCreationDisposition,
  96                                            int dwFlagsAndAttributes)
  97         throws WindowsException;
  98 
  99     /**
 100      * CloseHandle(
 101      *   HANDLE hObject
 102      * )
 103      */
 104     static native void CloseHandle(long handle);
 105 
 106     /**
 107      * DeleteFile(
 108      *   LPCTSTR lpFileName
 109      * )
 110      */
 111     static void DeleteFile(String path) throws WindowsException {
 112         NativeBuffer buffer = asNativeBuffer(path);
 113         try {
 114             DeleteFile0(buffer.address());
 115         } finally {
 116             buffer.release();

 117         }
 118     }
 119     private static native void DeleteFile0(long lpFileName)
 120         throws WindowsException;
 121 
 122     /**
 123      * CreateDirectory(
 124      *   LPCTSTR lpPathName,
 125      *   LPSECURITY_ATTRIBUTES lpSecurityAttributes
 126      * )
 127      */
 128     static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
 129         NativeBuffer buffer = asNativeBuffer(path);
 130         try {
 131             CreateDirectory0(buffer.address(), lpSecurityAttributes);
 132         } finally {
 133             buffer.release();

 134         }
 135     }
 136     private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
 137         throws WindowsException;
 138 
 139     /**
 140      * RemoveDirectory(
 141      *   LPCTSTR lpPathName
 142      * )
 143      */
 144     static void RemoveDirectory(String path) throws WindowsException {
 145         NativeBuffer buffer = asNativeBuffer(path);
 146         try {
 147             RemoveDirectory0(buffer.address());
 148         } finally {
 149             buffer.release();

 150         }
 151     }
 152     private static native void RemoveDirectory0(long lpFileName)
 153         throws WindowsException;
 154 
 155     /**
 156      * Marks a file as a sparse file.
 157      *
 158      * DeviceIoControl(
 159      *   FSCTL_SET_SPARSE
 160      * )
 161      */
 162     static native void DeviceIoControlSetSparse(long handle)
 163         throws WindowsException;
 164 
 165     /**
 166      * Retrieves the reparse point data associated with the file or directory.
 167      *
 168      * DeviceIoControl(
 169      *   FSCTL_GET_REPARSE_POINT

 172     static native void DeviceIoControlGetReparsePoint(long handle,
 173         long bufferAddress, int bufferSize) throws WindowsException;
 174 
 175     /**
 176      * Retrieves the size of the specified file.
 177      *
 178      * BOOL GetFileSizeEx(
 179      *   HANDLE hFile,
 180      *   PLARGE_INTEGER lpFileSize
 181      * )
 182      */
 183     static native long GetFileSizeEx(long handle) throws WindowsException;
 184 
 185     /**
 186      * HANDLE FindFirstFile(
 187      *   LPCTSTR lpFileName,
 188      *   LPWIN32_FIND_DATA lpFindFileData
 189      * )
 190      */
 191     static FirstFile FindFirstFile(String path) throws WindowsException {
 192         NativeBuffer buffer = asNativeBuffer(path);
 193         try {
 194             FirstFile data = new FirstFile();
 195             FindFirstFile0(buffer.address(), data);




 196             return data;
 197         } finally {
 198             buffer.release();
 199         }
 200     }
 201     static class FirstFile {
 202         private long handle;
 203         private String name;
 204         private int attributes;
 205 
 206         private FirstFile() { }
 207         public long handle()    { return handle; }
 208         public String name()    { return name; }
 209         public int attributes() { return attributes; }
 210     }
 211     private static native void FindFirstFile0(long lpFileName, FirstFile obj)
 212         throws WindowsException;
 213 
 214     /**
 215      * HANDLE FindFirstFile(
 216      *   LPCTSTR lpFileName,
 217      *   LPWIN32_FIND_DATA lpFindFileData
 218      * )
 219      */
 220     static long FindFirstFile(String path, long address) throws WindowsException {
 221         NativeBuffer buffer = asNativeBuffer(path);
 222         try {
 223             return FindFirstFile1(buffer.address(), address);
 224         } finally {
 225             buffer.release();

 226         }
 227     }
 228     private static native long FindFirstFile1(long lpFileName, long address)
 229         throws WindowsException;
 230 
 231     /**
 232      * FindNextFile(
 233      *   HANDLE hFindFile,
 234      *   LPWIN32_FIND_DATA lpFindFileData
 235      * )
 236      *
 237      * @return  lpFindFileData->cFileName or null
 238      */
 239     static native String FindNextFile(long handle, long address)







 240         throws WindowsException;
 241 
 242     /**
 243      * HANDLE FindFirstStreamW(
 244      *   LPCWSTR lpFileName,
 245      *   STREAM_INFO_LEVELS InfoLevel,
 246      *   LPVOID lpFindStreamData,
 247      *   DWORD dwFlags
 248      * )
 249      */
 250     static FirstStream FindFirstStream(String path) throws WindowsException {
 251         NativeBuffer buffer = asNativeBuffer(path);
 252         try {
 253             FirstStream data = new FirstStream();
 254             FindFirstStream0(buffer.address(), data);




 255             if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
 256                 return null;
 257             return data;
 258         } finally {
 259             buffer.release();
 260         }
 261     }
 262     static class FirstStream {
 263         private long handle;
 264         private String name;
 265 
 266         private FirstStream() { }
 267         public long handle()    { return handle; }
 268         public String name()    { return name; }
 269     }
 270     private static native void FindFirstStream0(long lpFileName, FirstStream obj)
 271         throws WindowsException;
 272 
 273     /*
 274      * FindNextStreamW(
 275      *   HANDLE hFindStream,
 276      *   LPVOID lpFindStreamData
 277      * )
 278      */
 279     static native String FindNextStream(long handle) throws WindowsException;







 280 
 281     /**
 282      * FindClose(
 283      *   HANDLE hFindFile
 284      * )
 285      */
 286     static native void FindClose(long handle) throws WindowsException;
 287 
 288     /**
 289      * GetFileInformationByHandle(
 290      *   HANDLE hFile,
 291      *   LPBY_HANDLE_FILE_INFORMATION lpFileInformation
 292      * )
 293      */
 294     static native void GetFileInformationByHandle(long handle, long address)









 295         throws WindowsException;
 296 
 297     /**
 298      * CopyFileEx(
 299      *   LPCWSTR lpExistingFileName
 300      *   LPCWSTR lpNewFileName,
 301      *   LPPROGRESS_ROUTINE lpProgressRoutine
 302      *   LPVOID lpData,
 303      *   LPBOOL pbCancel,
 304      *   DWORD dwCopyFlags
 305      * )
 306      */
 307     static void CopyFileEx(String source, String target, int flags,
 308                            long addressToPollForCancel)
 309         throws WindowsException
 310     {
 311         NativeBuffer sourceBuffer = asNativeBuffer(source);
 312         NativeBuffer targetBuffer = asNativeBuffer(target);
 313         try {
 314             CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
 315                         addressToPollForCancel);
 316         } finally {
 317             targetBuffer.release();
 318             sourceBuffer.release();


 319         }
 320     }
 321     private static native void CopyFileEx0(long existingAddress, long newAddress,
 322         int flags, long addressToPollForCancel) throws WindowsException;
 323 
 324     /**
 325      * MoveFileEx(
 326      *   LPCTSTR lpExistingFileName,
 327      *   LPCTSTR lpNewFileName,
 328      *   DWORD dwFlags
 329      * )
 330      */
 331     static void MoveFileEx(String source, String target, int flags)
 332         throws WindowsException
 333     {
 334         NativeBuffer sourceBuffer = asNativeBuffer(source);
 335         NativeBuffer targetBuffer = asNativeBuffer(target);
 336         try {
 337             MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
 338         } finally {
 339             targetBuffer.release();
 340             sourceBuffer.release();

 341         }
 342     }
 343     private static native void MoveFileEx0(long existingAddress, long newAddress,
 344         int flags) throws WindowsException;
 345 
 346     /**
 347      * DWORD GetFileAttributes(
 348      *   LPCTSTR lpFileName
 349      * )
 350      */
 351     static int GetFileAttributes(String path) throws WindowsException {
 352         NativeBuffer buffer = asNativeBuffer(path);
 353         try {
 354             return GetFileAttributes0(buffer.address());
 355         } finally {
 356             buffer.release();

 357         }
 358     }
 359     private static native int GetFileAttributes0(long lpFileName)
 360         throws WindowsException;
 361 
 362     /**
 363      * SetFileAttributes(
 364      *   LPCTSTR lpFileName,
 365      *   DWORD dwFileAttributes
 366      */
 367     static void SetFileAttributes(String path, int dwFileAttributes)
 368         throws WindowsException
 369     {
 370         NativeBuffer buffer = asNativeBuffer(path);
 371         try {
 372             SetFileAttributes0(buffer.address(), dwFileAttributes);
 373         } finally {
 374             buffer.release();

 375         }
 376     }
 377     private static native void SetFileAttributes0(long lpFileName,
 378         int dwFileAttributes) throws WindowsException;
 379 
 380     /**
 381      * GetFileAttributesEx(
 382      *   LPCTSTR lpFileName,
 383      *   GET_FILEEX_INFO_LEVELS fInfoLevelId,
 384      *   LPVOID lpFileInformation
 385      * );
 386      */
 387     static void GetFileAttributesEx(String path, long address) throws WindowsException {
 388         NativeBuffer buffer = asNativeBuffer(path);
 389         try {
 390             GetFileAttributesEx0(buffer.address(), address);
 391         } finally {
 392             buffer.release();

 393         }
 394     }
 395     private static native void GetFileAttributesEx0(long lpFileName, long address)
 396         throws WindowsException;

 397     /**
 398      * SetFileTime(
 399      *   HANDLE hFile,
 400      *   CONST FILETIME *lpCreationTime,
 401      *   CONST FILETIME *lpLastAccessTime,
 402      *   CONST FILETIME *lpLastWriteTime
 403      * )
 404      */
 405     static native void SetFileTime(long handle,
 406                                    long createTime,
 407                                    long lastAccessTime,
 408                                    long lastWriteTime)









 409         throws WindowsException;
 410 
 411     /**
 412      * SetEndOfFile(
 413      *   HANDLE hFile
 414      * )
 415      */
 416     static native void SetEndOfFile(long handle) throws WindowsException;
 417 
 418     /**
 419      * DWORD GetLogicalDrives(VOID)
 420      */
 421     static native int GetLogicalDrives() throws WindowsException;
 422 
 423     /**
 424      * GetVolumeInformation(
 425      *   LPCTSTR lpRootPathName,
 426      *   LPTSTR lpVolumeNameBuffer,
 427      *   DWORD nVolumeNameSize,
 428      *   LPDWORD lpVolumeSerialNumber,

 603     }
 604     private static native int GetFileSecurity0(long lpFileName,
 605                                                int requestedInformation,
 606                                                long pSecurityDescriptor,
 607                                                int nLength) throws WindowsException;
 608 
 609     /**
 610      * SetFileSecurity(
 611      *   LPCTSTR lpFileName,
 612      *   SECURITY_INFORMATION SecurityInformation,
 613      *   PSECURITY_DESCRIPTOR pSecurityDescriptor
 614      * )
 615      */
 616     static void SetFileSecurity(String path,
 617                                 int securityInformation,
 618                                 long pSecurityDescriptor)
 619         throws WindowsException
 620     {
 621         NativeBuffer buffer = asNativeBuffer(path);
 622         try {
 623             SetFileSecurity0(buffer.address(), securityInformation,
 624                 pSecurityDescriptor);
 625         } finally {
 626             buffer.release();
 627         }
 628     }
 629     static native void SetFileSecurity0(long lpFileName, int securityInformation,
 630         long pSecurityDescriptor) throws WindowsException;
 631 
 632     /**
 633      * GetSecurityDescriptorOwner(
 634      *   PSECURITY_DESCRIPTOR pSecurityDescriptor
 635      *   PSID *pOwner,
 636      *   LPBOOL lpbOwnerDefaulted
 637      * )
 638      *
 639      * @return  pOwner
 640      */
 641     static native long GetSecurityDescriptorOwner(long pSecurityDescriptor)
 642         throws WindowsException;
 643 
 644     /**

   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
  23  * questions.
  24  */
  25 
  26 package sun.nio.fs;
  27 
  28 import jdk.internal.misc.Blocker;
  29 import jdk.internal.misc.Unsafe;
  30 
  31 import static sun.nio.fs.WindowsConstants.*;
  32 
  33 /**
  34  * Win32 and library calls.
  35  */
  36 
  37 class WindowsNativeDispatcher {
  38     private WindowsNativeDispatcher() { }
  39 
  40     /**
  41      * HANDLE CreateEvent(
  42      *   LPSECURITY_ATTRIBUTES lpEventAttributes,
  43      *   BOOL bManualReset,
  44      *   BOOL bInitialState,
  45      *   PCTSTR lpName
  46      * );
  47      */
  48     static native long CreateEvent(boolean bManualReset, boolean bInitialState)

  50 
  51     /**
  52      * HANDLE CreateFile(
  53      *   LPCTSTR lpFileName,
  54      *   DWORD dwDesiredAccess,
  55      *   DWORD dwShareMode,
  56      *   LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  57      *   DWORD dwCreationDisposition,
  58      *   DWORD dwFlagsAndAttributes,
  59      *   HANDLE hTemplateFile
  60      * )
  61      */
  62     static long CreateFile(String path,
  63                            int dwDesiredAccess,
  64                            int dwShareMode,
  65                            long lpSecurityAttributes,
  66                            int dwCreationDisposition,
  67                            int dwFlagsAndAttributes)
  68         throws WindowsException
  69     {
  70         try (NativeBuffer buffer = asNativeBuffer(path)) {
  71             if (Thread.currentThread().isVirtual()) {
  72                 return Blocker.managedBlock(() ->
  73                         CreateFile0(buffer.address(),
  74                                     dwDesiredAccess,
  75                                     dwShareMode,
  76                                     lpSecurityAttributes,
  77                                     dwCreationDisposition,
  78                                     dwFlagsAndAttributes));
  79             } else {
  80                 return CreateFile0(buffer.address(),
  81                                    dwDesiredAccess,
  82                                    dwShareMode,
  83                                    lpSecurityAttributes,
  84                                    dwCreationDisposition,
  85                                    dwFlagsAndAttributes);
  86             }
  87         }
  88     }
  89     static long CreateFile(String path,
  90                            int dwDesiredAccess,
  91                            int dwShareMode,
  92                            int dwCreationDisposition,
  93                            int dwFlagsAndAttributes)
  94         throws WindowsException
  95     {
  96         return CreateFile(path, dwDesiredAccess, dwShareMode, 0L,
  97                           dwCreationDisposition, dwFlagsAndAttributes);
  98     }
  99     private static native long CreateFile0(long lpFileName,
 100                                            int dwDesiredAccess,
 101                                            int dwShareMode,
 102                                            long lpSecurityAttributes,
 103                                            int dwCreationDisposition,
 104                                            int dwFlagsAndAttributes)
 105         throws WindowsException;
 106 
 107     /**
 108      * CloseHandle(
 109      *   HANDLE hObject
 110      * )
 111      */
 112     static native void CloseHandle(long handle);
 113 
 114     /**
 115      * DeleteFile(
 116      *   LPCTSTR lpFileName
 117      * )
 118      */
 119     static void DeleteFile(String path) throws WindowsException {
 120         try (NativeBuffer buffer = asNativeBuffer(path)) {
 121             if (Thread.currentThread().isVirtual()) {
 122                 Blocker.managedBlock(() -> DeleteFile0(buffer.address()));
 123             } else {
 124                 DeleteFile0(buffer.address());
 125             }
 126         }
 127     }
 128     private static native void DeleteFile0(long lpFileName)
 129         throws WindowsException;
 130 
 131     /**
 132      * CreateDirectory(
 133      *   LPCTSTR lpPathName,
 134      *   LPSECURITY_ATTRIBUTES lpSecurityAttributes
 135      * )
 136      */
 137     static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
 138         try (NativeBuffer buffer = asNativeBuffer(path)) {
 139             if (Thread.currentThread().isVirtual()) {
 140                 Blocker.managedBlock(() -> CreateDirectory0(buffer.address(), lpSecurityAttributes));
 141             } else {
 142                 CreateDirectory0(buffer.address(), lpSecurityAttributes);
 143             }
 144         }
 145     }
 146     private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
 147         throws WindowsException;
 148 
 149     /**
 150      * RemoveDirectory(
 151      *   LPCTSTR lpPathName
 152      * )
 153      */
 154     static void RemoveDirectory(String path) throws WindowsException {
 155         try (NativeBuffer buffer = asNativeBuffer(path)) {
 156             if (Thread.currentThread().isVirtual()) {
 157                 Blocker.managedBlock(() -> RemoveDirectory0(buffer.address()));
 158             } else {
 159                 RemoveDirectory0(buffer.address());
 160             }
 161         }
 162     }
 163     private static native void RemoveDirectory0(long lpFileName)
 164         throws WindowsException;
 165 
 166     /**
 167      * Marks a file as a sparse file.
 168      *
 169      * DeviceIoControl(
 170      *   FSCTL_SET_SPARSE
 171      * )
 172      */
 173     static native void DeviceIoControlSetSparse(long handle)
 174         throws WindowsException;
 175 
 176     /**
 177      * Retrieves the reparse point data associated with the file or directory.
 178      *
 179      * DeviceIoControl(
 180      *   FSCTL_GET_REPARSE_POINT

 183     static native void DeviceIoControlGetReparsePoint(long handle,
 184         long bufferAddress, int bufferSize) throws WindowsException;
 185 
 186     /**
 187      * Retrieves the size of the specified file.
 188      *
 189      * BOOL GetFileSizeEx(
 190      *   HANDLE hFile,
 191      *   PLARGE_INTEGER lpFileSize
 192      * )
 193      */
 194     static native long GetFileSizeEx(long handle) throws WindowsException;
 195 
 196     /**
 197      * HANDLE FindFirstFile(
 198      *   LPCTSTR lpFileName,
 199      *   LPWIN32_FIND_DATA lpFindFileData
 200      * )
 201      */
 202     static FirstFile FindFirstFile(String path) throws WindowsException {
 203         try (NativeBuffer buffer = asNativeBuffer(path)) {

 204             FirstFile data = new FirstFile();
 205             if (Thread.currentThread().isVirtual()) {
 206                 Blocker.managedBlock(() -> FindFirstFile0(buffer.address(), data));
 207             } else {
 208                 FindFirstFile0(buffer.address(), data);
 209             }
 210             return data;


 211         }
 212     }
 213     static class FirstFile {
 214         private long handle;
 215         private String name;
 216         private int attributes;
 217 
 218         private FirstFile() { }
 219         public long handle()    { return handle; }
 220         public String name()    { return name; }
 221         public int attributes() { return attributes; }
 222     }
 223     private static native void FindFirstFile0(long lpFileName, FirstFile obj)
 224         throws WindowsException;
 225 
 226     /**
 227      * HANDLE FindFirstFile(
 228      *   LPCTSTR lpFileName,
 229      *   LPWIN32_FIND_DATA lpFindFileData
 230      * )
 231      */
 232     static long FindFirstFile(String path, long address) throws WindowsException {
 233         try (NativeBuffer buffer = asNativeBuffer(path)) {
 234             if (Thread.currentThread().isVirtual()) {
 235                 return Blocker.managedBlock(() -> FindFirstFile1(buffer.address(), address));
 236             } else {
 237                 return FindFirstFile1(buffer.address(), address);
 238             }
 239         }
 240     }
 241     private static native long FindFirstFile1(long lpFileName, long address)
 242         throws WindowsException;
 243 
 244     /**
 245      * FindNextFile(
 246      *   HANDLE hFindFile,
 247      *   LPWIN32_FIND_DATA lpFindFileData
 248      * )
 249      *
 250      * @return  lpFindFileData->cFileName or null
 251      */
 252     static String FindNextFile(long handle, long address) throws WindowsException {
 253         if (Thread.currentThread().isVirtual()) {
 254             return Blocker.managedBlock(() -> FindNextFile0(handle, address));
 255         } else {
 256             return FindNextFile0(handle, address);
 257         }
 258     }
 259     private static native String FindNextFile0(long handle, long address)
 260         throws WindowsException;
 261 
 262     /**
 263      * HANDLE FindFirstStreamW(
 264      *   LPCWSTR lpFileName,
 265      *   STREAM_INFO_LEVELS InfoLevel,
 266      *   LPVOID lpFindStreamData,
 267      *   DWORD dwFlags
 268      * )
 269      */
 270     static FirstStream FindFirstStream(String path) throws WindowsException {
 271         try (NativeBuffer buffer = asNativeBuffer(path)) {

 272             FirstStream data = new FirstStream();
 273             if (Thread.currentThread().isVirtual()) {
 274                 Blocker.managedBlock(() -> FindFirstStream0(buffer.address(), data));
 275             } else {
 276                 FindFirstStream0(buffer.address(), data);
 277             }
 278             if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
 279                 return null;
 280             return data;


 281         }
 282     }
 283     static class FirstStream {
 284         private long handle;
 285         private String name;
 286 
 287         private FirstStream() { }
 288         public long handle()    { return handle; }
 289         public String name()    { return name; }
 290     }
 291     private static native void FindFirstStream0(long lpFileName, FirstStream obj)
 292         throws WindowsException;
 293 
 294     /*
 295      * FindNextStreamW(
 296      *   HANDLE hFindStream,
 297      *   LPVOID lpFindStreamData
 298      * )
 299      */
 300     static String FindNextStream(long handle) throws WindowsException {
 301         if (Thread.currentThread().isVirtual()) {
 302             return Blocker.managedBlock(() -> FindNextStream0(handle));
 303         } else {
 304             return FindNextStream0(handle);
 305         }
 306     }
 307     private static native String FindNextStream0(long handle) throws WindowsException;
 308 
 309     /**
 310      * FindClose(
 311      *   HANDLE hFindFile
 312      * )
 313      */
 314     static native void FindClose(long handle) throws WindowsException;
 315 
 316     /**
 317      * GetFileInformationByHandle(
 318      *   HANDLE hFile,
 319      *   LPBY_HANDLE_FILE_INFORMATION lpFileInformation
 320      * )
 321      */
 322     static void GetFileInformationByHandle(long handle, long address)
 323         throws WindowsException
 324     {
 325         if (Thread.currentThread().isVirtual()) {
 326             Blocker.managedBlock(() -> GetFileInformationByHandle0(handle, address));
 327         } else {
 328             GetFileInformationByHandle0(handle, address);
 329         }
 330     }
 331     private static native void GetFileInformationByHandle0(long handle, long address)
 332         throws WindowsException;
 333 
 334     /**
 335      * CopyFileEx(
 336      *   LPCWSTR lpExistingFileName
 337      *   LPCWSTR lpNewFileName,
 338      *   LPPROGRESS_ROUTINE lpProgressRoutine
 339      *   LPVOID lpData,
 340      *   LPBOOL pbCancel,
 341      *   DWORD dwCopyFlags
 342      * )
 343      */
 344     static void CopyFileEx(String source, String target, int flags,
 345                            long addressToPollForCancel)
 346         throws WindowsException
 347     {
 348         try (NativeBuffer sourceBuffer = asNativeBuffer(source);
 349              NativeBuffer targetBuffer = asNativeBuffer(target)) {
 350             if (Thread.currentThread().isVirtual()) {
 351                 Blocker.managedBlock(() ->
 352                     CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
 353                                 addressToPollForCancel));
 354             } else {
 355                 CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
 356                             addressToPollForCancel);
 357             }
 358         }
 359     }
 360     private static native void CopyFileEx0(long existingAddress, long newAddress,
 361         int flags, long addressToPollForCancel) throws WindowsException;
 362 
 363     /**
 364      * MoveFileEx(
 365      *   LPCTSTR lpExistingFileName,
 366      *   LPCTSTR lpNewFileName,
 367      *   DWORD dwFlags
 368      * )
 369      */
 370     static void MoveFileEx(String source, String target, int flags)
 371         throws WindowsException
 372     {
 373         try (NativeBuffer sourceBuffer = asNativeBuffer(source);
 374              NativeBuffer targetBuffer = asNativeBuffer(target)) {
 375             if (Thread.currentThread().isVirtual()) {
 376                 Blocker.managedBlock(() ->
 377                     MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags));
 378             } else {
 379                 MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
 380             }
 381         }
 382     }
 383     private static native void MoveFileEx0(long existingAddress, long newAddress,
 384         int flags) throws WindowsException;
 385 
 386     /**
 387      * DWORD GetFileAttributes(
 388      *   LPCTSTR lpFileName
 389      * )
 390      */
 391     static int GetFileAttributes(String path) throws WindowsException {
 392         try (NativeBuffer buffer = asNativeBuffer(path)) {
 393             if (Thread.currentThread().isVirtual()) {
 394                 return Blocker.managedBlock(() -> GetFileAttributes0(buffer.address()));
 395             } else {
 396                 return GetFileAttributes0(buffer.address());
 397             }
 398         }
 399     }
 400     private static native int GetFileAttributes0(long lpFileName)
 401         throws WindowsException;
 402 
 403     /**
 404      * SetFileAttributes(
 405      *   LPCTSTR lpFileName,
 406      *   DWORD dwFileAttributes
 407      */
 408     static void SetFileAttributes(String path, int dwFileAttributes)
 409         throws WindowsException
 410     {
 411         try (NativeBuffer buffer = asNativeBuffer(path)) {
 412             if (Thread.currentThread().isVirtual()) {
 413                 Blocker.managedBlock(() -> SetFileAttributes0(buffer.address(), dwFileAttributes));
 414             } else {
 415                 SetFileAttributes0(buffer.address(), dwFileAttributes);
 416             }
 417         }
 418     }
 419     private static native void SetFileAttributes0(long lpFileName,
 420         int dwFileAttributes) throws WindowsException;
 421 
 422     /**
 423      * GetFileAttributesEx(
 424      *   LPCTSTR lpFileName,
 425      *   GET_FILEEX_INFO_LEVELS fInfoLevelId,
 426      *   LPVOID lpFileInformation
 427      * );
 428      */
 429     static void GetFileAttributesEx(String path, long address) throws WindowsException {
 430         try (NativeBuffer buffer = asNativeBuffer(path)) {
 431             if (Thread.currentThread().isVirtual()) {
 432                 Blocker.managedBlock(() -> GetFileAttributesEx0(buffer.address(), address));
 433             } else {
 434                 GetFileAttributesEx0(buffer.address(), address);
 435             }
 436         }
 437     }
 438     private static native void GetFileAttributesEx0(long lpFileName, long address)
 439         throws WindowsException;
 440 
 441     /**
 442      * SetFileTime(
 443      *   HANDLE hFile,
 444      *   CONST FILETIME *lpCreationTime,
 445      *   CONST FILETIME *lpLastAccessTime,
 446      *   CONST FILETIME *lpLastWriteTime
 447      * )
 448      */
 449     static void SetFileTime(long handle, long createTime, long lastAccessTime, long lastWriteTime)
 450         throws WindowsException
 451     {
 452         if (Thread.currentThread().isVirtual()) {
 453             Blocker.managedBlock(() -> SetFileTime0(handle, createTime, lastAccessTime, lastWriteTime));
 454         } else {
 455             SetFileTime0(handle, createTime, lastAccessTime, lastWriteTime);
 456         }
 457     }
 458     private static native void SetFileTime0(long handle,
 459                                             long createTime,
 460                                             long lastAccessTime,
 461                                             long lastWriteTime)
 462         throws WindowsException;
 463 
 464     /**
 465      * SetEndOfFile(
 466      *   HANDLE hFile
 467      * )
 468      */
 469     static native void SetEndOfFile(long handle) throws WindowsException;
 470 
 471     /**
 472      * DWORD GetLogicalDrives(VOID)
 473      */
 474     static native int GetLogicalDrives() throws WindowsException;
 475 
 476     /**
 477      * GetVolumeInformation(
 478      *   LPCTSTR lpRootPathName,
 479      *   LPTSTR lpVolumeNameBuffer,
 480      *   DWORD nVolumeNameSize,
 481      *   LPDWORD lpVolumeSerialNumber,

 656     }
 657     private static native int GetFileSecurity0(long lpFileName,
 658                                                int requestedInformation,
 659                                                long pSecurityDescriptor,
 660                                                int nLength) throws WindowsException;
 661 
 662     /**
 663      * SetFileSecurity(
 664      *   LPCTSTR lpFileName,
 665      *   SECURITY_INFORMATION SecurityInformation,
 666      *   PSECURITY_DESCRIPTOR pSecurityDescriptor
 667      * )
 668      */
 669     static void SetFileSecurity(String path,
 670                                 int securityInformation,
 671                                 long pSecurityDescriptor)
 672         throws WindowsException
 673     {
 674         NativeBuffer buffer = asNativeBuffer(path);
 675         try {
 676             // may be called with elevated privileges so always run on current thread
 677             SetFileSecurity0(buffer.address(), securityInformation, pSecurityDescriptor);
 678         } finally {
 679             buffer.release();
 680         }
 681     }
 682     static native void SetFileSecurity0(long lpFileName, int securityInformation,
 683         long pSecurityDescriptor) throws WindowsException;
 684 
 685     /**
 686      * GetSecurityDescriptorOwner(
 687      *   PSECURITY_DESCRIPTOR pSecurityDescriptor
 688      *   PSID *pOwner,
 689      *   LPBOOL lpbOwnerDefaulted
 690      * )
 691      *
 692      * @return  pOwner
 693      */
 694     static native long GetSecurityDescriptorOwner(long pSecurityDescriptor)
 695         throws WindowsException;
 696 
 697     /**
< prev index next >