summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-07-09 15:10:27 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-09 15:10:27 -0700
commit029b00d62b71747b2a700788066f92a7dd8579e2 (patch)
tree10dd2831f910a39afde1b42adde281c1483644ee
parente9de0dc2087de87074a3bb5a6391d9ca1bda79af (diff)
parentec618403efee992f232f017fbff1afff6cfa0de3 (diff)
downloadlibcore-029b00d62b71747b2a700788066f92a7dd8579e2.zip
libcore-029b00d62b71747b2a700788066f92a7dd8579e2.tar.gz
libcore-029b00d62b71747b2a700788066f92a7dd8579e2.tar.bz2
am ec618403: Merge "Switch libcore from statfs to statvfs."
* commit 'ec618403efee992f232f017fbff1afff6cfa0de3': Switch libcore from statfs to statvfs.
-rw-r--r--luni/src/main/java/java/io/File.java8
-rw-r--r--luni/src/main/java/libcore/io/ForwardingOs.java4
-rw-r--r--luni/src/main/java/libcore/io/Os.java5
-rw-r--r--luni/src/main/java/libcore/io/Posix.java4
-rw-r--r--luni/src/main/java/libcore/io/StructStatFs.java61
-rw-r--r--luni/src/main/java/libcore/io/StructStatVfs.java71
-rw-r--r--luni/src/main/native/Portability.h4
-rw-r--r--luni/src/main/native/libcore_io_Posix.cpp54
8 files changed, 110 insertions, 101 deletions
diff --git a/luni/src/main/java/java/io/File.java b/luni/src/main/java/java/io/File.java
index 6c179f4..a8b4810 100644
--- a/luni/src/main/java/java/io/File.java
+++ b/luni/src/main/java/java/io/File.java
@@ -27,7 +27,7 @@ import libcore.io.ErrnoException;
import libcore.io.IoUtils;
import libcore.io.Libcore;
import libcore.io.StructStat;
-import libcore.io.StructStatFs;
+import libcore.io.StructStatVfs;
import org.apache.harmony.luni.util.DeleteOnExit;
import static libcore.io.OsConstants.*;
@@ -1130,7 +1130,7 @@ public class File implements Serializable, Comparable<File> {
*/
public long getTotalSpace() {
try {
- StructStatFs sb = Libcore.os.statfs(path);
+ StructStatVfs sb = Libcore.os.statvfs(path);
return sb.f_blocks * sb.f_bsize; // total block count * block size in bytes.
} catch (ErrnoException errnoException) {
return 0;
@@ -1152,7 +1152,7 @@ public class File implements Serializable, Comparable<File> {
*/
public long getUsableSpace() {
try {
- StructStatFs sb = Libcore.os.statfs(path);
+ StructStatVfs sb = Libcore.os.statvfs(path);
return sb.f_bavail * sb.f_bsize; // non-root free block count * block size in bytes.
} catch (ErrnoException errnoException) {
return 0;
@@ -1170,7 +1170,7 @@ public class File implements Serializable, Comparable<File> {
*/
public long getFreeSpace() {
try {
- StructStatFs sb = Libcore.os.statfs(path);
+ StructStatVfs sb = Libcore.os.statvfs(path);
return sb.f_bfree * sb.f_bsize; // free block count * block size in bytes.
} catch (ErrnoException errnoException) {
return 0;
diff --git a/luni/src/main/java/libcore/io/ForwardingOs.java b/luni/src/main/java/libcore/io/ForwardingOs.java
index 2de13ae..0a7be06 100644
--- a/luni/src/main/java/libcore/io/ForwardingOs.java
+++ b/luni/src/main/java/libcore/io/ForwardingOs.java
@@ -54,7 +54,7 @@ public class ForwardingOs implements Os {
public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException { return os.fcntlFlock(fd, cmd, arg); }
public void fdatasync(FileDescriptor fd) throws ErrnoException { os.fdatasync(fd); }
public StructStat fstat(FileDescriptor fd) throws ErrnoException { return os.fstat(fd); }
- public StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException { return os.fstatfs(fd); }
+ public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return os.fstatvfs(fd); }
public void fsync(FileDescriptor fd) throws ErrnoException { os.fsync(fd); }
public void ftruncate(FileDescriptor fd, long length) throws ErrnoException { os.ftruncate(fd, length); }
public String gai_strerror(int error) { return os.gai_strerror(error); }
@@ -128,7 +128,7 @@ public class ForwardingOs implements Os {
public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return os.socket(domain, type, protocol); }
public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { os.socketpair(domain, type, protocol, fd1, fd2); }
public StructStat stat(String path) throws ErrnoException { return os.stat(path); }
- public StructStatFs statfs(String path) throws ErrnoException { return os.statfs(path); }
+ public StructStatVfs statvfs(String path) throws ErrnoException { return os.statvfs(path); }
public String strerror(int errno) { return os.strerror(errno); }
public String strsignal(int signal) { return os.strsignal(signal); }
public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); }
diff --git a/luni/src/main/java/libcore/io/Os.java b/luni/src/main/java/libcore/io/Os.java
index f3d2383..306acea 100644
--- a/luni/src/main/java/libcore/io/Os.java
+++ b/luni/src/main/java/libcore/io/Os.java
@@ -45,7 +45,7 @@ public interface Os {
public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException;
public void fdatasync(FileDescriptor fd) throws ErrnoException;
public StructStat fstat(FileDescriptor fd) throws ErrnoException;
- public StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException;
+ public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException;
public void fsync(FileDescriptor fd) throws ErrnoException;
public void ftruncate(FileDescriptor fd, long length) throws ErrnoException;
public String gai_strerror(int error);
@@ -121,8 +121,7 @@ public interface Os {
public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException;
public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException;
public StructStat stat(String path) throws ErrnoException;
- /* TODO: replace statfs with statvfs. */
- public StructStatFs statfs(String path) throws ErrnoException;
+ public StructStatVfs statvfs(String path) throws ErrnoException;
public String strerror(int errno);
public String strsignal(int signal);
public void symlink(String oldPath, String newPath) throws ErrnoException;
diff --git a/luni/src/main/java/libcore/io/Posix.java b/luni/src/main/java/libcore/io/Posix.java
index e9d1da3..f871697 100644
--- a/luni/src/main/java/libcore/io/Posix.java
+++ b/luni/src/main/java/libcore/io/Posix.java
@@ -48,7 +48,7 @@ public final class Posix implements Os {
public native int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException;
public native void fdatasync(FileDescriptor fd) throws ErrnoException;
public native StructStat fstat(FileDescriptor fd) throws ErrnoException;
- public native StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException;
+ public native StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException;
public native void fsync(FileDescriptor fd) throws ErrnoException;
public native void ftruncate(FileDescriptor fd, long length) throws ErrnoException;
public native String gai_strerror(int error);
@@ -172,7 +172,7 @@ public final class Posix implements Os {
public native FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException;
public native void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException;
public native StructStat stat(String path) throws ErrnoException;
- public native StructStatFs statfs(String path) throws ErrnoException;
+ public native StructStatVfs statvfs(String path) throws ErrnoException;
public native String strerror(int errno);
public native String strsignal(int signal);
public native void symlink(String oldPath, String newPath) throws ErrnoException;
diff --git a/luni/src/main/java/libcore/io/StructStatFs.java b/luni/src/main/java/libcore/io/StructStatFs.java
deleted file mode 100644
index 603dc86..0000000
--- a/luni/src/main/java/libcore/io/StructStatFs.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * 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.
- */
-
-package libcore.io;
-
-/**
- * File information returned by fstatfs(2) and statfs(2).
- *
- * TODO: this should be {@code struct statvfs}, but Bionic doesn't support that yet.
- * @hide until the TODO is fixed.
- */
-public final class StructStatFs {
- /** File system block size (used for block counts). */
- public final long f_bsize; /*unsigned long*/
-
- /** Total block count. */
- public final long f_blocks; /*fsblkcnt_t*/
-
- /** Free block count. */
- public final long f_bfree; /*fsblkcnt_t*/
-
- /** Free block count available to non-root. */
- public final long f_bavail; /*fsblkcnt_t*/
-
- /** Total file (inode) count. */
- public final long f_files; /*fsfilcnt_t*/
-
- /** Free file (inode) count. */
- public final long f_ffree; /*fsfilcnt_t*/
-
- /** Maximum filename length. */
- public final long f_namemax; /*unsigned long*/
-
- /** Fundamental file system block size. */
- public final long f_frsize; /*unsigned long*/
-
- StructStatFs(long f_bsize, long f_blocks, long f_bfree, long f_bavail,
- long f_files, long f_ffree, long f_namemax, long f_frsize) {
- this.f_bsize = f_bsize;
- this.f_blocks = f_blocks;
- this.f_bfree = f_bfree;
- this.f_bavail = f_bavail;
- this.f_files = f_files;
- this.f_ffree = f_ffree;
- this.f_namemax = f_namemax;
- this.f_frsize = f_frsize;
- }
-}
diff --git a/luni/src/main/java/libcore/io/StructStatVfs.java b/luni/src/main/java/libcore/io/StructStatVfs.java
new file mode 100644
index 0000000..bb78ff2
--- /dev/null
+++ b/luni/src/main/java/libcore/io/StructStatVfs.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package libcore.io;
+
+/**
+ * File information returned by fstatvfs(2) and statvfs(2).
+ */
+public final class StructStatVfs {
+ /** File system block size (used for block counts). */
+ public final long f_bsize; /*unsigned long*/
+
+ /** Fundamental file system block size. */
+ public final long f_frsize; /*unsigned long*/
+
+ /** Total block count. */
+ public final long f_blocks; /*fsblkcnt_t*/
+
+ /** Free block count. */
+ public final long f_bfree; /*fsblkcnt_t*/
+
+ /** Free block count available to non-root. */
+ public final long f_bavail; /*fsblkcnt_t*/
+
+ /** Total file (inode) count. */
+ public final long f_files; /*fsfilcnt_t*/
+
+ /** Free file (inode) count. */
+ public final long f_ffree; /*fsfilcnt_t*/
+
+ /** Free file (inode) count available to non-root. */
+ public final long f_favail; /*fsfilcnt_t*/
+
+ /** File system id. */
+ public final long f_fsid; /*unsigned long*/
+
+ /** Bit mask of ST_* flags. */
+ public final long f_flag; /*unsigned long*/
+
+ /** Maximum filename length. */
+ public final long f_namemax; /*unsigned long*/
+
+ StructStatVfs(long f_bsize, long f_frsize, long f_blocks, long f_bfree, long f_bavail,
+ long f_files, long f_ffree, long f_favail,
+ long f_fsid, long f_flag, long f_namemax) {
+ this.f_bsize = f_bsize;
+ this.f_frsize = f_frsize;
+ this.f_blocks = f_blocks;
+ this.f_bfree = f_bfree;
+ this.f_bavail = f_bavail;
+ this.f_files = f_files;
+ this.f_ffree = f_ffree;
+ this.f_favail = f_favail;
+ this.f_fsid = f_fsid;
+ this.f_flag = f_flag;
+ this.f_namemax = f_namemax;
+ }
+}
diff --git a/luni/src/main/native/Portability.h b/luni/src/main/native/Portability.h
index 833d5bb..60b7062 100644
--- a/luni/src/main/native/Portability.h
+++ b/luni/src/main/native/Portability.h
@@ -72,9 +72,7 @@ static inline int mincore(void* addr, size_t length, unsigned char* vec) {
#include <byteswap.h>
#include <sys/sendfile.h>
-
-// For statfs(3).
-#include <sys/vfs.h> // Bionic doesn't have <sys/statvfs.h>
+#include <sys/statvfs.h>
#endif
diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp
index 0745cbc..b358514 100644
--- a/luni/src/main/native/libcore_io_Posix.cpp
+++ b/luni/src/main/native/libcore_io_Posix.cpp
@@ -246,26 +246,28 @@ static jobject makeStructStat(JNIEnv* env, const struct stat& sb) {
static_cast<jlong>(sb.st_blocks));
}
-static jobject makeStructStatFs(JNIEnv* env, const struct statfs& sb) {
+static jobject makeStructStatVfs(JNIEnv* env, const struct statvfs& sb) {
#if defined(__APPLE__)
// Mac OS has no f_namelen field in struct statfs.
jlong max_name_length = 255; // __DARWIN_MAXNAMLEN
#else
- // Until Mac OS 10.7, these were 32-bit fields.
- STATIC_ASSERT(sizeof(sb.f_bavail) == sizeof(jlong), statfs_not_64_bit);
- STATIC_ASSERT(sizeof(sb.f_bfree) == sizeof(jlong), statfs_not_64_bit);
- STATIC_ASSERT(sizeof(sb.f_blocks) == sizeof(jlong), statfs_not_64_bit);
-
- jlong max_name_length = static_cast<jlong>(sb.f_namelen);
+ jlong max_name_length = static_cast<jlong>(sb.f_namemax);
#endif
- static jmethodID ctor = env->GetMethodID(JniConstants::structStatFsClass, "<init>",
- "(JJJJJJJJ)V");
- return env->NewObject(JniConstants::structStatFsClass, ctor, static_cast<jlong>(sb.f_bsize),
- static_cast<jlong>(sb.f_blocks), static_cast<jlong>(sb.f_bfree),
- static_cast<jlong>(sb.f_bavail), static_cast<jlong>(sb.f_files),
- static_cast<jlong>(sb.f_ffree), max_name_length,
- static_cast<jlong>(sb.f_frsize));
+ static jmethodID ctor = env->GetMethodID(JniConstants::structStatVfsClass, "<init>",
+ "(JJJJJJJJJJJ)V");
+ return env->NewObject(JniConstants::structStatVfsClass, ctor,
+ static_cast<jlong>(sb.f_bsize),
+ static_cast<jlong>(sb.f_frsize),
+ static_cast<jlong>(sb.f_blocks),
+ static_cast<jlong>(sb.f_bfree),
+ static_cast<jlong>(sb.f_bavail),
+ static_cast<jlong>(sb.f_files),
+ static_cast<jlong>(sb.f_ffree),
+ static_cast<jlong>(sb.f_favail),
+ static_cast<jlong>(sb.f_fsid),
+ static_cast<jlong>(sb.f_flag),
+ max_name_length);
}
static jobject makeStructLinger(JNIEnv* env, const struct linger& l) {
@@ -571,15 +573,15 @@ static jobject Posix_fstat(JNIEnv* env, jobject, jobject javaFd) {
return makeStructStat(env, sb);
}
-static jobject Posix_fstatfs(JNIEnv* env, jobject, jobject javaFd) {
+static jobject Posix_fstatvfs(JNIEnv* env, jobject, jobject javaFd) {
int fd = jniGetFDFromFileDescriptor(env, javaFd);
- struct statfs sb;
- int rc = TEMP_FAILURE_RETRY(fstatfs(fd, &sb));
+ struct statvfs sb;
+ int rc = TEMP_FAILURE_RETRY(fstatvfs(fd, &sb));
if (rc == -1) {
- throwErrnoException(env, "fstatfs");
+ throwErrnoException(env, "fstatvfs");
return NULL;
}
- return makeStructStatFs(env, sb);
+ return makeStructStatVfs(env, sb);
}
static void Posix_fsync(JNIEnv* env, jobject, jobject javaFd) {
@@ -1253,18 +1255,18 @@ static jobject Posix_stat(JNIEnv* env, jobject, jstring javaPath) {
return doStat(env, javaPath, false);
}
-static jobject Posix_statfs(JNIEnv* env, jobject, jstring javaPath) {
+static jobject Posix_statvfs(JNIEnv* env, jobject, jstring javaPath) {
ScopedUtfChars path(env, javaPath);
if (path.c_str() == NULL) {
return NULL;
}
- struct statfs sb;
- int rc = TEMP_FAILURE_RETRY(statfs(path.c_str(), &sb));
+ struct statvfs sb;
+ int rc = TEMP_FAILURE_RETRY(statvfs(path.c_str(), &sb));
if (rc == -1) {
- throwErrnoException(env, "statfs");
+ throwErrnoException(env, "statvfs");
return NULL;
}
- return makeStructStatFs(env, sb);
+ return makeStructStatVfs(env, sb);
}
static jstring Posix_strerror(JNIEnv* env, jobject, jint errnum) {
@@ -1377,7 +1379,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Posix, fcntlFlock, "(Ljava/io/FileDescriptor;ILlibcore/io/StructFlock;)I"),
NATIVE_METHOD(Posix, fdatasync, "(Ljava/io/FileDescriptor;)V"),
NATIVE_METHOD(Posix, fstat, "(Ljava/io/FileDescriptor;)Llibcore/io/StructStat;"),
- NATIVE_METHOD(Posix, fstatfs, "(Ljava/io/FileDescriptor;)Llibcore/io/StructStatFs;"),
+ NATIVE_METHOD(Posix, fstatvfs, "(Ljava/io/FileDescriptor;)Llibcore/io/StructStatVfs;"),
NATIVE_METHOD(Posix, fsync, "(Ljava/io/FileDescriptor;)V"),
NATIVE_METHOD(Posix, ftruncate, "(Ljava/io/FileDescriptor;J)V"),
NATIVE_METHOD(Posix, gai_strerror, "(I)Ljava/lang/String;"),
@@ -1446,7 +1448,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Posix, socket, "(III)Ljava/io/FileDescriptor;"),
NATIVE_METHOD(Posix, socketpair, "(IIILjava/io/FileDescriptor;Ljava/io/FileDescriptor;)V"),
NATIVE_METHOD(Posix, stat, "(Ljava/lang/String;)Llibcore/io/StructStat;"),
- NATIVE_METHOD(Posix, statfs, "(Ljava/lang/String;)Llibcore/io/StructStatFs;"),
+ NATIVE_METHOD(Posix, statvfs, "(Ljava/lang/String;)Llibcore/io/StructStatVfs;"),
NATIVE_METHOD(Posix, strerror, "(I)Ljava/lang/String;"),
NATIVE_METHOD(Posix, strsignal, "(I)Ljava/lang/String;"),
NATIVE_METHOD(Posix, symlink, "(Ljava/lang/String;Ljava/lang/String;)V"),