893N/A/*
2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/Apackage sun.nio.fs;
893N/A
893N/Aimport java.security.AccessController;
893N/Aimport java.security.PrivilegedAction;
893N/Aimport sun.misc.Unsafe;
893N/A
893N/A/**
893N/A * Win32 and library calls.
893N/A */
893N/A
893N/Aclass WindowsNativeDispatcher {
893N/A private WindowsNativeDispatcher() { }
893N/A
893N/A /**
893N/A * HANDLE CreateFile(
893N/A * LPCTSTR lpFileName,
893N/A * DWORD dwDesiredAccess,
893N/A * DWORD dwShareMode,
893N/A * LPSECURITY_ATTRIBUTES lpSecurityAttributes,
893N/A * DWORD dwCreationDisposition,
893N/A * DWORD dwFlagsAndAttributes,
893N/A * HANDLE hTemplateFile
893N/A * )
893N/A */
893N/A static long CreateFile(String path,
893N/A int dwDesiredAccess,
893N/A int dwShareMode,
893N/A long lpSecurityAttributes,
893N/A int dwCreationDisposition,
893N/A int dwFlagsAndAttributes)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return CreateFile0(buffer.address(),
893N/A dwDesiredAccess,
893N/A dwShareMode,
893N/A lpSecurityAttributes,
893N/A dwCreationDisposition,
893N/A dwFlagsAndAttributes);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static long CreateFile(String path,
893N/A int dwDesiredAccess,
893N/A int dwShareMode,
893N/A int dwCreationDisposition,
893N/A int dwFlagsAndAttributes)
893N/A throws WindowsException
893N/A {
893N/A return CreateFile(path, dwDesiredAccess, dwShareMode, 0L,
893N/A dwCreationDisposition, dwFlagsAndAttributes);
893N/A }
893N/A private static native long CreateFile0(long lpFileName,
893N/A int dwDesiredAccess,
893N/A int dwShareMode,
893N/A long lpSecurityAttributes,
893N/A int dwCreationDisposition,
893N/A int dwFlagsAndAttributes)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * CloseHandle(
893N/A * HANDLE hObject
893N/A * )
893N/A */
893N/A static native void CloseHandle(long handle);
893N/A
893N/A /**
893N/A * DeleteFile(
893N/A * LPCTSTR lpFileName
893N/A * )
893N/A */
893N/A static void DeleteFile(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A DeleteFile0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native void DeleteFile0(long lpFileName)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * CreateDirectory(
893N/A * LPCTSTR lpPathName,
893N/A * LPSECURITY_ATTRIBUTES lpSecurityAttributes
893N/A * )
893N/A */
893N/A static void CreateDirectory(String path, long lpSecurityAttributes) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A CreateDirectory0(buffer.address(), lpSecurityAttributes);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native void CreateDirectory0(long lpFileName, long lpSecurityAttributes)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * RemoveDirectory(
893N/A * LPCTSTR lpPathName
893N/A * )
893N/A */
893N/A static void RemoveDirectory(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A RemoveDirectory0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native void RemoveDirectory0(long lpFileName)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * Marks a file as a sparse file.
893N/A *
893N/A * DeviceIoControl(
893N/A * FSCTL_SET_SPARSE
893N/A * )
893N/A */
893N/A static native void DeviceIoControlSetSparse(long handle)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * Retrieves the reparse point data associated with the file or directory.
893N/A *
893N/A * DeviceIoControl(
893N/A * FSCTL_GET_REPARSE_POINT
893N/A * )
893N/A */
893N/A static native void DeviceIoControlGetReparsePoint(long handle,
893N/A long bufferAddress, int bufferSize) throws WindowsException;
893N/A
893N/A /**
893N/A * HANDLE FindFirstFile(
893N/A * LPCTSTR lpFileName,
893N/A * LPWIN32_FIND_DATA lpFindFileData
893N/A * )
893N/A */
893N/A static FirstFile FindFirstFile(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A FirstFile data = new FirstFile();
893N/A FindFirstFile0(buffer.address(), data);
893N/A return data;
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static class FirstFile {
893N/A private long handle;
893N/A private String name;
1576N/A private int attributes;
893N/A
893N/A private FirstFile() { }
893N/A public long handle() { return handle; }
893N/A public String name() { return name; }
1576N/A public int attributes() { return attributes; }
893N/A }
893N/A private static native void FindFirstFile0(long lpFileName, FirstFile obj)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * HANDLE FindFirstFile(
893N/A * LPCTSTR lpFileName,
893N/A * LPWIN32_FIND_DATA lpFindFileData
893N/A * )
893N/A */
893N/A static long FindFirstFile(String path, long address) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return FindFirstFile1(buffer.address(), address);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native long FindFirstFile1(long lpFileName, long address)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * FindNextFile(
893N/A * HANDLE hFindFile,
893N/A * LPWIN32_FIND_DATA lpFindFileData
893N/A * )
893N/A *
907N/A * @return lpFindFileData->cFileName or null
893N/A */
907N/A static native String FindNextFile(long handle, long address)
907N/A throws WindowsException;
893N/A
893N/A /**
893N/A * HANDLE FindFirstStreamW(
893N/A * LPCWSTR lpFileName,
893N/A * STREAM_INFO_LEVELS InfoLevel,
893N/A * LPVOID lpFindStreamData,
893N/A * DWORD dwFlags
893N/A * )
893N/A */
893N/A static FirstStream FindFirstStream(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A FirstStream data = new FirstStream();
893N/A FindFirstStream0(buffer.address(), data);
893N/A if (data.handle() == WindowsConstants.INVALID_HANDLE_VALUE)
893N/A return null;
893N/A return data;
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static class FirstStream {
893N/A private long handle;
893N/A private String name;
893N/A
893N/A private FirstStream() { }
893N/A public long handle() { return handle; }
893N/A public String name() { return name; }
893N/A }
893N/A private static native void FindFirstStream0(long lpFileName, FirstStream obj)
893N/A throws WindowsException;
893N/A
893N/A /*
893N/A * FindNextStreamW(
893N/A * HANDLE hFindStream,
893N/A * LPVOID lpFindStreamData
893N/A * )
893N/A */
893N/A static native String FindNextStream(long handle) throws WindowsException;
893N/A
893N/A /**
893N/A * FindClose(
893N/A * HANDLE hFindFile
893N/A * )
893N/A */
893N/A static native void FindClose(long handle) throws WindowsException;
893N/A
893N/A /**
893N/A * GetFileInformationByHandle(
893N/A * HANDLE hFile,
893N/A * LPBY_HANDLE_FILE_INFORMATION lpFileInformation
893N/A * )
893N/A */
893N/A static native void GetFileInformationByHandle(long handle, long address)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * CopyFileEx(
893N/A * LPCWSTR lpExistingFileName
893N/A * LPCWSTR lpNewFileName,
893N/A * LPPROGRESS_ROUTINE lpProgressRoutine
893N/A * LPVOID lpData,
893N/A * LPBOOL pbCancel,
893N/A * DWORD dwCopyFlags
893N/A * )
893N/A */
893N/A static void CopyFileEx(String source, String target, int flags,
893N/A long addressToPollForCancel)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer sourceBuffer = asNativeBuffer(source);
893N/A NativeBuffer targetBuffer = asNativeBuffer(target);
893N/A try {
893N/A CopyFileEx0(sourceBuffer.address(), targetBuffer.address(), flags,
893N/A addressToPollForCancel);
893N/A } finally {
893N/A targetBuffer.release();
893N/A sourceBuffer.release();
893N/A }
893N/A }
893N/A private static native void CopyFileEx0(long existingAddress, long newAddress,
893N/A int flags, long addressToPollForCancel) throws WindowsException;
893N/A
893N/A /**
893N/A * MoveFileEx(
893N/A * LPCTSTR lpExistingFileName,
893N/A * LPCTSTR lpNewFileName,
893N/A * DWORD dwFlags
893N/A * )
893N/A */
893N/A static void MoveFileEx(String source, String target, int flags)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer sourceBuffer = asNativeBuffer(source);
893N/A NativeBuffer targetBuffer = asNativeBuffer(target);
893N/A try {
893N/A MoveFileEx0(sourceBuffer.address(), targetBuffer.address(), flags);
893N/A } finally {
893N/A targetBuffer.release();
893N/A sourceBuffer.release();
893N/A }
893N/A }
893N/A private static native void MoveFileEx0(long existingAddress, long newAddress,
893N/A int flags) throws WindowsException;
893N/A
893N/A /**
893N/A * DWORD GetFileAttributes(
893N/A * LPCTSTR lpFileName
893N/A * )
893N/A */
893N/A static int GetFileAttributes(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return GetFileAttributes0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native int GetFileAttributes0(long lpFileName)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * SetFileAttributes(
893N/A * LPCTSTR lpFileName,
893N/A * DWORD dwFileAttributes
893N/A */
893N/A static void SetFileAttributes(String path, int dwFileAttributes)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A SetFileAttributes0(buffer.address(), dwFileAttributes);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native void SetFileAttributes0(long lpFileName,
893N/A int dwFileAttributes) throws WindowsException;
893N/A
893N/A /**
893N/A * GetFileAttributesEx(
893N/A * LPCTSTR lpFileName,
893N/A * GET_FILEEX_INFO_LEVELS fInfoLevelId,
893N/A * LPVOID lpFileInformation
893N/A * );
893N/A */
893N/A static void GetFileAttributesEx(String path, long address) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A GetFileAttributesEx0(buffer.address(), address);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native void GetFileAttributesEx0(long lpFileName, long address)
893N/A throws WindowsException;
893N/A /**
893N/A * SetFileTime(
893N/A * HANDLE hFile,
893N/A * CONST FILETIME *lpCreationTime,
893N/A * CONST FILETIME *lpLastAccessTime,
893N/A * CONST FILETIME *lpLastWriteTime
893N/A * )
893N/A */
1319N/A static native void SetFileTime(long handle,
1319N/A long createTime,
1319N/A long lastAccessTime,
1319N/A long lastWriteTime)
1319N/A throws WindowsException;
893N/A
893N/A /**
893N/A * SetEndOfFile(
893N/A * HANDLE hFile
893N/A * )
893N/A */
893N/A static native void SetEndOfFile(long handle) throws WindowsException;
893N/A
893N/A /**
893N/A * DWORD GetLogicalDrives(VOID)
893N/A */
893N/A static native int GetLogicalDrives() throws WindowsException;
893N/A
893N/A /**
893N/A * GetVolumeInformation(
893N/A * LPCTSTR lpRootPathName,
893N/A * LPTSTR lpVolumeNameBuffer,
893N/A * DWORD nVolumeNameSize,
893N/A * LPDWORD lpVolumeSerialNumber,
893N/A * LPDWORD lpMaximumComponentLength,
893N/A * LPDWORD lpFileSystemFlags,
893N/A * LPTSTR lpFileSystemNameBuffer,
893N/A * DWORD nFileSystemNameSize
893N/A * )
893N/A */
893N/A static VolumeInformation GetVolumeInformation(String root)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(root);
893N/A try {
893N/A VolumeInformation info = new VolumeInformation();
893N/A GetVolumeInformation0(buffer.address(), info);
893N/A return info;
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static class VolumeInformation {
893N/A private String fileSystemName;
893N/A private String volumeName;
893N/A private int volumeSerialNumber;
893N/A private int flags;
893N/A private VolumeInformation() { }
893N/A
893N/A public String fileSystemName() { return fileSystemName; }
893N/A public String volumeName() { return volumeName; }
893N/A public int volumeSerialNumber() { return volumeSerialNumber; }
893N/A public int flags() { return flags; }
893N/A }
893N/A private static native void GetVolumeInformation0(long lpRoot,
893N/A VolumeInformation obj)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * UINT GetDriveType(
893N/A * LPCTSTR lpRootPathName
893N/A * )
893N/A */
893N/A static int GetDriveType(String root) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(root);
893N/A try {
893N/A return GetDriveType0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native int GetDriveType0(long lpRoot) throws WindowsException;
893N/A
893N/A /**
893N/A * GetDiskFreeSpaceEx(
893N/A * LPCTSTR lpDirectoryName,
893N/A * PULARGE_INTEGER lpFreeBytesAvailableToCaller,
893N/A * PULARGE_INTEGER lpTotalNumberOfBytes,
893N/A * PULARGE_INTEGER lpTotalNumberOfFreeBytes
893N/A * )
893N/A */
893N/A static DiskFreeSpace GetDiskFreeSpaceEx(String path)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A DiskFreeSpace space = new DiskFreeSpace();
893N/A GetDiskFreeSpaceEx0(buffer.address(), space);
893N/A return space;
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static class DiskFreeSpace {
893N/A private long freeBytesAvailable;
893N/A private long totalNumberOfBytes;
893N/A private long totalNumberOfFreeBytes;
893N/A private DiskFreeSpace() { }
893N/A
893N/A public long freeBytesAvailable() { return freeBytesAvailable; }
893N/A public long totalNumberOfBytes() { return totalNumberOfBytes; }
893N/A public long totalNumberOfFreeBytes() { return totalNumberOfFreeBytes; }
893N/A }
893N/A private static native void GetDiskFreeSpaceEx0(long lpDirectoryName,
893N/A DiskFreeSpace obj)
893N/A throws WindowsException;
893N/A
893N/A
893N/A /**
893N/A * GetVolumePathName(
893N/A * LPCTSTR lpszFileName,
893N/A * LPTSTR lpszVolumePathName,
893N/A * DWORD cchBufferLength
893N/A * )
893N/A *
893N/A * @return lpFileName
893N/A */
893N/A static String GetVolumePathName(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return GetVolumePathName0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native String GetVolumePathName0(long lpFileName)
893N/A throws WindowsException;
893N/A
893N/A
893N/A /**
893N/A * InitializeSecurityDescriptor(
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
893N/A * DWORD dwRevision
893N/A * )
893N/A */
893N/A static native void InitializeSecurityDescriptor(long sdAddress)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * InitializeAcl(
893N/A * PACL pAcl,
893N/A * DWORD nAclLength,
893N/A * DWORD dwAclRevision
893N/A * )
893N/A */
893N/A static native void InitializeAcl(long aclAddress, int size)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * GetFileSecurity(
893N/A * LPCTSTR lpFileName,
893N/A * SECURITY_INFORMATION RequestedInformation,
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
893N/A * DWORD nLength,
893N/A * LPDWORD lpnLengthNeeded
893N/A * )
893N/A */
893N/A static int GetFileSecurity(String path,
893N/A int requestedInformation,
893N/A long pSecurityDescriptor,
893N/A int nLength) throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return GetFileSecurity0(buffer.address(), requestedInformation,
893N/A pSecurityDescriptor, nLength);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native int GetFileSecurity0(long lpFileName,
893N/A int requestedInformation,
893N/A long pSecurityDescriptor,
893N/A int nLength) throws WindowsException;
893N/A
893N/A /**
893N/A * SetFileSecurity(
893N/A * LPCTSTR lpFileName,
893N/A * SECURITY_INFORMATION SecurityInformation,
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor
893N/A * )
893N/A */
893N/A static void SetFileSecurity(String path,
893N/A int securityInformation,
893N/A long pSecurityDescriptor)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A SetFileSecurity0(buffer.address(), securityInformation,
893N/A pSecurityDescriptor);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A static native void SetFileSecurity0(long lpFileName, int securityInformation,
893N/A long pSecurityDescriptor) throws WindowsException;
893N/A
893N/A /**
893N/A * GetSecurityDescriptorOwner(
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor
893N/A * PSID *pOwner,
893N/A * LPBOOL lpbOwnerDefaulted
893N/A * )
893N/A *
893N/A * @return pOwner
893N/A */
893N/A static native long GetSecurityDescriptorOwner(long pSecurityDescriptor)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * SetSecurityDescriptorOwner(
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
893N/A * PSID pOwner,
893N/A * BOOL bOwnerDefaulted
893N/A * )
893N/A */
893N/A static native void SetSecurityDescriptorOwner(long pSecurityDescriptor,
893N/A long pOwner)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * GetSecurityDescriptorDacl(
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
893N/A * LPBOOL lpbDaclPresent,
893N/A * PACL *pDacl,
893N/A * LPBOOL lpbDaclDefaulted
893N/A * )
893N/A */
893N/A static native long GetSecurityDescriptorDacl(long pSecurityDescriptor);
893N/A
893N/A /**
893N/A * SetSecurityDescriptorDacl(
893N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
893N/A * BOOL bDaclPresent,
893N/A * PACL pDacl,
893N/A * BOOL bDaclDefaulted
893N/A * )
893N/A */
893N/A static native void SetSecurityDescriptorDacl(long pSecurityDescriptor, long pAcl)
893N/A throws WindowsException;
893N/A
893N/A
893N/A /**
893N/A * GetAclInformation(
893N/A * PACL pAcl,
893N/A * LPVOID pAclInformation,
893N/A * DWORD nAclInformationLength,
893N/A * ACL_INFORMATION_CLASS dwAclInformationClass
893N/A * )
893N/A */
893N/A static AclInformation GetAclInformation(long aclAddress) {
893N/A AclInformation info = new AclInformation();
893N/A GetAclInformation0(aclAddress, info);
893N/A return info;
893N/A }
893N/A static class AclInformation {
893N/A private int aceCount;
893N/A private AclInformation() { }
893N/A
893N/A public int aceCount() { return aceCount; }
893N/A }
893N/A private static native void GetAclInformation0(long aclAddress,
893N/A AclInformation obj);
893N/A
893N/A /**
893N/A * GetAce(
893N/A * PACL pAcl,
893N/A * DWORD dwAceIndex,
893N/A * LPVOID *pAce
893N/A * )
893N/A */
893N/A static native long GetAce(long aclAddress, int aceIndex);
893N/A
893N/A /**
893N/A * AddAccessAllowedAceEx(
893N/A * PACL pAcl,
893N/A * DWORD dwAceRevision,
893N/A * DWORD AceFlags,
893N/A * DWORD AccessMask,
893N/A * PSID pSid
893N/A * )
893N/A */
893N/A static native void AddAccessAllowedAceEx(long aclAddress, int flags,
893N/A int mask, long sidAddress) throws WindowsException;
893N/A
893N/A /**
893N/A * AddAccessDeniedAceEx(
893N/A * PACL pAcl,
893N/A * DWORD dwAceRevision,
893N/A * DWORD AceFlags,
893N/A * DWORD AccessMask,
893N/A * PSID pSid
893N/A * )
893N/A */
893N/A static native void AddAccessDeniedAceEx(long aclAddress, int flags,
893N/A int mask, long sidAddress) throws WindowsException;
893N/A
893N/A /**
893N/A * LookupAccountSid(
893N/A * LPCTSTR lpSystemName,
893N/A * PSID Sid,
893N/A * LPTSTR Name,
893N/A * LPDWORD cbName,
893N/A * LPTSTR ReferencedDomainName,
893N/A * LPDWORD cbReferencedDomainName,
893N/A * PSID_NAME_USE peUse
893N/A * )
893N/A */
893N/A static Account LookupAccountSid(long sidAddress) throws WindowsException {
893N/A Account acc = new Account();
893N/A LookupAccountSid0(sidAddress, acc);
893N/A return acc;
893N/A }
893N/A static class Account {
893N/A private String domain;
893N/A private String name;
893N/A private int use;
893N/A private Account() { }
893N/A
893N/A public String domain() { return domain; }
893N/A public String name() { return name; }
893N/A public int use() { return use; }
893N/A }
893N/A private static native void LookupAccountSid0(long sidAddress, Account obj)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * LookupAccountName(
893N/A * LPCTSTR lpSystemName,
893N/A * LPCTSTR lpAccountName,
893N/A * PSID Sid,
893N/A * LPDWORD cbSid,
893N/A * LPTSTR ReferencedDomainName,
893N/A * LPDWORD cbReferencedDomainName,
893N/A * PSID_NAME_USE peUse
893N/A * )
893N/A *
893N/A * @return cbSid
893N/A */
893N/A static int LookupAccountName(String accountName,
893N/A long pSid,
893N/A int cbSid) throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(accountName);
893N/A try {
893N/A return LookupAccountName0(buffer.address(), pSid, cbSid);
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native int LookupAccountName0(long lpAccountName, long pSid,
893N/A int cbSid) throws WindowsException;
893N/A
893N/A /**
893N/A * DWORD GetLengthSid(
893N/A * PSID pSid
893N/A * )
893N/A */
893N/A static native int GetLengthSid(long sidAddress);
893N/A
893N/A /**
893N/A * ConvertSidToStringSid(
893N/A * PSID Sid,
893N/A * LPTSTR* StringSid
893N/A * )
893N/A *
893N/A * @return StringSid
893N/A */
893N/A static native String ConvertSidToStringSid(long sidAddress)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * ConvertStringSidToSid(
893N/A * LPCTSTR StringSid,
893N/A * PSID* pSid
893N/A * )
893N/A *
893N/A * @return pSid
893N/A */
893N/A static long ConvertStringSidToSid(String sidString)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer buffer = asNativeBuffer(sidString);
893N/A try {
893N/A return ConvertStringSidToSid0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native long ConvertStringSidToSid0(long lpStringSid)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * HANDLE GetCurrentProcess(VOID)
893N/A */
893N/A static native long GetCurrentProcess();
893N/A
893N/A /**
893N/A * HANDLE GetCurrentThread(VOID)
893N/A */
893N/A static native long GetCurrentThread();
893N/A
893N/A /**
893N/A * OpenProcessToken(
893N/A * HANDLE ProcessHandle,
893N/A * DWORD DesiredAccess,
893N/A * PHANDLE TokenHandle
893N/A * )
893N/A */
893N/A static native long OpenProcessToken(long hProcess, int desiredAccess)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * OpenThreadToken(
893N/A * HANDLE ThreadHandle,
893N/A * DWORD DesiredAccess,
893N/A * BOOL OpenAsSelf,
893N/A * PHANDLE TokenHandle
893N/A * )
893N/A */
893N/A static native long OpenThreadToken(long hThread, int desiredAccess,
893N/A boolean openAsSelf) throws WindowsException;
893N/A
893N/A /**
893N/A */
893N/A static native long DuplicateTokenEx(long hThread, int desiredAccess)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * SetThreadToken(
893N/A * PHANDLE Thread,
893N/A * HANDLE Token
893N/A * )
893N/A */
893N/A static native void SetThreadToken(long thread, long hToken)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * GetTokenInformation(
893N/A * HANDLE TokenHandle,
893N/A * TOKEN_INFORMATION_CLASS TokenInformationClass,
893N/A * LPVOID TokenInformation,
893N/A * DWORD TokenInformationLength,
893N/A * PDWORD ReturnLength
893N/A * )
893N/A */
893N/A static native int GetTokenInformation(long token, int tokenInfoClass,
893N/A long pTokenInfo, int tokenInfoLength) throws WindowsException;
893N/A
893N/A /**
893N/A * AdjustTokenPrivileges(
893N/A * HANDLE TokenHandle,
893N/A * BOOL DisableAllPrivileges
893N/A * PTOKEN_PRIVILEGES NewState
893N/A * DWORD BufferLength
893N/A * PTOKEN_PRIVILEGES
893N/A * PDWORD ReturnLength
893N/A * )
893N/A */
893N/A static native void AdjustTokenPrivileges(long token, long luid, int attributes)
893N/A throws WindowsException;
893N/A
6091N/A
6091N/A /**
6091N/A * AccessCheck(
6091N/A * PSECURITY_DESCRIPTOR pSecurityDescriptor,
6091N/A * HANDLE ClientToken,
6091N/A * DWORD DesiredAccess,
6091N/A * PGENERIC_MAPPING GenericMapping,
6091N/A * PPRIVILEGE_SET PrivilegeSet,
6091N/A * LPDWORD PrivilegeSetLength,
6091N/A * LPDWORD GrantedAccess,
6091N/A * LPBOOL AccessStatus
6091N/A * )
6091N/A */
6091N/A static native boolean AccessCheck(long token, long securityInfo, int accessMask,
6091N/A int genericRead, int genericWrite, int genericExecute, int genericAll)
6091N/A throws WindowsException;
6091N/A
893N/A /**
893N/A */
893N/A static long LookupPrivilegeValue(String name) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(name);
893N/A try {
893N/A return LookupPrivilegeValue0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native long LookupPrivilegeValue0(long lpName)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * CreateSymbolicLink(
893N/A * LPCWSTR lpSymlinkFileName,
893N/A * LPCWSTR lpTargetFileName,
893N/A * DWORD dwFlags
893N/A * )
893N/A */
893N/A static void CreateSymbolicLink(String link, String target, int flags)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer linkBuffer = asNativeBuffer(link);
893N/A NativeBuffer targetBuffer = asNativeBuffer(target);
893N/A try {
893N/A CreateSymbolicLink0(linkBuffer.address(), targetBuffer.address(),
893N/A flags);
893N/A } finally {
893N/A targetBuffer.release();
893N/A linkBuffer.release();
893N/A }
893N/A }
893N/A private static native void CreateSymbolicLink0(long linkAddress,
893N/A long targetAddress, int flags) throws WindowsException;
893N/A
893N/A /**
893N/A * CreateHardLink(
893N/A * LPCTSTR lpFileName,
893N/A * LPCTSTR lpExistingFileName,
893N/A * LPSECURITY_ATTRIBUTES lpSecurityAttributes
893N/A * )
893N/A */
893N/A static void CreateHardLink(String newFile, String existingFile)
893N/A throws WindowsException
893N/A {
893N/A NativeBuffer newFileBuffer = asNativeBuffer(newFile);
893N/A NativeBuffer existingFileBuffer = asNativeBuffer(existingFile);
893N/A try {
893N/A CreateHardLink0(newFileBuffer.address(), existingFileBuffer.address());
893N/A } finally {
893N/A existingFileBuffer.release();
893N/A newFileBuffer.release();
893N/A }
893N/A }
893N/A private static native void CreateHardLink0(long newFileBuffer,
893N/A long existingFiletBuffer) throws WindowsException;
893N/A
893N/A /**
893N/A * GetFullPathName(
893N/A * LPCTSTR lpFileName,
893N/A * DWORD nBufferLength,
893N/A * LPTSTR lpBuffer,
893N/A * LPTSTR *lpFilePart
893N/A * )
893N/A */
893N/A static String GetFullPathName(String path) throws WindowsException {
893N/A NativeBuffer buffer = asNativeBuffer(path);
893N/A try {
893N/A return GetFullPathName0(buffer.address());
893N/A } finally {
893N/A buffer.release();
893N/A }
893N/A }
893N/A private static native String GetFullPathName0(long pathAddress)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * GetFinalPathNameByHandle(
893N/A * HANDLE hFile,
893N/A * LPTSTR lpszFilePath,
893N/A * DWORD cchFilePath,
893N/A * DWORD dwFlags
893N/A * )
893N/A */
893N/A static native String GetFinalPathNameByHandle(long handle)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * FormatMessage(
893N/A * DWORD dwFlags,
893N/A * LPCVOID lpSource,
893N/A * DWORD dwMessageId,
893N/A * DWORD dwLanguageId,
893N/A * LPTSTR lpBuffer,
893N/A * DWORD nSize,
893N/A * va_list *Arguments
893N/A * )
893N/A */
893N/A static native String FormatMessage(int errorCode);
893N/A
893N/A /**
893N/A * LocalFree(
893N/A * HLOCAL hMem
893N/A * )
893N/A */
893N/A static native void LocalFree(long address);
893N/A
893N/A /**
893N/A * HANDLE CreateIoCompletionPort (
893N/A * HANDLE FileHandle,
893N/A * HANDLE ExistingCompletionPort,
893N/A * DWORD CompletionKey,
893N/A * DWORD NumberOfConcurrentThreads
893N/A * )
893N/A */
893N/A static native long CreateIoCompletionPort(long fileHandle, long existingPort,
893N/A int completionKey) throws WindowsException;
893N/A
893N/A
893N/A /**
893N/A * GetQueuedCompletionStatus(
893N/A * HANDLE CompletionPort,
893N/A * LPDWORD lpNumberOfBytesTransferred,
893N/A * LPDWORD lpCompletionKey,
893N/A * LPOVERLAPPED *lpOverlapped,
893N/A * DWORD dwMilliseconds
893N/A */
893N/A static CompletionStatus GetQueuedCompletionStatus(long completionPort)
893N/A throws WindowsException
893N/A {
893N/A CompletionStatus status = new CompletionStatus();
893N/A GetQueuedCompletionStatus0(completionPort, status);
893N/A return status;
893N/A }
893N/A static class CompletionStatus {
893N/A private int error;
893N/A private int bytesTransferred;
893N/A private int completionKey;
893N/A private CompletionStatus() { }
893N/A
893N/A int error() { return error; }
893N/A int bytesTransferred() { return bytesTransferred; }
893N/A int completionKey() { return completionKey; }
893N/A }
893N/A private static native void GetQueuedCompletionStatus0(long completionPort,
893N/A CompletionStatus status) throws WindowsException;
893N/A
893N/A /**
893N/A * PostQueuedCompletionStatus(
893N/A * HANDLE CompletionPort,
893N/A * DWORD dwNumberOfBytesTransferred,
893N/A * DWORD dwCompletionKey,
893N/A * LPOVERLAPPED lpOverlapped
893N/A * )
893N/A */
893N/A static native void PostQueuedCompletionStatus(long completionPort,
893N/A int completionKey) throws WindowsException;
893N/A
893N/A /**
893N/A * ReadDirectoryChangesW(
893N/A * HANDLE hDirectory,
893N/A * LPVOID lpBuffer,
893N/A * DWORD nBufferLength,
893N/A * BOOL bWatchSubtree,
893N/A * DWORD dwNotifyFilter,
893N/A * LPDWORD lpBytesReturned,
893N/A * LPOVERLAPPED lpOverlapped,
893N/A * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
893N/A * )
893N/A */
893N/A static native void ReadDirectoryChangesW(long hDirectory,
893N/A long bufferAddress,
893N/A int bufferLength,
893N/A boolean watchSubTree,
893N/A int filter,
893N/A long bytesReturnedAddress,
893N/A long pOverlapped)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * BackupRead(
893N/A * HANDLE hFile,
893N/A * LPBYTE lpBuffer,
893N/A * DWORD nNumberOfBytesToRead,
893N/A * LPDWORD lpNumberOfBytesRead,
893N/A * BOOL bAbort,
893N/A * BOOL bProcessSecurity,
893N/A * LPVOID* lpContext
893N/A * )
893N/A */
893N/A static BackupResult BackupRead(long hFile,
893N/A long bufferAddress,
893N/A int bufferSize,
893N/A boolean abort,
893N/A long context)
893N/A throws WindowsException
893N/A {
893N/A BackupResult result = new BackupResult();
893N/A BackupRead0(hFile, bufferAddress, bufferSize, abort, context, result);
893N/A return result;
893N/A }
893N/A static class BackupResult {
893N/A private int bytesTransferred;
893N/A private long context;
893N/A private BackupResult() { }
893N/A
893N/A int bytesTransferred() { return bytesTransferred; }
893N/A long context() { return context; }
893N/A }
893N/A private static native void BackupRead0(long hFile, long bufferAddress,
893N/A int bufferSize, boolean abort, long context, BackupResult result)
893N/A throws WindowsException;
893N/A
893N/A /**
893N/A * BackupSeek(
893N/A * HANDLE hFile,
893N/A * DWORD dwLowBytesToSeek,
893N/A * DWORD dwHighBytesToSeek,
893N/A * LPDWORD lpdwLowByteSeeked,
893N/A * LPDWORD lpdwHighByteSeeked,
893N/A * LPVOID* lpContext
893N/A * )
893N/A */
893N/A static native void BackupSeek(long hFile, long bytesToSeek, long context)
893N/A throws WindowsException;
893N/A
893N/A
893N/A // -- support for copying String with a NativeBuffer --
893N/A
893N/A private static final Unsafe unsafe = Unsafe.getUnsafe();
893N/A
893N/A static NativeBuffer asNativeBuffer(String s) {
893N/A int stringLengthInBytes = s.length() << 1;
893N/A int sizeInBytes = stringLengthInBytes + 2; // char terminator
893N/A
893N/A // get a native buffer of sufficient size
893N/A NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(sizeInBytes);
893N/A if (buffer == null) {
893N/A buffer = NativeBuffers.allocNativeBuffer(sizeInBytes);
893N/A } else {
893N/A // buffer already contains the string contents
893N/A if (buffer.owner() == s)
893N/A return buffer;
893N/A }
893N/A
893N/A // copy into buffer and zero terminate
893N/A char[] chars = s.toCharArray();
893N/A unsafe.copyMemory(chars, Unsafe.ARRAY_CHAR_BASE_OFFSET, null,
893N/A buffer.address(), (long)stringLengthInBytes);
893N/A unsafe.putChar(buffer.address() + stringLengthInBytes, (char)0);
893N/A buffer.setOwner(s);
893N/A return buffer;
893N/A }
893N/A
893N/A // -- native library initialization --
893N/A
893N/A private static native void initIDs();
893N/A
893N/A static {
893N/A AccessController.doPrivileged(new PrivilegedAction<Void>() {
893N/A public Void run() {
893N/A // nio.dll has dependency on net.dll
893N/A System.loadLibrary("net");
893N/A System.loadLibrary("nio");
893N/A return null;
893N/A }});
893N/A initIDs();
893N/A }
893N/A
893N/A}