Implemented FileSystems on Linux.
This commit is contained in:
@@ -96,6 +96,7 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
|
|||||||
* Build 32 bit and 64 bit libraries.
|
* Build 32 bit and 64 bit libraries.
|
||||||
* Windows: flush System.out or System.err on attribute change.
|
* Windows: flush System.out or System.err on attribute change.
|
||||||
* Solaris: fix unicode file name handling.
|
* Solaris: fix unicode file name handling.
|
||||||
|
* Linux: detect remote filesystems.
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
@@ -113,4 +114,3 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
|
|||||||
* Improve error message when unsupported capability is used.
|
* Improve error message when unsupported capability is used.
|
||||||
* Initial release.
|
* Initial release.
|
||||||
* Use fully decomposed form for unicode file names on hfs+ filesystems.
|
* Use fully decomposed form for unicode file names on hfs+ filesystems.
|
||||||
|
|
||||||
|
|||||||
34
src/main/cpp/linux.cpp
Normal file
34
src/main/cpp/linux.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifdef __linux__
|
||||||
|
|
||||||
|
#include "native.h"
|
||||||
|
#include "generic.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* File system functions
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) {
|
||||||
|
FILE *fp = setmntent(MOUNTED, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
mark_failed_with_errno(env, "could not open mount file", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char buf[1024];
|
||||||
|
struct mntent mount_info;
|
||||||
|
|
||||||
|
jclass info_class = env->GetObjectClass(info);
|
||||||
|
jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V");
|
||||||
|
|
||||||
|
while (getmntent_r(fp, &mount_info, buf, sizeof(buf)) != NULL) {
|
||||||
|
jstring mount_point = env->NewStringUTF(mount_info.mnt_dir);
|
||||||
|
jstring file_system_type = env->NewStringUTF(mount_info.mnt_type);
|
||||||
|
jstring device_name = env->NewStringUTF(mount_info.mnt_fsname);
|
||||||
|
env->CallVoidMethod(info, method, mount_point, file_system_type, device_name, JNI_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
endmntent(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -27,7 +27,7 @@ Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getSystemIn
|
|||||||
jclass infoClass = env->GetObjectClass(info);
|
jclass infoClass = env->GetObjectClass(info);
|
||||||
|
|
||||||
// Empty string means load locale from environment.
|
// Empty string means load locale from environment.
|
||||||
locale_t locale = newlocale(LC_CTYPE_MASK, "", LC_GLOBAL_LOCALE);
|
locale_t locale = newlocale(LC_CTYPE_MASK, "", NULL);
|
||||||
if (locale == NULL) {
|
if (locale == NULL) {
|
||||||
mark_failed_with_message(env, "could not create locale", result);
|
mark_failed_with_message(env, "could not create locale", result);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -100,6 +100,13 @@ public abstract class Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class Linux extends Unix {
|
private static class Linux extends Unix {
|
||||||
|
@Override
|
||||||
|
public <T extends NativeIntegration> T get(Class<T> type) {
|
||||||
|
if (type.equals(FileSystems.class)) {
|
||||||
|
return type.cast(new PosixFileSystems());
|
||||||
|
}
|
||||||
|
return super.get(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Solaris extends Unix {
|
private static class Solaris extends Unix {
|
||||||
|
|||||||
Reference in New Issue
Block a user