1 /* |
1 /* |
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
197 return result; |
197 return result; |
198 } |
198 } |
199 |
199 |
200 /** |
200 /** |
201 * If the given attributes are the attributes of a reparse point, then |
201 * If the given attributes are the attributes of a reparse point, then |
202 * read and return the attributes of the final target. |
202 * read and return the attributes of the special cases. |
203 */ |
203 */ |
204 DWORD getFinalAttributesIfReparsePoint(WCHAR *path, DWORD a) |
204 DWORD getFinalAttributesIfReparsePoint(WCHAR *path, DWORD a) |
205 { |
205 { |
206 if ((a != INVALID_FILE_ATTRIBUTES) && |
206 if ((a != INVALID_FILE_ATTRIBUTES) && |
207 ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) |
207 ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) |
209 BY_HANDLE_FILE_INFORMATION finfo; |
209 BY_HANDLE_FILE_INFORMATION finfo; |
210 BOOL res = getFileInformation(path, &finfo); |
210 BOOL res = getFileInformation(path, &finfo); |
211 a = (res) ? finfo.dwFileAttributes : INVALID_FILE_ATTRIBUTES; |
211 a = (res) ? finfo.dwFileAttributes : INVALID_FILE_ATTRIBUTES; |
212 } |
212 } |
213 return a; |
213 return a; |
|
214 } |
|
215 |
|
216 /** |
|
217 * Take special cases into account when retrieving the attributes |
|
218 * of path |
|
219 */ |
|
220 DWORD getFinalAttributes(WCHAR *path) |
|
221 { |
|
222 DWORD attr = INVALID_FILE_ATTRIBUTES; |
|
223 |
|
224 WIN32_FILE_ATTRIBUTE_DATA wfad; |
|
225 WIN32_FIND_DATAW wfd; |
|
226 HANDLE h; |
|
227 |
|
228 if (GetFileAttributesExW(path, GetFileExInfoStandard, &wfad)) { |
|
229 attr = getFinalAttributesIfReparsePoint(path, wfad.dwFileAttributes); |
|
230 } else if (GetLastError() == ERROR_SHARING_VIOLATION && |
|
231 (h = FindFirstFileW(path, &wfd)) != INVALID_HANDLE_VALUE) { |
|
232 attr = getFinalAttributesIfReparsePoint(path, wfd.dwFileAttributes); |
|
233 CloseHandle(h); |
|
234 } |
|
235 return attr; |
214 } |
236 } |
215 |
237 |
216 JNIEXPORT jstring JNICALL |
238 JNIEXPORT jstring JNICALL |
217 Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, |
239 Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, |
218 jstring pathname) |
240 jstring pathname) |
335 |
357 |
336 JNIEXPORT jint JNICALL |
358 JNIEXPORT jint JNICALL |
337 Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this, |
359 Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this, |
338 jobject file) |
360 jobject file) |
339 { |
361 { |
340 |
|
341 jint rv = 0; |
362 jint rv = 0; |
342 jint pathlen; |
363 jint pathlen; |
343 |
364 |
344 /* both pagefile.sys and hiberfil.sys have length 12 */ |
365 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
345 #define SPECIALFILE_NAMELEN 12 |
|
346 |
|
347 WCHAR *pathbuf = fileToNTPath(env, file, ids.path); |
|
348 WIN32_FILE_ATTRIBUTE_DATA wfad; |
|
349 if (pathbuf == NULL) |
366 if (pathbuf == NULL) |
350 return rv; |
367 return rv; |
351 if (!isReservedDeviceNameW(pathbuf)) { |
368 if (!isReservedDeviceNameW(pathbuf)) { |
352 if (GetFileAttributesExW(pathbuf, GetFileExInfoStandard, &wfad)) { |
369 DWORD a = getFinalAttributes(pathbuf); |
353 DWORD a = getFinalAttributesIfReparsePoint(pathbuf, wfad.dwFileAttributes); |
370 if (a != INVALID_FILE_ATTRIBUTES) { |
354 if (a != INVALID_FILE_ATTRIBUTES) { |
371 rv = (java_io_FileSystem_BA_EXISTS |
355 rv = (java_io_FileSystem_BA_EXISTS |
372 | ((a & FILE_ATTRIBUTE_DIRECTORY) |
356 | ((a & FILE_ATTRIBUTE_DIRECTORY) |
373 ? java_io_FileSystem_BA_DIRECTORY |
357 ? java_io_FileSystem_BA_DIRECTORY |
374 : java_io_FileSystem_BA_REGULAR) |
358 : java_io_FileSystem_BA_REGULAR) |
375 | ((a & FILE_ATTRIBUTE_HIDDEN) |
359 | ((a & FILE_ATTRIBUTE_HIDDEN) |
376 ? java_io_FileSystem_BA_HIDDEN : 0)); |
360 ? java_io_FileSystem_BA_HIDDEN : 0)); |
|
361 } |
|
362 } else { /* pagefile.sys is a special case */ |
|
363 if (GetLastError() == ERROR_SHARING_VIOLATION) { |
|
364 rv = java_io_FileSystem_BA_EXISTS; |
|
365 if ((pathlen = (jint)wcslen(pathbuf)) >= SPECIALFILE_NAMELEN && |
|
366 (_wcsicmp(pathbuf + pathlen - SPECIALFILE_NAMELEN, |
|
367 L"pagefile.sys") == 0) || |
|
368 (_wcsicmp(pathbuf + pathlen - SPECIALFILE_NAMELEN, |
|
369 L"hiberfil.sys") == 0)) |
|
370 rv |= java_io_FileSystem_BA_REGULAR; |
|
371 } |
|
372 } |
377 } |
373 } |
378 } |
374 free(pathbuf); |
379 free(pathbuf); |
375 return rv; |
380 return rv; |
376 } |
381 } |