summaryrefslogtreecommitdiff
path: root/native
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2007-11-06 13:38:39 +0000
committerMario Torre <neugens@limasoftware.net>2007-11-06 13:38:39 +0000
commitf4dbe7089736fdd7366bd05a605837dd64503277 (patch)
tree6c721ff9be14c422c65b07ada949a97cd9b78ea7 /native
parentfb62a205d6958df7d73355fa3dbd4c93f9b4bbcd (diff)
downloadclasspath-f4dbe7089736fdd7366bd05a605837dd64503277.tar.gz
2007-11-06 Mario Torre <neugens@limasoftware.net>
* vm/reference/java/io/VMFile.java: (getTotalSpace): new method. (getUsableSpace): likewise. (getFreeSpace): likewise. * java/io/File.java: (getTotalSpace): new method. (getUsableSpace): likewise. (getFreeSpace): likewise. * native/jni/java-io/java_io_VMFile.c: (Java_java_io_VMFile_getTotalSpace): new function. (Java_java_io_VMFile_getFreeSpace): likewise. (Java_java_io_VMFile_getUsableSpace): likewise. * native/jni/native-lib/cpio.h: (cpio_df): new function. (CPFILE_DF_TYPE): enum type for cpio_df. * native/jni/native-lib/cpio.c: (cpio_df): new function. * include/java_io_VMFile.h: regenerated. * configure.ac: added check for statvfs.
Diffstat (limited to 'native')
-rw-r--r--native/jni/java-io/java_io_VMFile.c88
-rw-r--r--native/jni/native-lib/cpio.c42
-rw-r--r--native/jni/native-lib/cpio.h9
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);