author | alanb |
Sat, 30 Nov 2019 16:21:19 +0000 | |
changeset 59329 | 289000934908 |
parent 59146 | 455612b3161a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57826 | 2 |
* Copyright (c) 2000, 2019, 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 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/socket.h> |
|
28 |
#include <fcntl.h> |
|
29 |
#include <sys/uio.h> |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
30 |
#include <unistd.h> |
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
31 |
#include <sys/stat.h> |
47428 | 32 |
#include <sys/statvfs.h> |
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
33 |
|
26618
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
34 |
#if defined(__linux__) |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
35 |
#include <linux/fs.h> |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
36 |
#include <sys/ioctl.h> |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
37 |
#endif |
2 | 38 |
|
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
39 |
#if defined(_ALLBSD_SOURCE) |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
40 |
#define lseek64 lseek |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
41 |
#define stat64 stat |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
42 |
#define flock64 flock |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
43 |
#define off64_t off_t |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
44 |
#define F_SETLKW64 F_SETLKW |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
45 |
#define F_SETLK64 F_SETLK |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
46 |
#define pread64 pread |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
47 |
#define pwrite64 pwrite |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
48 |
#define ftruncate64 ftruncate |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
49 |
#define fstat64 fstat |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
50 |
#define fdatasync fsync |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11908
diff
changeset
|
51 |
#endif |
2 | 52 |
|
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
53 |
#include "jni.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
54 |
#include "jni_util.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
55 |
#include "jvm.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
56 |
#include "jlong.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
57 |
#include "nio.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
58 |
#include "nio_util.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
59 |
#include "sun_nio_ch_FileDispatcherImpl.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
60 |
#include "java_lang_Long.h" |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
61 |
|
2 | 62 |
static int preCloseFD = -1; /* File descriptor to which we dup other fd's |
63 |
before closing them for real */ |
|
64 |
||
65 |
||
66 |
JNIEXPORT void JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
67 |
Java_sun_nio_ch_FileDispatcherImpl_init(JNIEnv *env, jclass cl) |
2 | 68 |
{ |
69 |
int sp[2]; |
|
70 |
if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) { |
|
71 |
JNU_ThrowIOExceptionWithLastError(env, "socketpair failed"); |
|
72 |
return; |
|
73 |
} |
|
74 |
preCloseFD = sp[0]; |
|
75 |
close(sp[1]); |
|
76 |
} |
|
77 |
||
78 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
79 |
Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz, |
2 | 80 |
jobject fdo, jlong address, jint len) |
81 |
{ |
|
82 |
jint fd = fdval(env, fdo); |
|
83 |
void *buf = (void *)jlong_to_ptr(address); |
|
84 |
||
85 |
return convertReturnVal(env, read(fd, buf, len), JNI_TRUE); |
|
86 |
} |
|
87 |
||
88 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
89 |
Java_sun_nio_ch_FileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 90 |
jlong address, jint len, jlong offset) |
91 |
{ |
|
92 |
jint fd = fdval(env, fdo); |
|
93 |
void *buf = (void *)jlong_to_ptr(address); |
|
94 |
||
95 |
return convertReturnVal(env, pread64(fd, buf, len, offset), JNI_TRUE); |
|
96 |
} |
|
97 |
||
98 |
JNIEXPORT jlong JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
99 |
Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz, |
2 | 100 |
jobject fdo, jlong address, jint len) |
101 |
{ |
|
102 |
jint fd = fdval(env, fdo); |
|
103 |
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); |
|
104 |
return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE); |
|
105 |
} |
|
106 |
||
107 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
108 |
Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, |
2 | 109 |
jobject fdo, jlong address, jint len) |
110 |
{ |
|
111 |
jint fd = fdval(env, fdo); |
|
112 |
void *buf = (void *)jlong_to_ptr(address); |
|
113 |
||
114 |
return convertReturnVal(env, write(fd, buf, len), JNI_FALSE); |
|
115 |
} |
|
116 |
||
117 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
118 |
Java_sun_nio_ch_FileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 119 |
jlong address, jint len, jlong offset) |
120 |
{ |
|
121 |
jint fd = fdval(env, fdo); |
|
122 |
void *buf = (void *)jlong_to_ptr(address); |
|
123 |
||
124 |
return convertReturnVal(env, pwrite64(fd, buf, len, offset), JNI_FALSE); |
|
125 |
} |
|
126 |
||
127 |
JNIEXPORT jlong JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
128 |
Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, |
2 | 129 |
jobject fdo, jlong address, jint len) |
130 |
{ |
|
131 |
jint fd = fdval(env, fdo); |
|
132 |
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); |
|
133 |
return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE); |
|
134 |
} |
|
135 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
136 |
static jlong |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
137 |
handle(JNIEnv *env, jlong rv, char *msg) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
138 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
139 |
if (rv >= 0) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
140 |
return rv; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
141 |
if (errno == EINTR) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
142 |
return IOS_INTERRUPTED; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
143 |
JNU_ThrowIOExceptionWithLastError(env, msg); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
144 |
return IOS_THROWN; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
145 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
146 |
|
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
147 |
JNIEXPORT jlong JNICALL |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
148 |
Java_sun_nio_ch_FileDispatcherImpl_seek0(JNIEnv *env, jclass clazz, |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
149 |
jobject fdo, jlong offset) |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
150 |
{ |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
151 |
jint fd = fdval(env, fdo); |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
152 |
off64_t result; |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
153 |
if (offset < 0) { |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
154 |
result = lseek64(fd, 0, SEEK_CUR); |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
155 |
} else { |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
156 |
result = lseek64(fd, offset, SEEK_SET); |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
157 |
} |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
158 |
return handle(env, (jlong)result, "lseek64 failed"); |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
159 |
} |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
160 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
161 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
162 |
Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
163 |
jobject fdo, jboolean md) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
164 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
165 |
jint fd = fdval(env, fdo); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
166 |
int result = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
167 |
|
30689
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
168 |
#ifdef MACOSX |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
169 |
result = fcntl(fd, F_FULLFSYNC); |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
170 |
if (result == -1 && errno == ENOTSUP) { |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
171 |
/* Try fsync() in case F_FULLSYUNC is not implemented on the file system. */ |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
172 |
result = fsync(fd); |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
173 |
} |
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
174 |
#else /* end MACOSX, begin not-MACOSX */ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
175 |
if (md == JNI_FALSE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
176 |
result = fdatasync(fd); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
177 |
} else { |
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
178 |
#ifdef _AIX |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
179 |
/* On AIX, calling fsync on a file descriptor that is opened only for |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
180 |
* reading results in an error ("EBADF: The FileDescriptor parameter is |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
181 |
* not a valid file descriptor open for writing."). |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
182 |
* However, at this point it is not possibly anymore to read the |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
183 |
* 'writable' attribute of the corresponding file channel so we have to |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
184 |
* use 'fcntl'. |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
185 |
*/ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
186 |
int getfl = fcntl(fd, F_GETFL); |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
187 |
if (getfl >= 0 && (getfl & O_ACCMODE) == O_RDONLY) { |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
188 |
return 0; |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
14342
diff
changeset
|
189 |
} |
30689
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
190 |
#endif /* _AIX */ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
191 |
result = fsync(fd); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
192 |
} |
30689
446373feb21e
8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X
bpb
parents:
26618
diff
changeset
|
193 |
#endif /* not-MACOSX */ |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
194 |
return handle(env, result, "Force failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
195 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
196 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
197 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
198 |
Java_sun_nio_ch_FileDispatcherImpl_truncate0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
199 |
jobject fdo, jlong size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
200 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
201 |
return handle(env, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
202 |
ftruncate64(fdval(env, fdo), size), |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
203 |
"Truncation failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
204 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
205 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
206 |
JNIEXPORT jlong JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
207 |
Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
208 |
{ |
26618
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
209 |
jint fd = fdval(env, fdo); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
210 |
struct stat64 fbuf; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
211 |
|
26618
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
212 |
if (fstat64(fd, &fbuf) < 0) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
213 |
return handle(env, -1, "Size failed"); |
26618
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
214 |
|
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
215 |
#ifdef BLKGETSIZE64 |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
216 |
if (S_ISBLK(fbuf.st_mode)) { |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
217 |
uint64_t size; |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
218 |
if (ioctl(fd, BLKGETSIZE64, &size) < 0) |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
219 |
return handle(env, -1, "Size failed"); |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
220 |
return (jlong)size; |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
221 |
} |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
222 |
#endif |
f30d461d3162
8054029: (fc) FileChannel.size() returns 0 for block devices on Linux
igerasim
parents:
25859
diff
changeset
|
223 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
224 |
return fbuf.st_size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
225 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
226 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
227 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
228 |
Java_sun_nio_ch_FileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject fdo, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
229 |
jboolean block, jlong pos, jlong size, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
230 |
jboolean shared) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
231 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
232 |
jint fd = fdval(env, fdo); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
233 |
jint lockResult = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
234 |
int cmd = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
235 |
struct flock64 fl; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
236 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
237 |
fl.l_whence = SEEK_SET; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
238 |
if (size == (jlong)java_lang_Long_MAX_VALUE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
239 |
fl.l_len = (off64_t)0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
240 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
241 |
fl.l_len = (off64_t)size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
242 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
243 |
fl.l_start = (off64_t)pos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
244 |
if (shared == JNI_TRUE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
245 |
fl.l_type = F_RDLCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
246 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
247 |
fl.l_type = F_WRLCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
248 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
249 |
if (block == JNI_TRUE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
250 |
cmd = F_SETLKW64; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
251 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
252 |
cmd = F_SETLK64; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
253 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
254 |
lockResult = fcntl(fd, cmd, &fl); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
255 |
if (lockResult < 0) { |
11908
384d1c31d539
7146506: (fc) Add EACCES check to the return of fcntl native method
littlee
parents:
5506
diff
changeset
|
256 |
if ((cmd == F_SETLK64) && (errno == EAGAIN || errno == EACCES)) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
257 |
return sun_nio_ch_FileDispatcherImpl_NO_LOCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
258 |
if (errno == EINTR) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
259 |
return sun_nio_ch_FileDispatcherImpl_INTERRUPTED; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
260 |
JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
261 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
262 |
return 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
263 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
264 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
265 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
266 |
Java_sun_nio_ch_FileDispatcherImpl_release0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
267 |
jobject fdo, jlong pos, jlong size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
268 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
269 |
jint fd = fdval(env, fdo); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
270 |
jint lockResult = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
271 |
struct flock64 fl; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
272 |
int cmd = F_SETLK64; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
273 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
274 |
fl.l_whence = SEEK_SET; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
275 |
if (size == (jlong)java_lang_Long_MAX_VALUE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
276 |
fl.l_len = (off64_t)0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
277 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
278 |
fl.l_len = (off64_t)size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
279 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
280 |
fl.l_start = (off64_t)pos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
281 |
fl.l_type = F_UNLCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
282 |
lockResult = fcntl(fd, cmd, &fl); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
283 |
if (lockResult < 0) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
284 |
JNU_ThrowIOExceptionWithLastError(env, "Release failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
285 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
286 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
287 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
288 |
|
2 | 289 |
static void closeFileDescriptor(JNIEnv *env, int fd) { |
290 |
if (fd != -1) { |
|
291 |
int result = close(fd); |
|
292 |
if (result < 0) |
|
293 |
JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
JNIEXPORT void JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
298 |
Java_sun_nio_ch_FileDispatcherImpl_close0(JNIEnv *env, jclass clazz, jobject fdo) |
2 | 299 |
{ |
300 |
jint fd = fdval(env, fdo); |
|
301 |
closeFileDescriptor(env, fd); |
|
302 |
} |
|
303 |
||
304 |
JNIEXPORT void JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
305 |
Java_sun_nio_ch_FileDispatcherImpl_preClose0(JNIEnv *env, jclass clazz, jobject fdo) |
2 | 306 |
{ |
307 |
jint fd = fdval(env, fdo); |
|
308 |
if (preCloseFD >= 0) { |
|
309 |
if (dup2(preCloseFD, fd) < 0) |
|
310 |
JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
JNIEXPORT void JNICALL |
|
59146
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
315 |
Java_sun_nio_ch_FileDispatcherImpl_dup0(JNIEnv *env, jobject this, jobject fdo1, jobject fdo2) |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
316 |
{ |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
317 |
if (dup2(fdval(env, fdo1), fdval(env, fdo2)) < 0) { |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
318 |
JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
319 |
} |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
320 |
} |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
321 |
|
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
57826
diff
changeset
|
322 |
JNIEXPORT void JNICALL |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
323 |
Java_sun_nio_ch_FileDispatcherImpl_closeIntFD(JNIEnv *env, jclass clazz, jint fd) |
2 | 324 |
{ |
325 |
closeFileDescriptor(env, fd); |
|
326 |
} |
|
47428 | 327 |
|
328 |
JNIEXPORT jint JNICALL |
|
329 |
Java_sun_nio_ch_FileDispatcherImpl_setDirect0(JNIEnv *env, jclass clazz, |
|
330 |
jobject fdo) |
|
331 |
{ |
|
332 |
jint fd = fdval(env, fdo); |
|
333 |
jint result; |
|
334 |
#ifdef MACOSX |
|
335 |
struct statvfs file_stat; |
|
336 |
#else |
|
337 |
struct statvfs64 file_stat; |
|
338 |
#endif |
|
339 |
||
340 |
#if defined(O_DIRECT) || defined(F_NOCACHE) || defined(DIRECTIO_ON) |
|
341 |
#ifdef O_DIRECT |
|
342 |
jint orig_flag; |
|
343 |
orig_flag = fcntl(fd, F_GETFL); |
|
344 |
if (orig_flag == -1) { |
|
345 |
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); |
|
346 |
return -1; |
|
347 |
} |
|
348 |
result = fcntl(fd, F_SETFL, orig_flag | O_DIRECT); |
|
349 |
if (result == -1) { |
|
350 |
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); |
|
351 |
return result; |
|
352 |
} |
|
57826 | 353 |
#elif defined(F_NOCACHE) |
47428 | 354 |
result = fcntl(fd, F_NOCACHE, 1); |
355 |
if (result == -1) { |
|
356 |
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); |
|
357 |
return result; |
|
358 |
} |
|
57826 | 359 |
#elif defined(DIRECTIO_ON) |
47428 | 360 |
result = directio(fd, DIRECTIO_ON); |
361 |
if (result == -1) { |
|
362 |
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); |
|
363 |
return result; |
|
364 |
} |
|
365 |
#endif |
|
366 |
#ifdef MACOSX |
|
367 |
result = fstatvfs(fd, &file_stat); |
|
368 |
#else |
|
369 |
result = fstatvfs64(fd, &file_stat); |
|
370 |
#endif |
|
371 |
if(result == -1) { |
|
372 |
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); |
|
373 |
return result; |
|
374 |
} else { |
|
375 |
result = (int)file_stat.f_frsize; |
|
376 |
} |
|
377 |
#else |
|
378 |
result == -1; |
|
379 |
#endif |
|
380 |
return result; |
|
381 |
} |