author | robm |
Thu, 06 Jun 2013 22:22:56 +0100 | |
changeset 18144 | b085ffaf3abb |
parent 17722 | d891aa9e1b74 |
child 18157 | ee3bda8e26c6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17722
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
2 |
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
9027
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
26 |
/* Access APIs for WinXP and above */ |
2 | 27 |
#ifndef _WIN32_WINNT |
9027
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
28 |
#define _WIN32_WINNT 0x0501 |
2 | 29 |
#endif |
30 |
||
31 |
#include <assert.h> |
|
32 |
#include <stdio.h> |
|
33 |
#include <stdlib.h> |
|
34 |
#include <ctype.h> |
|
35 |
#include <direct.h> |
|
36 |
#include <windows.h> |
|
37 |
#include <io.h> |
|
38 |
||
39 |
#include "jni.h" |
|
40 |
#include "io_util.h" |
|
41 |
#include "jlong.h" |
|
42 |
#include "io_util_md.h" |
|
43 |
#include "dirent_md.h" |
|
44 |
#include "java_io_FileSystem.h" |
|
45 |
||
46 |
#define MAX_PATH_LENGTH 1024 |
|
47 |
||
48 |
static struct { |
|
49 |
jfieldID path; |
|
50 |
} ids; |
|
51 |
||
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
52 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
53 |
* GetFinalPathNameByHandle is available on Windows Vista and newer |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
54 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
55 |
typedef BOOL (WINAPI* GetFinalPathNameByHandleProc) (HANDLE, LPWSTR, DWORD, DWORD); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
56 |
static GetFinalPathNameByHandleProc GetFinalPathNameByHandle_func; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
57 |
|
2 | 58 |
JNIEXPORT void JNICALL |
59 |
Java_java_io_WinNTFileSystem_initIDs(JNIEnv *env, jclass cls) |
|
60 |
{ |
|
9027
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
61 |
HMODULE handle; |
2 | 62 |
jclass fileClass = (*env)->FindClass(env, "java/io/File"); |
63 |
if (!fileClass) return; |
|
64 |
ids.path = |
|
65 |
(*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;"); |
|
9027
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
66 |
|
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
67 |
// GetFinalPathNameByHandle requires Windows Vista or newer |
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
68 |
if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | |
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
69 |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT), |
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
70 |
(LPCWSTR)&CreateFileW, &handle) != 0) |
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
71 |
{ |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
72 |
GetFinalPathNameByHandle_func = (GetFinalPathNameByHandleProc) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
73 |
GetProcAddress(handle, "GetFinalPathNameByHandleW"); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
74 |
} |
2 | 75 |
} |
76 |
||
77 |
/* -- Path operations -- */ |
|
78 |
||
79 |
extern int wcanonicalize(const WCHAR *path, WCHAR *out, int len); |
|
80 |
extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pathWithCanonicalPrefix, WCHAR *out, int len); |
|
81 |
||
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
82 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
83 |
* Retrieves the fully resolved (final) path for the given path or NULL |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
84 |
* if the function fails. |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
85 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
86 |
static WCHAR* getFinalPath(const WCHAR *path) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
87 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
88 |
HANDLE h; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
89 |
WCHAR *result; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
90 |
DWORD error; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
91 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
92 |
/* Need Windows Vista or newer to get the final path */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
93 |
if (GetFinalPathNameByHandle_func == NULL) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
94 |
return NULL; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
95 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
96 |
h = CreateFileW(path, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
97 |
FILE_READ_ATTRIBUTES, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
98 |
FILE_SHARE_DELETE | |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
99 |
FILE_SHARE_READ | FILE_SHARE_WRITE, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
100 |
NULL, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
101 |
OPEN_EXISTING, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
102 |
FILE_FLAG_BACKUP_SEMANTICS, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
103 |
NULL); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
104 |
if (h == INVALID_HANDLE_VALUE) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
105 |
return NULL; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
106 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
107 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
108 |
* Allocate a buffer for the resolved path. For a long path we may need |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
109 |
* to allocate a larger buffer. |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
110 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
111 |
result = (WCHAR*)malloc(MAX_PATH * sizeof(WCHAR)); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
112 |
if (result != NULL) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
113 |
DWORD len = (*GetFinalPathNameByHandle_func)(h, result, MAX_PATH, 0); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
114 |
if (len >= MAX_PATH) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
115 |
/* retry with a buffer of the right size */ |
16008
2734ca906c3e
8007609: WinNTFileSystem_md.c should correctly check value returned from realloc
jzavgren
parents:
14342
diff
changeset
|
116 |
WCHAR* newResult = (WCHAR*)realloc(result, (len+1) * sizeof(WCHAR)); |
2734ca906c3e
8007609: WinNTFileSystem_md.c should correctly check value returned from realloc
jzavgren
parents:
14342
diff
changeset
|
117 |
if (newResult != NULL) { |
2734ca906c3e
8007609: WinNTFileSystem_md.c should correctly check value returned from realloc
jzavgren
parents:
14342
diff
changeset
|
118 |
result = newResult; |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
119 |
len = (*GetFinalPathNameByHandle_func)(h, result, len, 0); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
120 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
121 |
len = 0; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
122 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
123 |
} |
16008
2734ca906c3e
8007609: WinNTFileSystem_md.c should correctly check value returned from realloc
jzavgren
parents:
14342
diff
changeset
|
124 |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
125 |
if (len > 0) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
126 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
127 |
* Strip prefix (should be \\?\ or \\?\UNC) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
128 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
129 |
if (result[0] == L'\\' && result[1] == L'\\' && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
130 |
result[2] == L'?' && result[3] == L'\\') |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
131 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
132 |
int isUnc = (result[4] == L'U' && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
133 |
result[5] == L'N' && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
134 |
result[6] == L'C'); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
135 |
int prefixLen = (isUnc) ? 7 : 4; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
136 |
/* actual result length (includes terminator) */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
137 |
int resultLen = len - prefixLen + (isUnc ? 1 : 0) + 1; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
138 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
139 |
/* copy result without prefix into new buffer */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
140 |
WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR)); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
141 |
if (tmp == NULL) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
142 |
len = 0; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
143 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
144 |
WCHAR *p = result; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
145 |
p += prefixLen; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
146 |
if (isUnc) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
147 |
WCHAR *p2 = tmp; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
148 |
p2[0] = L'\\'; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
149 |
p2++; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
150 |
wcscpy(p2, p); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
151 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
152 |
wcscpy(tmp, p); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
153 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
154 |
free(result); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
155 |
result = tmp; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
156 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
157 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
158 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
159 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
160 |
/* unable to get final path */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
161 |
if (len == 0 && result != NULL) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
162 |
free(result); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
163 |
result = NULL; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
164 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
165 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
166 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
167 |
error = GetLastError(); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
168 |
if (CloseHandle(h)) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
169 |
SetLastError(error); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
170 |
return result; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
171 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
172 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
173 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
174 |
* Retrieves file information for the specified file. If the file is |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
175 |
* symbolic link then the information on fully resolved target is |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
176 |
* returned. |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
177 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
178 |
static BOOL getFileInformation(const WCHAR *path, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
179 |
BY_HANDLE_FILE_INFORMATION *finfo) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
180 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
181 |
BOOL result; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
182 |
DWORD error; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
183 |
HANDLE h = CreateFileW(path, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
184 |
FILE_READ_ATTRIBUTES, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
185 |
FILE_SHARE_DELETE | |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
186 |
FILE_SHARE_READ | FILE_SHARE_WRITE, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
187 |
NULL, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
188 |
OPEN_EXISTING, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
189 |
FILE_FLAG_BACKUP_SEMANTICS, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
190 |
NULL); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
191 |
if (h == INVALID_HANDLE_VALUE) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
192 |
return FALSE; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
193 |
result = GetFileInformationByHandle(h, finfo); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
194 |
error = GetLastError(); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
195 |
if (CloseHandle(h)) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
196 |
SetLastError(error); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
197 |
return result; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
198 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
199 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
200 |
/** |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
201 |
* If the given attributes are the attributes of a reparse point, then |
17722
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
202 |
* read and return the attributes of the special cases. |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
203 |
*/ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
204 |
DWORD getFinalAttributesIfReparsePoint(WCHAR *path, DWORD a) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
205 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
206 |
if ((a != INVALID_FILE_ATTRIBUTES) && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
207 |
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
208 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
209 |
BY_HANDLE_FILE_INFORMATION finfo; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
210 |
BOOL res = getFileInformation(path, &finfo); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
211 |
a = (res) ? finfo.dwFileAttributes : INVALID_FILE_ATTRIBUTES; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
212 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
213 |
return a; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
214 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
215 |
|
17722
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
216 |
/** |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
217 |
* Take special cases into account when retrieving the attributes |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
218 |
* of path |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
219 |
*/ |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
220 |
DWORD getFinalAttributes(WCHAR *path) |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
221 |
{ |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
222 |
DWORD attr = INVALID_FILE_ATTRIBUTES; |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
223 |
|
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
224 |
WIN32_FILE_ATTRIBUTE_DATA wfad; |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
225 |
WIN32_FIND_DATAW wfd; |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
226 |
HANDLE h; |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
227 |
|
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
228 |
if (GetFileAttributesExW(path, GetFileExInfoStandard, &wfad)) { |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
229 |
attr = getFinalAttributesIfReparsePoint(path, wfad.dwFileAttributes); |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
230 |
} else if (GetLastError() == ERROR_SHARING_VIOLATION && |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
231 |
(h = FindFirstFileW(path, &wfd)) != INVALID_HANDLE_VALUE) { |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
232 |
attr = getFinalAttributesIfReparsePoint(path, wfd.dwFileAttributes); |
18144 | 233 |
FindClose(h); |
17722
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
234 |
} |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
235 |
return attr; |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
236 |
} |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
237 |
|
2 | 238 |
JNIEXPORT jstring JNICALL |
239 |
Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, |
|
240 |
jstring pathname) |
|
241 |
{ |
|
242 |
jstring rv = NULL; |
|
243 |
WCHAR canonicalPath[MAX_PATH_LENGTH]; |
|
244 |
||
245 |
WITH_UNICODE_STRING(env, pathname, path) { |
|
246 |
/*we estimate the max length of memory needed as |
|
247 |
"currentDir. length + pathname.length" |
|
248 |
*/ |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
249 |
int len = (int)wcslen(path); |
2 | 250 |
len += currentDirLength(path, len); |
251 |
if (len > MAX_PATH_LENGTH - 1) { |
|
252 |
WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR)); |
|
253 |
if (cp != NULL) { |
|
254 |
if (wcanonicalize(path, cp, len) >= 0) { |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
255 |
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); |
2 | 256 |
} |
257 |
free(cp); |
|
258 |
} |
|
259 |
} else |
|
260 |
if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) { |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
261 |
rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath)); |
2 | 262 |
} |
263 |
} END_UNICODE_STRING(env, path); |
|
264 |
if (rv == NULL) { |
|
265 |
JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); |
|
266 |
} |
|
267 |
return rv; |
|
268 |
} |
|
269 |
||
270 |
||
271 |
JNIEXPORT jstring JNICALL |
|
272 |
Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this, |
|
273 |
jstring canonicalPrefixString, |
|
274 |
jstring pathWithCanonicalPrefixString) |
|
275 |
{ |
|
276 |
jstring rv = NULL; |
|
277 |
WCHAR canonicalPath[MAX_PATH_LENGTH]; |
|
278 |
WITH_UNICODE_STRING(env, canonicalPrefixString, canonicalPrefix) { |
|
279 |
WITH_UNICODE_STRING(env, pathWithCanonicalPrefixString, pathWithCanonicalPrefix) { |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
280 |
int len = (int)wcslen(canonicalPrefix) + MAX_PATH; |
2 | 281 |
if (len > MAX_PATH_LENGTH) { |
282 |
WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR)); |
|
283 |
if (cp != NULL) { |
|
284 |
if (wcanonicalizeWithPrefix(canonicalPrefix, |
|
285 |
pathWithCanonicalPrefix, |
|
286 |
cp, len) >= 0) { |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
287 |
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); |
2 | 288 |
} |
289 |
free(cp); |
|
290 |
} |
|
291 |
} else |
|
292 |
if (wcanonicalizeWithPrefix(canonicalPrefix, |
|
293 |
pathWithCanonicalPrefix, |
|
294 |
canonicalPath, MAX_PATH_LENGTH) >= 0) { |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
295 |
rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath)); |
2 | 296 |
} |
297 |
} END_UNICODE_STRING(env, pathWithCanonicalPrefix); |
|
298 |
} END_UNICODE_STRING(env, canonicalPrefix); |
|
299 |
if (rv == NULL) { |
|
300 |
JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); |
|
301 |
} |
|
302 |
return rv; |
|
303 |
} |
|
304 |
||
305 |
/* -- Attribute accessors -- */ |
|
306 |
||
307 |
/* Check whether or not the file name in "path" is a Windows reserved |
|
308 |
device name (CON, PRN, AUX, NUL, COM[1-9], LPT[1-9]) based on the |
|
309 |
returned result from GetFullPathName, which should be in thr form of |
|
310 |
"\\.\[ReservedDeviceName]" if the path represents a reserved device |
|
311 |
name. |
|
312 |
Note1: GetFullPathName doesn't think "CLOCK$" (which is no longer |
|
313 |
important anyway) is a device name, so we don't check it here. |
|
314 |
GetFileAttributesEx will catch it later by returning 0 on NT/XP/ |
|
315 |
200X. |
|
316 |
||
317 |
Note2: Theoretically the implementation could just lookup the table |
|
318 |
below linearly if the first 4 characters of the fullpath returned |
|
319 |
from GetFullPathName are "\\.\". The current implementation should |
|
320 |
achieve the same result. If Microsoft add more names into their |
|
321 |
reserved device name repository in the future, which probably will |
|
322 |
never happen, we will need to revisit the lookup implementation. |
|
323 |
||
324 |
static WCHAR* ReservedDEviceNames[] = { |
|
325 |
L"CON", L"PRN", L"AUX", L"NUL", |
|
326 |
L"COM1", L"COM2", L"COM3", L"COM4", L"COM5", L"COM6", L"COM7", L"COM8", L"COM9", |
|
327 |
L"LPT1", L"LPT2", L"LPT3", L"LPT4", L"LPT5", L"LPT6", L"LPT7", L"LPT8", L"LPT9", |
|
328 |
L"CLOCK$" |
|
329 |
}; |
|
330 |
*/ |
|
331 |
||
332 |
static BOOL isReservedDeviceNameW(WCHAR* path) { |
|
333 |
#define BUFSIZE 9 |
|
334 |
WCHAR buf[BUFSIZE]; |
|
335 |
WCHAR *lpf = NULL; |
|
336 |
DWORD retLen = GetFullPathNameW(path, |
|
337 |
BUFSIZE, |
|
338 |
buf, |
|
339 |
&lpf); |
|
340 |
if ((retLen == BUFSIZE - 1 || retLen == BUFSIZE - 2) && |
|
341 |
buf[0] == L'\\' && buf[1] == L'\\' && |
|
342 |
buf[2] == L'.' && buf[3] == L'\\') { |
|
343 |
WCHAR* dname = _wcsupr(buf + 4); |
|
344 |
if (wcscmp(dname, L"CON") == 0 || |
|
345 |
wcscmp(dname, L"PRN") == 0 || |
|
346 |
wcscmp(dname, L"AUX") == 0 || |
|
347 |
wcscmp(dname, L"NUL") == 0) |
|
348 |
return TRUE; |
|
349 |
if ((wcsncmp(dname, L"COM", 3) == 0 || |
|
350 |
wcsncmp(dname, L"LPT", 3) == 0) && |
|
351 |
dname[3] - L'0' > 0 && |
|
352 |
dname[3] - L'0' <= 9) |
|
353 |
return TRUE; |
|
354 |
} |
|
355 |
return FALSE; |
|
356 |
} |
|
357 |
||
358 |
JNIEXPORT jint JNICALL |
|
359 |
Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this, |
|
360 |
jobject file) |
|
361 |
{ |
|
362 |
jint rv = 0; |
|
363 |
jint pathlen; |
|
364 |
||
365 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
366 |
if (pathbuf == NULL) |
|
367 |
return rv; |
|
368 |
if (!isReservedDeviceNameW(pathbuf)) { |
|
17722
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
369 |
DWORD a = getFinalAttributes(pathbuf); |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
370 |
if (a != INVALID_FILE_ATTRIBUTES) { |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
371 |
rv = (java_io_FileSystem_BA_EXISTS |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
372 |
| ((a & FILE_ATTRIBUTE_DIRECTORY) |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
373 |
? java_io_FileSystem_BA_DIRECTORY |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
374 |
: java_io_FileSystem_BA_REGULAR) |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
375 |
| ((a & FILE_ATTRIBUTE_HIDDEN) |
d891aa9e1b74
7038105: File.isHidden() should return true for pagefile.sys and hiberfil.sys
robm
parents:
16008
diff
changeset
|
376 |
? java_io_FileSystem_BA_HIDDEN : 0)); |
2 | 377 |
} |
378 |
} |
|
379 |
free(pathbuf); |
|
380 |
return rv; |
|
381 |
} |
|
382 |
||
383 |
||
384 |
JNIEXPORT jboolean |
|
385 |
JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this, |
|
386 |
jobject file, jint access) |
|
387 |
{ |
|
691
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
388 |
DWORD attr; |
2 | 389 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
390 |
if (pathbuf == NULL) |
|
391 |
return JNI_FALSE; |
|
691
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
392 |
attr = GetFileAttributesW(pathbuf); |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
393 |
attr = getFinalAttributesIfReparsePoint(pathbuf, attr); |
691
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
394 |
free(pathbuf); |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
395 |
if (attr == INVALID_FILE_ATTRIBUTES) |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
396 |
return JNI_FALSE; |
2 | 397 |
switch (access) { |
398 |
case java_io_FileSystem_ACCESS_READ: |
|
399 |
case java_io_FileSystem_ACCESS_EXECUTE: |
|
691
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
400 |
return JNI_TRUE; |
2 | 401 |
case java_io_FileSystem_ACCESS_WRITE: |
691
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
402 |
/* Read-only attribute ignored on directories */ |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
403 |
if ((attr & FILE_ATTRIBUTE_DIRECTORY) || |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
404 |
(attr & FILE_ATTRIBUTE_READONLY) == 0) |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
405 |
return JNI_TRUE; |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
406 |
else |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
407 |
return JNI_FALSE; |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
408 |
default: |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
409 |
assert(0); |
2033c9b86813
4939819: File.canWrite() returns false for the "My Documents" directory (win)
alanb
parents:
2
diff
changeset
|
410 |
return JNI_FALSE; |
2 | 411 |
} |
412 |
} |
|
413 |
||
414 |
JNIEXPORT jboolean JNICALL |
|
415 |
Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this, |
|
416 |
jobject file, |
|
417 |
jint access, |
|
418 |
jboolean enable, |
|
419 |
jboolean owneronly) |
|
420 |
{ |
|
421 |
jboolean rv = JNI_FALSE; |
|
422 |
WCHAR *pathbuf; |
|
423 |
DWORD a; |
|
424 |
if (access == java_io_FileSystem_ACCESS_READ || |
|
425 |
access == java_io_FileSystem_ACCESS_EXECUTE) { |
|
426 |
return enable; |
|
427 |
} |
|
428 |
pathbuf = fileToNTPath(env, file, ids.path); |
|
429 |
if (pathbuf == NULL) |
|
430 |
return JNI_FALSE; |
|
431 |
a = GetFileAttributesW(pathbuf); |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
432 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
433 |
/* if reparse point, get final target */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
434 |
if ((a != INVALID_FILE_ATTRIBUTES) && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
435 |
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
436 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
437 |
WCHAR *fp = getFinalPath(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
438 |
if (fp == NULL) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
439 |
a = INVALID_FILE_ATTRIBUTES; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
440 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
441 |
free(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
442 |
pathbuf = fp; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
443 |
a = GetFileAttributesW(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
444 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
445 |
} |
6884
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
446 |
if ((a != INVALID_FILE_ATTRIBUTES) && |
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
447 |
((a & FILE_ATTRIBUTE_DIRECTORY) == 0)) |
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
448 |
{ |
2 | 449 |
if (enable) |
450 |
a = a & ~FILE_ATTRIBUTE_READONLY; |
|
451 |
else |
|
452 |
a = a | FILE_ATTRIBUTE_READONLY; |
|
453 |
if (SetFileAttributesW(pathbuf, a)) |
|
454 |
rv = JNI_TRUE; |
|
455 |
} |
|
456 |
free(pathbuf); |
|
457 |
return rv; |
|
458 |
} |
|
459 |
||
460 |
JNIEXPORT jlong JNICALL |
|
461 |
Java_java_io_WinNTFileSystem_getLastModifiedTime(JNIEnv *env, jobject this, |
|
462 |
jobject file) |
|
463 |
{ |
|
464 |
jlong rv = 0; |
|
465 |
LARGE_INTEGER modTime; |
|
466 |
FILETIME t; |
|
467 |
HANDLE h; |
|
468 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
469 |
if (pathbuf == NULL) |
|
470 |
return rv; |
|
471 |
h = CreateFileW(pathbuf, |
|
472 |
/* Device query access */ |
|
473 |
0, |
|
474 |
/* Share it */ |
|
475 |
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, |
|
476 |
/* No security attributes */ |
|
477 |
NULL, |
|
478 |
/* Open existing or fail */ |
|
479 |
OPEN_EXISTING, |
|
480 |
/* Backup semantics for directories */ |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
481 |
FILE_FLAG_BACKUP_SEMANTICS, |
2 | 482 |
/* No template file */ |
483 |
NULL); |
|
484 |
if (h != INVALID_HANDLE_VALUE) { |
|
2426
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
485 |
if (GetFileTime(h, NULL, NULL, &t)) { |
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
486 |
modTime.LowPart = (DWORD) t.dwLowDateTime; |
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
487 |
modTime.HighPart = (LONG) t.dwHighDateTime; |
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
488 |
rv = modTime.QuadPart / 10000; |
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
489 |
rv -= 11644473600000; |
a528c0830862
6819689: File.lastModified can return bogus value for remote file accessed as it is being deleted [win]
alanb
parents:
715
diff
changeset
|
490 |
} |
2 | 491 |
CloseHandle(h); |
492 |
} |
|
493 |
free(pathbuf); |
|
494 |
return rv; |
|
495 |
} |
|
496 |
||
497 |
JNIEXPORT jlong JNICALL |
|
498 |
Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file) |
|
499 |
{ |
|
500 |
jlong rv = 0; |
|
501 |
WIN32_FILE_ATTRIBUTE_DATA wfad; |
|
502 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
503 |
if (pathbuf == NULL) |
|
504 |
return rv; |
|
505 |
if (GetFileAttributesExW(pathbuf, |
|
506 |
GetFileExInfoStandard, |
|
507 |
&wfad)) { |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
508 |
if ((wfad.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
509 |
rv = wfad.nFileSizeHigh * ((jlong)MAXDWORD + 1) + wfad.nFileSizeLow; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
510 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
511 |
/* file is a reparse point so read attributes of final target */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
512 |
BY_HANDLE_FILE_INFORMATION finfo; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
513 |
if (getFileInformation(pathbuf, &finfo)) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
514 |
rv = finfo.nFileSizeHigh * ((jlong)MAXDWORD + 1) + |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
515 |
finfo.nFileSizeLow; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
516 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
517 |
} |
2 | 518 |
} else { |
519 |
if (GetLastError() == ERROR_SHARING_VIOLATION) { |
|
520 |
/* The error is "share violation", which means the file/dir |
|
521 |
must exists. Try _wstati64, we know this at least works |
|
522 |
for pagefile.sys and hiberfil.sys. |
|
523 |
*/ |
|
524 |
struct _stati64 sb; |
|
525 |
if (_wstati64(pathbuf, &sb) == 0) { |
|
526 |
rv = sb.st_size; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
free(pathbuf); |
|
531 |
return rv; |
|
532 |
} |
|
533 |
||
534 |
/* -- File operations -- */ |
|
535 |
||
536 |
JNIEXPORT jboolean JNICALL |
|
537 |
Java_java_io_WinNTFileSystem_createFileExclusively(JNIEnv *env, jclass cls, |
|
538 |
jstring path) |
|
539 |
{ |
|
540 |
HANDLE h = NULL; |
|
541 |
WCHAR *pathbuf = pathToNTPath(env, path, JNI_FALSE); |
|
542 |
if (pathbuf == NULL) |
|
543 |
return JNI_FALSE; |
|
544 |
h = CreateFileW( |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
545 |
pathbuf, /* Wide char path name */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
546 |
GENERIC_READ | GENERIC_WRITE, /* Read and write permission */ |
2 | 547 |
FILE_SHARE_READ | FILE_SHARE_WRITE, /* File sharing flags */ |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
548 |
NULL, /* Security attributes */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
549 |
CREATE_NEW, /* creation disposition */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
550 |
FILE_ATTRIBUTE_NORMAL | |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
551 |
FILE_FLAG_OPEN_REPARSE_POINT, /* flags and attributes */ |
2 | 552 |
NULL); |
553 |
||
554 |
if (h == INVALID_HANDLE_VALUE) { |
|
555 |
DWORD error = GetLastError(); |
|
556 |
if ((error != ERROR_FILE_EXISTS) && (error != ERROR_ALREADY_EXISTS)) { |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
557 |
// return false rather than throwing an exception when there is |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
558 |
// an existing file. |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
559 |
DWORD a = GetFileAttributesW(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
560 |
if (a == INVALID_FILE_ATTRIBUTES) { |
2 | 561 |
SetLastError(error); |
562 |
JNU_ThrowIOExceptionWithLastError(env, "Could not open file"); |
|
563 |
} |
|
564 |
} |
|
565 |
free(pathbuf); |
|
566 |
return JNI_FALSE; |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
567 |
} |
2 | 568 |
free(pathbuf); |
569 |
CloseHandle(h); |
|
570 |
return JNI_TRUE; |
|
571 |
} |
|
572 |
||
573 |
static int |
|
574 |
removeFileOrDirectory(const jchar *path) |
|
575 |
{ |
|
576 |
/* Returns 0 on success */ |
|
577 |
DWORD a; |
|
578 |
||
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
579 |
SetFileAttributesW(path, FILE_ATTRIBUTE_NORMAL); |
2 | 580 |
a = GetFileAttributesW(path); |
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
581 |
if (a == INVALID_FILE_ATTRIBUTES) { |
2 | 582 |
return 1; |
583 |
} else if (a & FILE_ATTRIBUTE_DIRECTORY) { |
|
584 |
return !RemoveDirectoryW(path); |
|
585 |
} else { |
|
586 |
return !DeleteFileW(path); |
|
587 |
} |
|
588 |
} |
|
589 |
||
590 |
JNIEXPORT jboolean JNICALL |
|
591 |
Java_java_io_WinNTFileSystem_delete0(JNIEnv *env, jobject this, jobject file) |
|
592 |
{ |
|
593 |
jboolean rv = JNI_FALSE; |
|
594 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
595 |
if (pathbuf == NULL) { |
|
596 |
return JNI_FALSE; |
|
597 |
} |
|
598 |
if (removeFileOrDirectory(pathbuf) == 0) { |
|
599 |
rv = JNI_TRUE; |
|
600 |
} |
|
601 |
free(pathbuf); |
|
602 |
return rv; |
|
603 |
} |
|
604 |
||
605 |
JNIEXPORT jobjectArray JNICALL |
|
606 |
Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) |
|
607 |
{ |
|
608 |
WCHAR *search_path; |
|
609 |
HANDLE handle; |
|
610 |
WIN32_FIND_DATAW find_data; |
|
611 |
int len, maxlen; |
|
612 |
jobjectArray rv, old; |
|
613 |
DWORD fattr; |
|
614 |
jstring name; |
|
615 |
||
616 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
617 |
if (pathbuf == NULL) |
|
618 |
return NULL; |
|
619 |
search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6); |
|
620 |
if (search_path == 0) { |
|
621 |
free (pathbuf); |
|
622 |
errno = ENOMEM; |
|
623 |
return NULL; |
|
624 |
} |
|
625 |
wcscpy(search_path, pathbuf); |
|
626 |
free(pathbuf); |
|
627 |
fattr = GetFileAttributesW(search_path); |
|
628 |
if (fattr == INVALID_FILE_ATTRIBUTES) { |
|
629 |
free(search_path); |
|
630 |
return NULL; |
|
631 |
} else if ((fattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
|
632 |
free(search_path); |
|
633 |
return NULL; |
|
634 |
} |
|
635 |
||
636 |
/* Remove trailing space chars from directory name */ |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
637 |
len = (int)wcslen(search_path); |
2 | 638 |
while (search_path[len-1] == ' ') { |
639 |
len--; |
|
640 |
} |
|
641 |
search_path[len] = 0; |
|
642 |
||
643 |
/* Append "*", or possibly "\\*", to path */ |
|
644 |
if ((search_path[0] == L'\\' && search_path[1] == L'\0') || |
|
645 |
(search_path[1] == L':' |
|
646 |
&& (search_path[2] == L'\0' |
|
647 |
|| (search_path[2] == L'\\' && search_path[3] == L'\0')))) { |
|
648 |
/* No '\\' needed for cases like "\" or "Z:" or "Z:\" */ |
|
649 |
wcscat(search_path, L"*"); |
|
650 |
} else { |
|
651 |
wcscat(search_path, L"\\*"); |
|
652 |
} |
|
653 |
||
654 |
/* Open handle to the first file */ |
|
655 |
handle = FindFirstFileW(search_path, &find_data); |
|
656 |
free(search_path); |
|
657 |
if (handle == INVALID_HANDLE_VALUE) { |
|
658 |
if (GetLastError() != ERROR_FILE_NOT_FOUND) { |
|
659 |
// error |
|
660 |
return NULL; |
|
661 |
} else { |
|
662 |
// No files found - return an empty array |
|
663 |
rv = (*env)->NewObjectArray(env, 0, JNU_ClassString(env), NULL); |
|
664 |
return rv; |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
/* Allocate an initial String array */ |
|
669 |
len = 0; |
|
670 |
maxlen = 16; |
|
671 |
rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL); |
|
672 |
if (rv == NULL) // Couldn't allocate an array |
|
673 |
return NULL; |
|
674 |
/* Scan the directory */ |
|
675 |
do { |
|
676 |
if (!wcscmp(find_data.cFileName, L".") |
|
677 |
|| !wcscmp(find_data.cFileName, L"..")) |
|
678 |
continue; |
|
679 |
name = (*env)->NewString(env, find_data.cFileName, |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
680 |
(jsize)wcslen(find_data.cFileName)); |
2 | 681 |
if (name == NULL) |
682 |
return NULL; // error; |
|
683 |
if (len == maxlen) { |
|
684 |
old = rv; |
|
685 |
rv = (*env)->NewObjectArray(env, maxlen <<= 1, |
|
686 |
JNU_ClassString(env), NULL); |
|
687 |
if ( rv == NULL |
|
688 |
|| JNU_CopyObjectArray(env, rv, old, len) < 0) |
|
689 |
return NULL; // error |
|
690 |
(*env)->DeleteLocalRef(env, old); |
|
691 |
} |
|
692 |
(*env)->SetObjectArrayElement(env, rv, len++, name); |
|
693 |
(*env)->DeleteLocalRef(env, name); |
|
694 |
||
695 |
} while (FindNextFileW(handle, &find_data)); |
|
696 |
||
697 |
if (GetLastError() != ERROR_NO_MORE_FILES) |
|
698 |
return NULL; // error |
|
699 |
FindClose(handle); |
|
700 |
||
701 |
/* Copy the final results into an appropriately-sized array */ |
|
702 |
old = rv; |
|
703 |
rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL); |
|
704 |
if (rv == NULL) |
|
705 |
return NULL; /* error */ |
|
706 |
if (JNU_CopyObjectArray(env, rv, old, len) < 0) |
|
707 |
return NULL; /* error */ |
|
708 |
return rv; |
|
709 |
} |
|
710 |
||
711 |
||
712 |
JNIEXPORT jboolean JNICALL |
|
713 |
Java_java_io_WinNTFileSystem_createDirectory(JNIEnv *env, jobject this, |
|
714 |
jobject file) |
|
715 |
{ |
|
716 |
BOOL h = FALSE; |
|
717 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
718 |
if (pathbuf == NULL) { |
|
719 |
/* Exception is pending */ |
|
720 |
return JNI_FALSE; |
|
721 |
} |
|
722 |
h = CreateDirectoryW(pathbuf, NULL); |
|
723 |
free(pathbuf); |
|
724 |
||
725 |
if (h == 0) { |
|
726 |
return JNI_FALSE; |
|
727 |
} |
|
728 |
||
729 |
return JNI_TRUE; |
|
730 |
} |
|
731 |
||
732 |
||
733 |
JNIEXPORT jboolean JNICALL |
|
734 |
Java_java_io_WinNTFileSystem_rename0(JNIEnv *env, jobject this, jobject from, |
|
735 |
jobject to) |
|
736 |
{ |
|
737 |
||
738 |
jboolean rv = JNI_FALSE; |
|
739 |
WCHAR *frompath = fileToNTPath(env, from, ids.path); |
|
740 |
WCHAR *topath = fileToNTPath(env, to, ids.path); |
|
741 |
if (frompath == NULL || topath == NULL) |
|
742 |
return JNI_FALSE; |
|
743 |
if (_wrename(frompath, topath) == 0) { |
|
744 |
rv = JNI_TRUE; |
|
745 |
} |
|
746 |
free(frompath); |
|
747 |
free(topath); |
|
748 |
return rv; |
|
749 |
} |
|
750 |
||
751 |
||
752 |
JNIEXPORT jboolean JNICALL |
|
753 |
Java_java_io_WinNTFileSystem_setLastModifiedTime(JNIEnv *env, jobject this, |
|
754 |
jobject file, jlong time) |
|
755 |
{ |
|
756 |
jboolean rv = JNI_FALSE; |
|
757 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
758 |
HANDLE h; |
|
759 |
if (pathbuf == NULL) |
|
760 |
return JNI_FALSE; |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
761 |
h = CreateFileW(pathbuf, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
762 |
FILE_WRITE_ATTRIBUTES, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
763 |
FILE_SHARE_READ | FILE_SHARE_WRITE, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
764 |
NULL, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
765 |
OPEN_EXISTING, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
766 |
FILE_FLAG_BACKUP_SEMANTICS, |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
767 |
0); |
2 | 768 |
if (h != INVALID_HANDLE_VALUE) { |
769 |
LARGE_INTEGER modTime; |
|
770 |
FILETIME t; |
|
771 |
modTime.QuadPart = (time + 11644473600000L) * 10000L; |
|
772 |
t.dwLowDateTime = (DWORD)modTime.LowPart; |
|
773 |
t.dwHighDateTime = (DWORD)modTime.HighPart; |
|
774 |
if (SetFileTime(h, NULL, NULL, &t)) { |
|
775 |
rv = JNI_TRUE; |
|
776 |
} |
|
777 |
CloseHandle(h); |
|
778 |
} |
|
779 |
free(pathbuf); |
|
780 |
||
781 |
return rv; |
|
782 |
} |
|
783 |
||
784 |
||
785 |
JNIEXPORT jboolean JNICALL |
|
786 |
Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this, |
|
787 |
jobject file) |
|
788 |
{ |
|
789 |
jboolean rv = JNI_FALSE; |
|
790 |
DWORD a; |
|
791 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
792 |
if (pathbuf == NULL) |
|
793 |
return JNI_FALSE; |
|
794 |
a = GetFileAttributesW(pathbuf); |
|
3627
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
795 |
|
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
796 |
/* if reparse point, get final target */ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
797 |
if ((a != INVALID_FILE_ATTRIBUTES) && |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
798 |
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
799 |
{ |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
800 |
WCHAR *fp = getFinalPath(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
801 |
if (fp == NULL) { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
802 |
a = INVALID_FILE_ATTRIBUTES; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
803 |
} else { |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
804 |
free(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
805 |
pathbuf = fp; |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
806 |
a = GetFileAttributesW(pathbuf); |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
807 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
808 |
} |
d0ad40d5adab
6595866: File does work with symbolic links (win,vista)
alanb
parents:
2426
diff
changeset
|
809 |
|
6884
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
810 |
if ((a != INVALID_FILE_ATTRIBUTES) && |
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
811 |
((a & FILE_ATTRIBUTE_DIRECTORY) == 0)) { |
2 | 812 |
if (SetFileAttributesW(pathbuf, a | FILE_ATTRIBUTE_READONLY)) |
6884
65b1fa0a0fae
6728842: File.setReadOnly does not make a directory read-only (win)
alanb
parents:
5506
diff
changeset
|
813 |
rv = JNI_TRUE; |
2 | 814 |
} |
815 |
free(pathbuf); |
|
816 |
return rv; |
|
817 |
} |
|
818 |
||
819 |
/* -- Filesystem interface -- */ |
|
820 |
||
821 |
||
822 |
JNIEXPORT jobject JNICALL |
|
823 |
Java_java_io_WinNTFileSystem_getDriveDirectory(JNIEnv *env, jobject this, |
|
824 |
jint drive) |
|
825 |
{ |
|
826 |
jstring ret = NULL; |
|
6885
5605d7d60c9c
6983520: java/io/pathNames/GeneralWin32.java fails with jdk7-b108 (win)
alanb
parents:
6884
diff
changeset
|
827 |
jchar *p = currentDir(drive); |
2 | 828 |
jchar *pf = p; |
829 |
if (p == NULL) return NULL; |
|
830 |
if (iswalpha(*p) && (p[1] == L':')) p += 2; |
|
8186
d0e2cc8b3073
7017454: Residual warnings in sun/nio/** and java/io native code (win64)
alanb
parents:
7668
diff
changeset
|
831 |
ret = (*env)->NewString(env, p, (jsize)wcslen(p)); |
2 | 832 |
free (pf); |
833 |
return ret; |
|
834 |
} |
|
835 |
||
14177 | 836 |
JNIEXPORT jint JNICALL |
837 |
Java_java_io_WinNTFileSystem_listRoots0(JNIEnv *env, jclass ignored) |
|
838 |
{ |
|
839 |
return GetLogicalDrives(); |
|
840 |
} |
|
841 |
||
2 | 842 |
JNIEXPORT jlong JNICALL |
843 |
Java_java_io_WinNTFileSystem_getSpace0(JNIEnv *env, jobject this, |
|
844 |
jobject file, jint t) |
|
845 |
{ |
|
846 |
WCHAR volname[MAX_PATH_LENGTH + 1]; |
|
847 |
jlong rv = 0L; |
|
848 |
WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
849 |
||
9027
540bd52f1881
7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents:
8186
diff
changeset
|
850 |
if (GetVolumePathNameW(pathbuf, volname, MAX_PATH_LENGTH)) { |
2 | 851 |
ULARGE_INTEGER totalSpace, freeSpace, usableSpace; |
852 |
if (GetDiskFreeSpaceExW(volname, &usableSpace, &totalSpace, &freeSpace)) { |
|
853 |
switch(t) { |
|
854 |
case java_io_FileSystem_SPACE_TOTAL: |
|
855 |
rv = long_to_jlong(totalSpace.QuadPart); |
|
856 |
break; |
|
857 |
case java_io_FileSystem_SPACE_FREE: |
|
858 |
rv = long_to_jlong(freeSpace.QuadPart); |
|
859 |
break; |
|
860 |
case java_io_FileSystem_SPACE_USABLE: |
|
861 |
rv = long_to_jlong(usableSpace.QuadPart); |
|
862 |
break; |
|
863 |
default: |
|
864 |
assert(0); |
|
865 |
} |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
free(pathbuf); |
|
870 |
return rv; |
|
871 |
} |