diff options
Diffstat (limited to 'src/kernel/tests/lib/tst_fs_has_free.c')
-rw-r--r-- | src/kernel/tests/lib/tst_fs_has_free.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/kernel/tests/lib/tst_fs_has_free.c b/src/kernel/tests/lib/tst_fs_has_free.c new file mode 100644 index 0000000..e82dfa8 --- /dev/null +++ b/src/kernel/tests/lib/tst_fs_has_free.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014 Fujitsu Ltd. + * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * DESCRIPTION + * Check if the mounted file system has enough free space, + * if it is, tst_fs_has_free() returns 1, otherwise 0. + */ + +#include <stdint.h> +#include <sys/vfs.h> +#include "test.h" +#include "tst_fs.h" + +int tst_fs_has_free_(void (*cleanup)(void), const char *path, + unsigned int size, unsigned int mult) +{ + struct statfs sf; + + if (statfs(path, &sf)) { + tst_brkm(TBROK | TERRNO, cleanup, + "tst_fs_has_free: failed to statfs(%s)", path); + return 0; + } + + if ((uint64_t)sf.f_bavail * sf.f_bsize >= (uint64_t)size * mult) + return 1; + + return 0; +} |