diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/jni/java-io/java_io_VMFile.c | 88 | ||||
-rw-r--r-- | native/jni/native-lib/cpio.c | 42 | ||||
-rw-r--r-- | native/jni/native-lib/cpio.h | 9 |
3 files changed, 138 insertions, 1 deletions
diff --git a/native/jni/java-io/java_io_VMFile.c b/native/jni/java-io/java_io_VMFile.c index 2882075bb..e79704fa6 100644 --- a/native/jni/java-io/java_io_VMFile.c +++ b/native/jni/java-io/java_io_VMFile.c @@ -334,6 +334,94 @@ Java_java_io_VMFile_setExecutable (JNIEnv *env, return set_file_permissions (env, name, executable, ownerOnly, CPFILE_FLAG_EXEC); } + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getTotalSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, TOTAL); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getFreeSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, FREE); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + +/*************************************************************************/ + +JNIEXPORT jlong JNICALL +Java_java_io_VMFile_getUsableSpace (JNIEnv *env, + jclass clazz __attribute__ ((__unused__)), + jstring path) +{ +#ifndef WITHOUT_FILESYSTEM + + jlong result; + const char *_path = NULL; + + _path = (*env)->GetStringUTFChars (env, path, 0); + if (_path == NULL) + { + return 0L; + } + + result = cpio_df (_path, USABLE); + + (*env)->ReleaseStringUTFChars (env, path, _path); + + return result; + +#else /* not WITHOUT_FILESYSTEM */ + return 0L; +#endif /* not WITHOUT_FILESYSTEM */ +} + /*************************************************************************/ /* diff --git a/native/jni/native-lib/cpio.c b/native/jni/native-lib/cpio.c index 743968bd3..52b45ad11 100644 --- a/native/jni/native-lib/cpio.c +++ b/native/jni/native-lib/cpio.c @@ -71,6 +71,10 @@ exception statement from your version. */ #include <sys/select.h> #endif +#if defined(HAVE_STATVFS) +#include <sys/statvfs.h> +#endif + #include <utime.h> #include "cpnative.h" @@ -395,6 +399,43 @@ int cpio_chmod (const char *filename, int permissions) return 0; } +JNIEXPORT long long +cpio_df (const char *path, CPFILE_DF_TYPE type) +{ + long long result = 0L; + +#if defined(HAVE_STATVFS) + + long long scale_factor = 0L; + struct statvfs buf; + + if (statvfs (path, &buf) < 0) + return 0L; + + /* f_blocks, f_bfree and f_bavail are defined in terms of f_frsize */ + scale_factor = (long long) (buf.f_frsize); + + switch (type) + { + case TOTAL: + result = (long long) (buf.f_blocks * scale_factor); + break; + case FREE: + result = (long long) (buf.f_bfree * scale_factor); + break; + case USABLE: + result = (long long) (buf.f_bavail * scale_factor); + break; + default: + result = 0L; + break; + } + +#endif + + return result; +} + int cpio_checkAccess (const char *filename, unsigned int flag) { struct stat statbuf; @@ -544,7 +585,6 @@ int cpio_readDir (void *handle, char *filename) return 0; } - int cpio_closeOnExec(int fd) { diff --git a/native/jni/native-lib/cpio.h b/native/jni/native-lib/cpio.h index 259fc62cf..a42fe62db 100644 --- a/native/jni/native-lib/cpio.h +++ b/native/jni/native-lib/cpio.h @@ -83,6 +83,15 @@ JNIEXPORT int cpio_removeFile (const char *filename); JNIEXPORT int cpio_mkdir (const char *filename); JNIEXPORT int cpio_rename (const char *old_name, const char *new_name); +/* to be used with cpio_df */ +typedef enum { + TOTAL = 0, + FREE, + USABLE +} CPFILE_DF_TYPE; + +JNIEXPORT long long cpio_df (const char *path, CPFILE_DF_TYPE type); + JNIEXPORT int cpio_openDir (const char *dirname, void **handle); JNIEXPORT int cpio_closeDir (void *handle); JNIEXPORT int cpio_readDir (void *handle, char *filename); |