author | alanb |
Thu, 16 Aug 2012 11:14:42 +0100 | |
changeset 13571 | 737b7b4bd73a |
parent 5506 | 202f599c92aa |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
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 |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
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. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
#include "jni.h" |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
#include "jni_util.h" |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
#include "jvm.h" |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
#include "jlong.h" |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
#include <stdio.h> |
13571
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
32 |
#include <string.h> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
#include <dlfcn.h> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
#include <errno.h> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
#include <mntent.h> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
#include "sun_nio_fs_LinuxNativeDispatcher.h" |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
typedef size_t fgetxattr_func(int fd, const char* name, void* value, size_t size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
typedef int fsetxattr_func(int fd, const char* name, void* value, size_t size, int flags); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
typedef int fremovexattr_func(int fd, const char* name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
typedef int flistxattr_func(int fd, char* list, size_t size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
fgetxattr_func* my_fgetxattr_func = NULL; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
fsetxattr_func* my_fsetxattr_func = NULL; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
fremovexattr_func* my_fremovexattr_func = NULL; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
flistxattr_func* my_flistxattr_func = NULL; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
|
13571
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
49 |
static jfieldID entry_name; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
50 |
static jfieldID entry_dir; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
51 |
static jfieldID entry_fstype; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
52 |
static jfieldID entry_options; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
53 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
54 |
static void throwUnixException(JNIEnv* env, int errnum) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
"(I)V", errnum); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
if (x != NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
(*env)->Throw(env, x); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr"); |
13571
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
69 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
70 |
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
71 |
if (clazz == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
72 |
return; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
73 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
74 |
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
75 |
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
76 |
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
77 |
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
Java_sun_nio_fs_LinuxNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
82 |
jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
size_t res = -1; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
const char* name = jlong_to_ptr(nameAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
void* value = jlong_to_ptr(valueAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
if (my_fgetxattr_func == NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
errno = ENOTSUP; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
/* EINTR not documented */ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
res = (*my_fgetxattr_func)(fd, name, value, valueLen); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
if (res == (size_t)-1) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
throwUnixException(env, errno); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
return (jint)res; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
Java_sun_nio_fs_LinuxNativeDispatcher_fsetxattr0(JNIEnv* env, jclass clazz, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
102 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
int res = -1; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
const char* name = jlong_to_ptr(nameAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
void* value = jlong_to_ptr(valueAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
if (my_fsetxattr_func == NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
108 |
errno = ENOTSUP; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
/* EINTR not documented */ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
res = (*my_fsetxattr_func)(fd, name, value, valueLen, 0); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
if (res == -1) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
throwUnixException(env, errno); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
Java_sun_nio_fs_LinuxNativeDispatcher_fremovexattr0(JNIEnv* env, jclass clazz, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
jint fd, jlong nameAddress) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
int res = -1; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
const char* name = jlong_to_ptr(nameAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
if (my_fremovexattr_func == NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
errno = ENOTSUP; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
/* EINTR not documented */ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
res = (*my_fremovexattr_func)(fd, name); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
if (res == -1) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
throwUnixException(env, errno); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
Java_sun_nio_fs_LinuxNativeDispatcher_flistxattr(JNIEnv* env, jclass clazz, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
jint fd, jlong listAddress, jint size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
size_t res = -1; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
char* list = jlong_to_ptr(listAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
141 |
if (my_flistxattr_func == NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
errno = ENOTSUP; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
/* EINTR not documented */ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
res = (*my_flistxattr_func)(fd, list, (size_t)size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
if (res == (size_t)-1) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
throwUnixException(env, errno); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
return (jint)res; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
JNIEXPORT jlong JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
153 |
Java_sun_nio_fs_LinuxNativeDispatcher_setmntent0(JNIEnv* env, jclass this, jlong pathAddress, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
jlong modeAddress) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
FILE* fp = NULL; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
const char* path = (const char*)jlong_to_ptr(pathAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
const char* mode = (const char*)jlong_to_ptr(modeAddress); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
do { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
fp = setmntent(path, mode); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
} while (fp == NULL && errno == EINTR); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
if (fp == NULL) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
throwUnixException(env, errno); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
return ptr_to_jlong(fp); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
168 |
|
13571
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
169 |
JNIEXPORT jint JNICALL |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
170 |
Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this, |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
171 |
jlong value, jobject entry) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
172 |
{ |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
173 |
struct mntent ent; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
174 |
char buf[1024]; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
175 |
int buflen = sizeof(buf); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
176 |
struct mntent* m; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
177 |
FILE* fp = jlong_to_ptr(value); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
178 |
jsize len; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
179 |
jbyteArray bytes; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
180 |
char* name; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
181 |
char* dir; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
182 |
char* fstype; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
183 |
char* options; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
184 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
185 |
m = getmntent_r(fp, &ent, (char*)&buf, buflen); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
186 |
if (m == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
187 |
return -1; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
188 |
name = m->mnt_fsname; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
189 |
dir = m->mnt_dir; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
190 |
fstype = m->mnt_type; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
191 |
options = m->mnt_opts; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
192 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
193 |
len = strlen(name); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
194 |
bytes = (*env)->NewByteArray(env, len); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
195 |
if (bytes == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
196 |
return -1; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
197 |
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
198 |
(*env)->SetObjectField(env, entry, entry_name, bytes); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
199 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
200 |
len = strlen(dir); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
201 |
bytes = (*env)->NewByteArray(env, len); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
202 |
if (bytes == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
203 |
return -1; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
204 |
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
205 |
(*env)->SetObjectField(env, entry, entry_dir, bytes); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
206 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
207 |
len = strlen(fstype); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
208 |
bytes = (*env)->NewByteArray(env, len); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
209 |
if (bytes == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
210 |
return -1; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
211 |
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
212 |
(*env)->SetObjectField(env, entry, entry_fstype, bytes); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
213 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
214 |
len = strlen(options); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
215 |
bytes = (*env)->NewByteArray(env, len); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
216 |
if (bytes == NULL) |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
217 |
return -1; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
218 |
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
219 |
(*env)->SetObjectField(env, entry, entry_options, bytes); |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
220 |
|
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
221 |
return 0; |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
222 |
} |
737b7b4bd73a
7191556: (fs) UnixNativeDispatcher.getextmntent should be moved into platform specific code
alanb
parents:
5506
diff
changeset
|
223 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
224 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
Java_sun_nio_fs_LinuxNativeDispatcher_endmntent(JNIEnv* env, jclass this, jlong stream) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
226 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
227 |
FILE* fp = jlong_to_ptr(stream); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
228 |
/* FIXME - man page doesn't explain how errors are returned */ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
229 |
endmntent(fp); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
230 |
} |