Implemented FileSystems on Linux.

This commit is contained in:
Adam Murdoch
2012-08-12 12:59:00 +10:00
parent b494c52441
commit 058df967a4
4 changed files with 43 additions and 2 deletions

View File

@@ -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.

34
src/main/cpp/linux.cpp Normal file
View 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

View File

@@ -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;

View File

@@ -100,6 +100,13 @@ public abstract class Platform {
}
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 {