diff --git a/readme.md b/readme.md index 2e9e93e..7552cab 100755 --- a/readme.md +++ b/readme.md @@ -96,6 +96,7 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application. * Build 32 bit and 64 bit libraries. * Windows: flush System.out or System.err on attribute change. * Solaris: fix unicode file name handling. +* Linux: detect remote filesystems. ### 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. * Initial release. * Use fully decomposed form for unicode file names on hfs+ filesystems. - diff --git a/src/main/cpp/linux.cpp b/src/main/cpp/linux.cpp new file mode 100644 index 0000000..2372d26 --- /dev/null +++ b/src/main/cpp/linux.cpp @@ -0,0 +1,34 @@ +#ifdef __linux__ + +#include "native.h" +#include "generic.h" +#include +#include + +/* + * 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 diff --git a/src/main/cpp/posix.cpp b/src/main/cpp/posix.cpp index 0ef1457..5da2a68 100755 --- a/src/main/cpp/posix.cpp +++ b/src/main/cpp/posix.cpp @@ -27,7 +27,7 @@ Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getSystemIn jclass infoClass = env->GetObjectClass(info); // 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) { mark_failed_with_message(env, "could not create locale", result); return; diff --git a/src/main/java/net/rubygrapefruit/platform/internal/Platform.java b/src/main/java/net/rubygrapefruit/platform/internal/Platform.java index 7746bc9..0497960 100755 --- a/src/main/java/net/rubygrapefruit/platform/internal/Platform.java +++ b/src/main/java/net/rubygrapefruit/platform/internal/Platform.java @@ -100,6 +100,13 @@ public abstract class Platform { } private static class Linux extends Unix { + @Override + public T get(Class type) { + if (type.equals(FileSystems.class)) { + return type.cast(new PosixFileSystems()); + } + return super.get(type); + } } private static class Solaris extends Unix {