diff --git a/src/main/cpp/freebsd.cpp b/src/main/cpp/freebsd.cpp index 29f408b..63a8fb7 100644 --- a/src/main/cpp/freebsd.cpp +++ b/src/main/cpp/freebsd.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014 Adam Murdoch + * Copyright 2012 Adam Murdoch * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +15,47 @@ */ /* - * FreeBSD specific functions. + * FreeBSD (including OS X) specific functions. */ -#ifdef __FreeBSD__ +#if defined(__APPLE__) || defined(__FreeBSD__) #include "native.h" #include "generic.h" +#include +#include +#include +#include /* * File system functions */ JNIEXPORT void JNICALL Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) { - mark_failed_with_message(env, "not implemented", result); + int fs_count = getfsstat(NULL, 0, MNT_NOWAIT); + if (fs_count < 0) { + mark_failed_with_errno(env, "could not stat file systems", result); + return; + } + + size_t len = fs_count * sizeof(struct statfs); + struct statfs* buf = (struct statfs*)malloc(len); + if (getfsstat(buf, len, MNT_NOWAIT) < 0 ) { + mark_failed_with_errno(env, "could not stat file systems", result); + free(buf); + return; + } + + jclass info_class = env->GetObjectClass(info); + jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"); + + for (int i = 0; i < fs_count; i++) { + jstring mount_point = char_to_java(env, buf[i].f_mntonname, result); + jstring file_system_type = char_to_java(env, buf[i].f_fstypename, result); + jstring device_name = char_to_java(env, buf[i].f_mntfromname, result); + jboolean remote = (buf[i].f_flags & MNT_LOCAL) == 0; + env->CallVoidMethod(info, method, mount_point, file_system_type, device_name, remote); + } + free(buf); } #endif diff --git a/src/main/cpp/osx.cpp b/src/main/cpp/osx.cpp deleted file mode 100644 index 507f8db..0000000 --- a/src/main/cpp/osx.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012 Adam Murdoch - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * OS X specific functions. - */ -#ifdef __APPLE__ - -#include "native.h" -#include "generic.h" -#include -#include -#include -#include - -/* - * File system functions - */ -JNIEXPORT void JNICALL -Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) { - int fs_count = getfsstat(NULL, 0, MNT_NOWAIT); - if (fs_count < 0) { - mark_failed_with_errno(env, "could not stat file systems", result); - return; - } - - size_t len = fs_count * sizeof(struct statfs); - struct statfs* buf = (struct statfs*)malloc(len); - if (getfsstat(buf, len, MNT_NOWAIT) < 0 ) { - mark_failed_with_errno(env, "could not stat file systems", result); - free(buf); - return; - } - - jclass info_class = env->GetObjectClass(info); - jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"); - - for (int i = 0; i < fs_count; i++) { - jstring mount_point = char_to_java(env, buf[i].f_mntonname, result); - jstring file_system_type = char_to_java(env, buf[i].f_fstypename, result); - jstring device_name = char_to_java(env, buf[i].f_mntfromname, result); - jboolean remote = (buf[i].f_flags & MNT_LOCAL) == 0; - env->CallVoidMethod(info, method, mount_point, file_system_type, device_name, remote); - } - free(buf); -} - -#endif