From: Elliott Hughes Date: Tue, 9 Jul 2013 20:25:03 +0000 (-0700) Subject: Add . X-Git-Tag: android-x86-4.4-r1~19^2~37^2^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=06040fd75c1edff9e5ffb2b3d3e2a6e66d57c11d;p=android-x86%2Fbionic.git Add . Bug: 2512019 Change-Id: I6e7fd3fa281977cc4bc270481a95416b5b2dc351 --- diff --git a/libc/Android.mk b/libc/Android.mk index eba0a00f0..16b24de8b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -225,6 +225,7 @@ libc_bionic_src_files := \ bionic/setlocale.cpp \ bionic/signalfd.cpp \ bionic/sigwait.cpp \ + bionic/statvfs.cpp \ bionic/__strcat_chk.cpp \ bionic/__strchr_chk.cpp \ bionic/__strcpy_chk.cpp \ diff --git a/libc/bionic/statvfs.cpp b/libc/bionic/statvfs.cpp new file mode 100644 index 000000000..5d5828149 --- /dev/null +++ b/libc/bionic/statvfs.cpp @@ -0,0 +1,58 @@ +/* + * 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 + +#include + +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(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; +} diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index c7fb9de25..a4c1afff1 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -211,8 +211,10 @@ #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 diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h index a249d658f..2537ab96c 100644 --- a/libc/include/sys/signalfd.h +++ b/libc/include/sys/signalfd.h @@ -35,7 +35,7 @@ __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 diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h new file mode 100644 index 000000000..e910c0310 --- /dev/null +++ b/libc/include/sys/statvfs.h @@ -0,0 +1,55 @@ +/* + * 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 +#include +#include + +__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_ */ diff --git a/libc/include/sys/swap.h b/libc/include/sys/swap.h index 85627f94d..97a6f3605 100644 --- a/libc/include/sys/swap.h +++ b/libc/include/sys/swap.h @@ -33,8 +33,8 @@ __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 diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h index d14944dc9..6a55c9927 100644 --- a/libc/include/sys/vfs.h +++ b/libc/include/sys/vfs.h @@ -34,7 +34,7 @@ __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; @@ -48,7 +48,8 @@ struct statfs { 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 { @@ -62,7 +63,8 @@ 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 diff --git a/tests/Android.mk b/tests/Android.mk index 34aaec933..efee17bca 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -74,6 +74,7 @@ test_src_files = \ signal_test.cpp \ stack_protector_test.cpp \ stack_unwinding_test.cpp \ + statvfs_test.cpp \ stdio_test.cpp \ stdlib_test.cpp \ string_test.cpp \ diff --git a/tests/statvfs_test.cpp b/tests/statvfs_test.cpp new file mode 100644 index 000000000..8afc6fd20 --- /dev/null +++ b/tests/statvfs_test.cpp @@ -0,0 +1,71 @@ +/* + * 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 + +#include + +#include +#include +#include + +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 +}