42 |
43 |
43 fgetxattr_func* my_fgetxattr_func = NULL; |
44 fgetxattr_func* my_fgetxattr_func = NULL; |
44 fsetxattr_func* my_fsetxattr_func = NULL; |
45 fsetxattr_func* my_fsetxattr_func = NULL; |
45 fremovexattr_func* my_fremovexattr_func = NULL; |
46 fremovexattr_func* my_fremovexattr_func = NULL; |
46 flistxattr_func* my_flistxattr_func = NULL; |
47 flistxattr_func* my_flistxattr_func = NULL; |
|
48 |
|
49 static jfieldID entry_name; |
|
50 static jfieldID entry_dir; |
|
51 static jfieldID entry_fstype; |
|
52 static jfieldID entry_options; |
47 |
53 |
48 static void throwUnixException(JNIEnv* env, int errnum) { |
54 static void throwUnixException(JNIEnv* env, int errnum) { |
49 jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", |
55 jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", |
50 "(I)V", errnum); |
56 "(I)V", errnum); |
51 if (x != NULL) { |
57 if (x != NULL) { |
58 { |
64 { |
59 my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr"); |
65 my_fgetxattr_func = (fgetxattr_func*)dlsym(RTLD_DEFAULT, "fgetxattr"); |
60 my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr"); |
66 my_fsetxattr_func = (fsetxattr_func*)dlsym(RTLD_DEFAULT, "fsetxattr"); |
61 my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr"); |
67 my_fremovexattr_func = (fremovexattr_func*)dlsym(RTLD_DEFAULT, "fremovexattr"); |
62 my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr"); |
68 my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr"); |
|
69 |
|
70 clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry"); |
|
71 if (clazz == NULL) |
|
72 return; |
|
73 |
|
74 entry_name = (*env)->GetFieldID(env, clazz, "name", "[B"); |
|
75 entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B"); |
|
76 entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B"); |
|
77 entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B"); |
63 } |
78 } |
64 |
79 |
65 JNIEXPORT jint JNICALL |
80 JNIEXPORT jint JNICALL |
66 Java_sun_nio_fs_LinuxNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz, |
81 Java_sun_nio_fs_LinuxNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz, |
67 jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) |
82 jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) |
149 throwUnixException(env, errno); |
164 throwUnixException(env, errno); |
150 } |
165 } |
151 return ptr_to_jlong(fp); |
166 return ptr_to_jlong(fp); |
152 } |
167 } |
153 |
168 |
|
169 JNIEXPORT jint JNICALL |
|
170 Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this, |
|
171 jlong value, jobject entry) |
|
172 { |
|
173 struct mntent ent; |
|
174 char buf[1024]; |
|
175 int buflen = sizeof(buf); |
|
176 struct mntent* m; |
|
177 FILE* fp = jlong_to_ptr(value); |
|
178 jsize len; |
|
179 jbyteArray bytes; |
|
180 char* name; |
|
181 char* dir; |
|
182 char* fstype; |
|
183 char* options; |
|
184 |
|
185 m = getmntent_r(fp, &ent, (char*)&buf, buflen); |
|
186 if (m == NULL) |
|
187 return -1; |
|
188 name = m->mnt_fsname; |
|
189 dir = m->mnt_dir; |
|
190 fstype = m->mnt_type; |
|
191 options = m->mnt_opts; |
|
192 |
|
193 len = strlen(name); |
|
194 bytes = (*env)->NewByteArray(env, len); |
|
195 if (bytes == NULL) |
|
196 return -1; |
|
197 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name); |
|
198 (*env)->SetObjectField(env, entry, entry_name, bytes); |
|
199 |
|
200 len = strlen(dir); |
|
201 bytes = (*env)->NewByteArray(env, len); |
|
202 if (bytes == NULL) |
|
203 return -1; |
|
204 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir); |
|
205 (*env)->SetObjectField(env, entry, entry_dir, bytes); |
|
206 |
|
207 len = strlen(fstype); |
|
208 bytes = (*env)->NewByteArray(env, len); |
|
209 if (bytes == NULL) |
|
210 return -1; |
|
211 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype); |
|
212 (*env)->SetObjectField(env, entry, entry_fstype, bytes); |
|
213 |
|
214 len = strlen(options); |
|
215 bytes = (*env)->NewByteArray(env, len); |
|
216 if (bytes == NULL) |
|
217 return -1; |
|
218 (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options); |
|
219 (*env)->SetObjectField(env, entry, entry_options, bytes); |
|
220 |
|
221 return 0; |
|
222 } |
|
223 |
154 JNIEXPORT void JNICALL |
224 JNIEXPORT void JNICALL |
155 Java_sun_nio_fs_LinuxNativeDispatcher_endmntent(JNIEnv* env, jclass this, jlong stream) |
225 Java_sun_nio_fs_LinuxNativeDispatcher_endmntent(JNIEnv* env, jclass this, jlong stream) |
156 { |
226 { |
157 FILE* fp = jlong_to_ptr(stream); |
227 FILE* fp = jlong_to_ptr(stream); |
158 /* FIXME - man page doesn't explain how errors are returned */ |
228 /* FIXME - man page doesn't explain how errors are returned */ |