summaryrefslogtreecommitdiff
path: root/java/io
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 /java/io
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 'java/io')
-rw-r--r--java/io/File.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/java/io/File.java b/java/io/File.java
index f34b4dd2b..cd1116350 100644
--- a/java/io/File.java
+++ b/java/io/File.java
@@ -1293,6 +1293,73 @@ public class File implements Serializable, Comparable<File>
}
/**
+ * Get the total space for the partition pointed by this file path, in bytes.
+ *
+ * @return the total number of bytes in this partition.
+ * @since 1.6
+ */
+ public long getTotalSpace()
+ {
+ // check security manager.
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
+ checkRead();
+
+ return VMFile.getTotalSpace(path);
+ }
+
+ /**
+ * Get the free space in the partition pointed by this file path, in bytes.
+ *
+ * @return the number of free bytes in this partition.
+ * @since 1.6
+ */
+ public long getFreeSpace()
+ {
+ // check security manager.
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
+ checkRead();
+
+ return VMFile.getFreeSpace(path);
+ }
+
+ /**
+ * Get the usable space in the partition pointed by this file path, in bytes.
+ * This is not necessarily the same as the number returned by
+ * {@link #getFreeSpace()}.
+ *
+ * <strong>Implementation note</strong>: Unlike the RI, on Linux and UNIX
+ * like systems this methods take into account the reserved space for the
+ * "root" user. This means that the returned results will be a little
+ * different if a normal user or root perform the query.
+ *
+ * Also, the bytes returned should be interpreted as an hint, and may be
+ * different at each call of this method or even right after the method
+ * returns.
+ *
+ * @return the number of usable bytes in this partition.
+ * @since 1.6
+ */
+ public long getUsableSpace()
+ {
+ // check security manager.
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkPermission(new RuntimePermission("getFileSystemAttributes"));
+ checkRead();
+
+ // root users can use the reserved extra space
+ String user = System.getProperty("user.name");
+ if (user != null && user.equals("root"))
+ return VMFile.getFreeSpace(path);
+
+ return VMFile.getUsableSpace(path);
+ }
+
+ /**
* This method sets the file represented by this object to be read only.
* A read only file or directory cannot be modified. Please note that
* GNU systems allow read only files to be deleted if the directory it