author | coleenp |
Tue, 31 Oct 2017 11:55:09 -0400 | |
changeset 47765 | b7c7428eaab9 |
parent 47216 | 71c04702a3d5 |
child 51105 | c6600aba799b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45178
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
2 |
* Copyright (c) 1998, 2017, 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 |
||
42777
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
26 |
#include <unistd.h> |
2 | 27 |
#include <assert.h> |
28 |
#include <sys/types.h> |
|
29 |
#include <sys/time.h> |
|
30 |
#include <sys/stat.h> |
|
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
31 |
#ifdef MACOSX |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
32 |
#include <sys/param.h> |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
33 |
#include <sys/mount.h> |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
34 |
#else |
2 | 35 |
#include <sys/statvfs.h> |
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
36 |
#endif |
2 | 37 |
#include <string.h> |
38 |
#include <stdlib.h> |
|
39 |
#include <dlfcn.h> |
|
40 |
#include <limits.h> |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
41 |
#include <errno.h> |
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
42 |
#include <fcntl.h> |
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
43 |
#include <dirent.h> |
2 | 44 |
|
45 |
#include "jni.h" |
|
46 |
#include "jni_util.h" |
|
47 |
#include "jlong.h" |
|
48 |
#include "io_util.h" |
|
13360
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
49 |
#include "io_util_md.h" |
2 | 50 |
#include "java_io_FileSystem.h" |
51 |
#include "java_io_UnixFileSystem.h" |
|
52 |
||
42944 | 53 |
#if defined(_AIX) |
54 |
#if !defined(NAME_MAX) |
|
55 |
#define NAME_MAX MAXNAMLEN |
|
56 |
#endif |
|
57 |
#define DIR DIR64 |
|
58 |
#define opendir opendir64 |
|
59 |
#define closedir closedir64 |
|
60 |
#endif |
|
61 |
||
62 |
#if defined(__solaris__) && !defined(NAME_MAX) |
|
63 |
#define NAME_MAX MAXNAMLEN |
|
64 |
#endif |
|
65 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7668
diff
changeset
|
66 |
#if defined(_ALLBSD_SOURCE) |
42944 | 67 |
#define dirent64 dirent |
68 |
#define readdir64_r readdir_r |
|
69 |
#define stat64 stat |
|
70 |
#ifndef MACOSX |
|
71 |
#define statvfs64 statvfs |
|
72 |
#endif |
|
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
73 |
#endif |
2 | 74 |
|
75 |
/* -- Field IDs -- */ |
|
76 |
||
77 |
static struct { |
|
78 |
jfieldID path; |
|
79 |
} ids; |
|
80 |
||
81 |
||
82 |
JNIEXPORT void JNICALL |
|
83 |
Java_java_io_UnixFileSystem_initIDs(JNIEnv *env, jclass cls) |
|
84 |
{ |
|
85 |
jclass fileClass = (*env)->FindClass(env, "java/io/File"); |
|
86 |
if (!fileClass) return; |
|
87 |
ids.path = (*env)->GetFieldID(env, fileClass, |
|
88 |
"path", "Ljava/lang/String;"); |
|
89 |
} |
|
90 |
||
91 |
/* -- Path operations -- */ |
|
92 |
||
93 |
extern int canonicalize(char *path, const char *out, int len); |
|
94 |
||
95 |
JNIEXPORT jstring JNICALL |
|
96 |
Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this, |
|
97 |
jstring pathname) |
|
98 |
{ |
|
99 |
jstring rv = NULL; |
|
100 |
||
101 |
WITH_PLATFORM_STRING(env, pathname, path) { |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
102 |
char canonicalPath[PATH_MAX]; |
16476
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
103 |
if (canonicalize((char *)path, |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
104 |
canonicalPath, PATH_MAX) < 0) { |
2 | 105 |
JNU_ThrowIOExceptionWithLastError(env, "Bad pathname"); |
106 |
} else { |
|
13360
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
107 |
#ifdef MACOSX |
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
108 |
rv = newStringPlatform(env, canonicalPath); |
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
109 |
#else |
2 | 110 |
rv = JNU_NewStringPlatform(env, canonicalPath); |
13360
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
111 |
#endif |
2 | 112 |
} |
113 |
} END_PLATFORM_STRING(env, path); |
|
114 |
return rv; |
|
115 |
} |
|
116 |
||
117 |
||
118 |
/* -- Attribute accessors -- */ |
|
119 |
||
120 |
||
121 |
static jboolean |
|
122 |
statMode(const char *path, int *mode) |
|
123 |
{ |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
124 |
struct stat64 sb; |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
125 |
if (stat64(path, &sb) == 0) { |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
126 |
*mode = sb.st_mode; |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
127 |
return JNI_TRUE; |
2 | 128 |
} |
129 |
return JNI_FALSE; |
|
130 |
} |
|
131 |
||
132 |
||
133 |
JNIEXPORT jint JNICALL |
|
134 |
Java_java_io_UnixFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this, |
|
135 |
jobject file) |
|
136 |
{ |
|
137 |
jint rv = 0; |
|
138 |
||
139 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
140 |
int mode; |
|
141 |
if (statMode(path, &mode)) { |
|
142 |
int fmt = mode & S_IFMT; |
|
143 |
rv = (jint) (java_io_FileSystem_BA_EXISTS |
|
144 |
| ((fmt == S_IFREG) ? java_io_FileSystem_BA_REGULAR : 0) |
|
145 |
| ((fmt == S_IFDIR) ? java_io_FileSystem_BA_DIRECTORY : 0)); |
|
146 |
} |
|
147 |
} END_PLATFORM_STRING(env, path); |
|
148 |
return rv; |
|
149 |
} |
|
150 |
||
151 |
JNIEXPORT jboolean JNICALL |
|
152 |
Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this, |
|
153 |
jobject file, jint a) |
|
154 |
{ |
|
155 |
jboolean rv = JNI_FALSE; |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
156 |
int mode = 0; |
2 | 157 |
switch (a) { |
158 |
case java_io_FileSystem_ACCESS_READ: |
|
159 |
mode = R_OK; |
|
160 |
break; |
|
161 |
case java_io_FileSystem_ACCESS_WRITE: |
|
162 |
mode = W_OK; |
|
163 |
break; |
|
164 |
case java_io_FileSystem_ACCESS_EXECUTE: |
|
165 |
mode = X_OK; |
|
166 |
break; |
|
167 |
default: assert(0); |
|
168 |
} |
|
169 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
170 |
if (access(path, mode) == 0) { |
|
171 |
rv = JNI_TRUE; |
|
172 |
} |
|
173 |
} END_PLATFORM_STRING(env, path); |
|
174 |
return rv; |
|
175 |
} |
|
176 |
||
177 |
||
178 |
JNIEXPORT jboolean JNICALL |
|
179 |
Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this, |
|
180 |
jobject file, |
|
181 |
jint access, |
|
182 |
jboolean enable, |
|
183 |
jboolean owneronly) |
|
184 |
{ |
|
185 |
jboolean rv = JNI_FALSE; |
|
186 |
||
187 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
188 |
int amode = 0; |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
5506
diff
changeset
|
189 |
int mode; |
2 | 190 |
switch (access) { |
191 |
case java_io_FileSystem_ACCESS_READ: |
|
192 |
if (owneronly) |
|
193 |
amode = S_IRUSR; |
|
194 |
else |
|
195 |
amode = S_IRUSR | S_IRGRP | S_IROTH; |
|
196 |
break; |
|
197 |
case java_io_FileSystem_ACCESS_WRITE: |
|
198 |
if (owneronly) |
|
199 |
amode = S_IWUSR; |
|
200 |
else |
|
201 |
amode = S_IWUSR | S_IWGRP | S_IWOTH; |
|
202 |
break; |
|
203 |
case java_io_FileSystem_ACCESS_EXECUTE: |
|
204 |
if (owneronly) |
|
205 |
amode = S_IXUSR; |
|
206 |
else |
|
207 |
amode = S_IXUSR | S_IXGRP | S_IXOTH; |
|
208 |
break; |
|
209 |
default: |
|
210 |
assert(0); |
|
211 |
} |
|
212 |
if (statMode(path, &mode)) { |
|
213 |
if (enable) |
|
214 |
mode |= amode; |
|
215 |
else |
|
216 |
mode &= ~amode; |
|
217 |
if (chmod(path, mode) >= 0) { |
|
218 |
rv = JNI_TRUE; |
|
219 |
} |
|
220 |
} |
|
221 |
} END_PLATFORM_STRING(env, path); |
|
222 |
return rv; |
|
223 |
} |
|
224 |
||
225 |
JNIEXPORT jlong JNICALL |
|
226 |
Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this, |
|
227 |
jobject file) |
|
228 |
{ |
|
229 |
jlong rv = 0; |
|
230 |
||
231 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
232 |
struct stat64 sb; |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
233 |
if (stat64(path, &sb) == 0) { |
45297 | 234 |
#if defined(_AIX) |
235 |
rv = (jlong)sb.st_mtime * 1000; |
|
236 |
rv += (jlong)sb.st_mtime_n / 1000000; |
|
237 |
#elif defined(MACOSX) |
|
238 |
rv = (jlong)sb.st_mtimespec.tv_sec * 1000; |
|
239 |
rv += (jlong)sb.st_mtimespec.tv_nsec / 1000000; |
|
240 |
#else |
|
45178
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
241 |
rv = (jlong)sb.st_mtim.tv_sec * 1000; |
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
242 |
rv += (jlong)sb.st_mtim.tv_nsec / 1000000; |
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
243 |
#endif |
2 | 244 |
} |
245 |
} END_PLATFORM_STRING(env, path); |
|
246 |
return rv; |
|
247 |
} |
|
248 |
||
249 |
||
250 |
JNIEXPORT jlong JNICALL |
|
251 |
Java_java_io_UnixFileSystem_getLength(JNIEnv *env, jobject this, |
|
252 |
jobject file) |
|
253 |
{ |
|
254 |
jlong rv = 0; |
|
255 |
||
256 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
257 |
struct stat64 sb; |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
258 |
if (stat64(path, &sb) == 0) { |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
259 |
rv = sb.st_size; |
2 | 260 |
} |
261 |
} END_PLATFORM_STRING(env, path); |
|
262 |
return rv; |
|
263 |
} |
|
264 |
||
265 |
||
266 |
/* -- File operations -- */ |
|
267 |
||
268 |
||
269 |
JNIEXPORT jboolean JNICALL |
|
270 |
Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls, |
|
271 |
jstring pathname) |
|
272 |
{ |
|
273 |
jboolean rv = JNI_FALSE; |
|
274 |
||
275 |
WITH_PLATFORM_STRING(env, pathname, path) { |
|
16476
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
276 |
FD fd; |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
277 |
/* The root directory always exists */ |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
278 |
if (strcmp (path, "/")) { |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
279 |
fd = handleOpen(path, O_RDWR | O_CREAT | O_EXCL, 0666); |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
280 |
if (fd < 0) { |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
281 |
if (errno != EEXIST) |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
282 |
JNU_ThrowIOExceptionWithLastError(env, path); |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
283 |
} else { |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
284 |
if (close(fd) == -1) |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
285 |
JNU_ThrowIOExceptionWithLastError(env, path); |
e269be167fae
8001334: Remove use of JVM_* functions from java.io code
dxu
parents:
14342
diff
changeset
|
286 |
rv = JNI_TRUE; |
2 | 287 |
} |
288 |
} |
|
289 |
} END_PLATFORM_STRING(env, path); |
|
290 |
return rv; |
|
291 |
} |
|
292 |
||
293 |
||
294 |
JNIEXPORT jboolean JNICALL |
|
295 |
Java_java_io_UnixFileSystem_delete0(JNIEnv *env, jobject this, |
|
296 |
jobject file) |
|
297 |
{ |
|
298 |
jboolean rv = JNI_FALSE; |
|
299 |
||
300 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
301 |
if (remove(path) == 0) { |
|
302 |
rv = JNI_TRUE; |
|
303 |
} |
|
304 |
} END_PLATFORM_STRING(env, path); |
|
305 |
return rv; |
|
306 |
} |
|
307 |
||
308 |
||
309 |
JNIEXPORT jobjectArray JNICALL |
|
310 |
Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this, |
|
311 |
jobject file) |
|
312 |
{ |
|
313 |
DIR *dir = NULL; |
|
314 |
struct dirent64 *ptr; |
|
315 |
struct dirent64 *result; |
|
316 |
int len, maxlen; |
|
317 |
jobjectArray rv, old; |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
318 |
jclass str_class; |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
319 |
|
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
320 |
str_class = JNU_ClassString(env); |
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
321 |
CHECK_NULL_RETURN(str_class, NULL); |
2 | 322 |
|
323 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
324 |
dir = opendir(path); |
|
325 |
} END_PLATFORM_STRING(env, path); |
|
326 |
if (dir == NULL) return NULL; |
|
327 |
||
328 |
ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1)); |
|
329 |
if (ptr == NULL) { |
|
330 |
JNU_ThrowOutOfMemoryError(env, "heap allocation failed"); |
|
331 |
closedir(dir); |
|
332 |
return NULL; |
|
333 |
} |
|
334 |
||
335 |
/* Allocate an initial String array */ |
|
336 |
len = 0; |
|
337 |
maxlen = 16; |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
338 |
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL); |
2 | 339 |
if (rv == NULL) goto error; |
340 |
||
341 |
/* Scan the directory */ |
|
342 |
while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) { |
|
343 |
jstring name; |
|
344 |
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, "..")) |
|
345 |
continue; |
|
346 |
if (len == maxlen) { |
|
347 |
old = rv; |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
348 |
rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL); |
2 | 349 |
if (rv == NULL) goto error; |
350 |
if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error; |
|
351 |
(*env)->DeleteLocalRef(env, old); |
|
352 |
} |
|
13360
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
353 |
#ifdef MACOSX |
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
354 |
name = newStringPlatform(env, ptr->d_name); |
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
355 |
#else |
2 | 356 |
name = JNU_NewStringPlatform(env, ptr->d_name); |
13360
b62b5e86f92a
7130915: File.equals does not give expected results when path contains Non-English characters on Mac OS X
sherman
parents:
12047
diff
changeset
|
357 |
#endif |
2 | 358 |
if (name == NULL) goto error; |
359 |
(*env)->SetObjectArrayElement(env, rv, len++, name); |
|
360 |
(*env)->DeleteLocalRef(env, name); |
|
361 |
} |
|
362 |
closedir(dir); |
|
363 |
free(ptr); |
|
364 |
||
365 |
/* Copy the final results into an appropriately-sized array */ |
|
366 |
old = rv; |
|
22631
ac85b05a53f4
8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents:
16476
diff
changeset
|
367 |
rv = (*env)->NewObjectArray(env, len, str_class, NULL); |
2 | 368 |
if (rv == NULL) { |
369 |
return NULL; |
|
370 |
} |
|
371 |
if (JNU_CopyObjectArray(env, rv, old, len) < 0) { |
|
372 |
return NULL; |
|
373 |
} |
|
374 |
return rv; |
|
375 |
||
376 |
error: |
|
377 |
closedir(dir); |
|
378 |
free(ptr); |
|
379 |
return NULL; |
|
380 |
} |
|
381 |
||
382 |
||
383 |
JNIEXPORT jboolean JNICALL |
|
384 |
Java_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this, |
|
385 |
jobject file) |
|
386 |
{ |
|
387 |
jboolean rv = JNI_FALSE; |
|
388 |
||
389 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
390 |
if (mkdir(path, 0777) == 0) { |
|
391 |
rv = JNI_TRUE; |
|
392 |
} |
|
393 |
} END_PLATFORM_STRING(env, path); |
|
394 |
return rv; |
|
395 |
} |
|
396 |
||
397 |
||
398 |
JNIEXPORT jboolean JNICALL |
|
399 |
Java_java_io_UnixFileSystem_rename0(JNIEnv *env, jobject this, |
|
400 |
jobject from, jobject to) |
|
401 |
{ |
|
402 |
jboolean rv = JNI_FALSE; |
|
403 |
||
404 |
WITH_FIELD_PLATFORM_STRING(env, from, ids.path, fromPath) { |
|
405 |
WITH_FIELD_PLATFORM_STRING(env, to, ids.path, toPath) { |
|
406 |
if (rename(fromPath, toPath) == 0) { |
|
407 |
rv = JNI_TRUE; |
|
408 |
} |
|
409 |
} END_PLATFORM_STRING(env, toPath); |
|
410 |
} END_PLATFORM_STRING(env, fromPath); |
|
411 |
return rv; |
|
412 |
} |
|
413 |
||
414 |
JNIEXPORT jboolean JNICALL |
|
415 |
Java_java_io_UnixFileSystem_setLastModifiedTime(JNIEnv *env, jobject this, |
|
416 |
jobject file, jlong time) |
|
417 |
{ |
|
418 |
jboolean rv = JNI_FALSE; |
|
419 |
||
420 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
421 |
struct stat64 sb; |
2 | 422 |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
423 |
if (stat64(path, &sb) == 0) { |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
424 |
struct timeval tv[2]; |
2 | 425 |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
426 |
/* Preserve access time */ |
45297 | 427 |
#if defined(_AIX) |
428 |
tv[0].tv_sec = sb.st_atime; |
|
429 |
tv[0].tv_usec = sb.st_atime_n / 1000; |
|
430 |
#elif defined(MACOSX) |
|
431 |
tv[0].tv_sec = sb.st_atimespec.tv_sec; |
|
432 |
tv[0].tv_usec = sb.st_atimespec.tv_nsec / 1000; |
|
433 |
#else |
|
45178
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
434 |
tv[0].tv_sec = sb.st_atim.tv_sec; |
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
435 |
tv[0].tv_usec = sb.st_atim.tv_nsec / 1000; |
9ff621041842
8177809: File.lastModified() is losing milliseconds (always ends in 000)
bpb
parents:
42944
diff
changeset
|
436 |
#endif |
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
437 |
/* Change last-modified time */ |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
438 |
tv[1].tv_sec = time / 1000; |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
439 |
tv[1].tv_usec = (time % 1000) * 1000; |
2 | 440 |
|
692
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
441 |
if (utimes(path, tv) == 0) |
50a393caed65
6652379: File.setLastModified fails on large files (lnx only)
alanb
parents:
2
diff
changeset
|
442 |
rv = JNI_TRUE; |
2 | 443 |
} |
444 |
} END_PLATFORM_STRING(env, path); |
|
445 |
||
446 |
return rv; |
|
447 |
} |
|
448 |
||
449 |
||
450 |
JNIEXPORT jboolean JNICALL |
|
451 |
Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this, |
|
452 |
jobject file) |
|
453 |
{ |
|
454 |
jboolean rv = JNI_FALSE; |
|
455 |
||
456 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
457 |
int mode; |
|
458 |
if (statMode(path, &mode)) { |
|
459 |
if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) { |
|
460 |
rv = JNI_TRUE; |
|
461 |
} |
|
462 |
} |
|
463 |
} END_PLATFORM_STRING(env, path); |
|
464 |
return rv; |
|
465 |
} |
|
466 |
||
467 |
JNIEXPORT jlong JNICALL |
|
468 |
Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this, |
|
469 |
jobject file, jint t) |
|
470 |
{ |
|
471 |
jlong rv = 0L; |
|
472 |
||
473 |
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { |
|
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
474 |
#ifdef MACOSX |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
475 |
struct statfs fsstat; |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
476 |
#else |
4981
3a3f498acc86
6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents:
715
diff
changeset
|
477 |
struct statvfs64 fsstat; |
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
478 |
#endif |
4981
3a3f498acc86
6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents:
715
diff
changeset
|
479 |
memset(&fsstat, 0, sizeof(fsstat)); |
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
480 |
#ifdef MACOSX |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
481 |
if (statfs(path, &fsstat) == 0) { |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
482 |
switch(t) { |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
483 |
case java_io_FileSystem_SPACE_TOTAL: |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
484 |
rv = jlong_mul(long_to_jlong(fsstat.f_bsize), |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
485 |
long_to_jlong(fsstat.f_blocks)); |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
486 |
break; |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
487 |
case java_io_FileSystem_SPACE_FREE: |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
488 |
rv = jlong_mul(long_to_jlong(fsstat.f_bsize), |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
489 |
long_to_jlong(fsstat.f_bfree)); |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
490 |
break; |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
491 |
case java_io_FileSystem_SPACE_USABLE: |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
492 |
rv = jlong_mul(long_to_jlong(fsstat.f_bsize), |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
493 |
long_to_jlong(fsstat.f_bavail)); |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
494 |
break; |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
495 |
default: |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
496 |
assert(0); |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
497 |
} |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
498 |
} |
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
499 |
#else |
4981
3a3f498acc86
6815768: File.getxxxSpace() methods fail for very large file systems under 32bit Java
alanb
parents:
715
diff
changeset
|
500 |
if (statvfs64(path, &fsstat) == 0) { |
2 | 501 |
switch(t) { |
502 |
case java_io_FileSystem_SPACE_TOTAL: |
|
503 |
rv = jlong_mul(long_to_jlong(fsstat.f_frsize), |
|
504 |
long_to_jlong(fsstat.f_blocks)); |
|
505 |
break; |
|
506 |
case java_io_FileSystem_SPACE_FREE: |
|
507 |
rv = jlong_mul(long_to_jlong(fsstat.f_frsize), |
|
508 |
long_to_jlong(fsstat.f_bfree)); |
|
509 |
break; |
|
510 |
case java_io_FileSystem_SPACE_USABLE: |
|
511 |
rv = jlong_mul(long_to_jlong(fsstat.f_frsize), |
|
512 |
long_to_jlong(fsstat.f_bavail)); |
|
513 |
break; |
|
514 |
default: |
|
515 |
assert(0); |
|
516 |
} |
|
517 |
} |
|
31144
8154c9d7bc32
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
bpb
parents:
25859
diff
changeset
|
518 |
#endif |
2 | 519 |
} END_PLATFORM_STRING(env, path); |
520 |
return rv; |
|
521 |
} |
|
42777
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
522 |
|
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
523 |
JNIEXPORT jlong JNICALL |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
524 |
Java_java_io_UnixFileSystem_getNameMax0(JNIEnv *env, jobject this, |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
525 |
jstring pathname) |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
526 |
{ |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
527 |
jlong length = -1; |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
528 |
WITH_PLATFORM_STRING(env, pathname, path) { |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
529 |
length = (jlong)pathconf(path, _PC_NAME_MAX); |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
530 |
} END_PLATFORM_STRING(env, path); |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
531 |
return length != -1 ? length : (jlong)NAME_MAX; |
a94fc33e9866
8148023: File.createTempFile is not adhering to the contract regarding file name lengths
bpb
parents:
31144
diff
changeset
|
532 |
} |