bionic/setlocale.cpp \
bionic/signalfd.cpp \
bionic/sigwait.cpp \
+ bionic/statvfs.cpp \
bionic/__strcat_chk.cpp \
bionic/__strchr_chk.cpp \
bionic/__strcpy_chk.cpp \
--- /dev/null
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <sys/statvfs.h>
+
+#include <sys/statfs.h>
+
+extern "C" int __statfs64(const char*, size_t, struct statfs*);
+extern "C" int __fstatfs64(int, size_t, struct statfs*);
+
+#define ST_VALID 0x0020
+
+static void __statfs_to_statvfs(const struct statfs& in, struct statvfs* out) {
+ out->f_bsize = in.f_bsize;
+ out->f_frsize = in.f_frsize;
+ out->f_blocks = in.f_blocks;
+ out->f_bfree = in.f_bfree;
+ out->f_bavail = in.f_bavail;
+ out->f_files = in.f_files;
+ out->f_ffree = in.f_ffree;
+ out->f_favail = in.f_ffree;
+ out->f_fsid = in.f_fsid.__val[0] | (static_cast<uint64_t>(in.f_fsid.__val[1]) << 32);
+ out->f_flag = in.f_flags & ~ST_VALID;
+ out->f_namemax = in.f_namelen;
+}
+
+int statvfs(const char* path, struct statvfs* result) {
+ struct statfs tmp;
+ int rc = __statfs64(path, sizeof(tmp), &tmp);
+ if (rc != 0) {
+ return rc;
+ }
+ __statfs_to_statvfs(tmp, result);
+ return 0;
+}
+
+int fstatvfs(int fd, struct statvfs* result) {
+ struct statfs tmp;
+ int rc = __fstatfs64(fd, sizeof(tmp), &tmp);
+ if (rc != 0) {
+ return rc;
+ }
+ __statfs_to_statvfs(tmp, result);
+ return 0;
+}
#define __statement(x) (x)
#endif
-#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __attribute__((__nonnull__(x)))
-#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __attribute__((__nonnull__(x)))
+#define __nonnull(args) __attribute__((__nonnull__ args))
+
+#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
+#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
/*
* C99 defines the restrict type qualifier keyword, which was made available
__BEGIN_DECLS
-extern int signalfd(int fd, const sigset_t* mask, int flags) __attribute__((__nonnull__(2)));
+extern int signalfd(int fd, const sigset_t* mask, int flags) __nonnull((2));
__END_DECLS
--- /dev/null
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef _SYS_STATVFS_H_
+#define _SYS_STATVFS_H_
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+struct statvfs {
+ unsigned long f_bsize;
+ unsigned long f_frsize;
+ fsblkcnt_t f_blocks;
+ fsblkcnt_t f_bfree;
+ fsblkcnt_t f_bavail;
+ fsfilcnt_t f_files;
+ fsfilcnt_t f_ffree;
+ fsfilcnt_t f_favail;
+ unsigned long f_fsid;
+ unsigned long f_flag;
+ unsigned long f_namemax;
+};
+
+#define ST_RDONLY 0x0001
+#define ST_NOSUID 0x0002
+#define ST_NODEV 0x0004
+#define ST_NOEXEC 0x0008
+#define ST_SYNCHRONOUS 0x0010
+#define ST_MANDLOCK 0x0040
+#define ST_NOATIME 0x0400
+#define ST_NODIRATIME 0x0800
+#define ST_RELATIME 0x1000
+
+extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2));
+extern int fstatvfs(int, struct statvfs*) __nonnull((2));
+
+__END_DECLS
+
+#endif /* _SYS_STATVFS_H_ */
__BEGIN_DECLS
-extern int swapon(const char *, int) __attribute__((__nonnull__(1)));
-extern int swapoff(const char *) __attribute__((__nonnull__(1)));
+extern int swapon(const char*, int) __nonnull((1));
+extern int swapoff(const char*) __nonnull((1));
__END_DECLS
__BEGIN_DECLS
-/* note: this corresponds to the kernel's statfs64 type */
+/* These correspond to the kernel's statfs64 type. */
#ifdef __mips__
struct statfs {
uint32_t f_type;
uint64_t f_bavail;
__kernel_fsid_t f_fsid;
uint32_t f_namelen;
- uint32_t f_spare[6];
+ uint32_t f_flags;
+ uint32_t f_spare[5];
};
#else
struct statfs {
__kernel_fsid_t f_fsid;
uint32_t f_namelen;
uint32_t f_frsize;
- uint32_t f_spare[5];
+ uint32_t f_flags;
+ uint32_t f_spare[4];
};
#endif
signal_test.cpp \
stack_protector_test.cpp \
stack_unwinding_test.cpp \
+ statvfs_test.cpp \
stdio_test.cpp \
stdlib_test.cpp \
string_test.cpp \
--- /dev/null
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <sys/statvfs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+TEST(statvfs, statvfs) {
+ struct statvfs sb;
+ memset(&sb, 0, sizeof(sb));
+
+ ASSERT_EQ(0, statvfs("/", &sb));
+#if __BIONIC__
+ ASSERT_EQ(0U, sb.f_bfree);
+ ASSERT_EQ(0U, sb.f_ffree);
+ ASSERT_EQ(0U, sb.f_fsid);
+ ASSERT_TRUE((sb.f_flag & ST_RDONLY) != 0);
+#endif
+
+#if __BIONIC__
+ ASSERT_EQ(0, statvfs("/data/data", &sb));
+ ASSERT_NE(0U, sb.f_bfree);
+ ASSERT_NE(0U, sb.f_ffree);
+ ASSERT_NE(0U, sb.f_fsid);
+ ASSERT_FALSE((sb.f_flag & ST_RDONLY) != 0);
+ ASSERT_TRUE((sb.f_flag & ST_NOSUID) != 0);
+#endif
+}
+
+TEST(statvfs, fstatvfs) {
+ struct statvfs sb;
+ memset(&sb, 0, sizeof(sb));
+
+ int fd = open("/", O_RDONLY);
+ ASSERT_EQ(0, fstatvfs(fd, &sb));
+ close(fd);
+#if __BIONIC__
+ ASSERT_EQ(0U, sb.f_bfree);
+ ASSERT_EQ(0U, sb.f_ffree);
+ ASSERT_EQ(0U, sb.f_fsid);
+ ASSERT_TRUE((sb.f_flag & ST_RDONLY) != 0);
+#endif
+
+#if __BIONIC__
+ fd = open("/data/data", O_RDONLY);
+ ASSERT_EQ(0, fstatvfs(fd, &sb));
+ close(fd);
+ ASSERT_NE(0U, sb.f_bfree);
+ ASSERT_NE(0U, sb.f_ffree);
+ ASSERT_NE(0U, sb.f_fsid);
+ ASSERT_FALSE((sb.f_flag & ST_RDONLY) != 0);
+ ASSERT_TRUE((sb.f_flag & ST_NOSUID) != 0);
+#endif
+}