Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Fujitsu Ltd. |
| 3 | * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * DESCRIPTION |
| 20 | * Check if the mounted file system has enough free space, |
| 21 | * if it is, tst_fs_has_free() returns 1, otherwise 0. |
| 22 | */ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <sys/vfs.h> |
| 26 | #include "test.h" |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 27 | #include "tst_fs.h" |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 28 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 29 | int tst_fs_has_free_(void (*cleanup)(void), const char *path, |
| 30 | unsigned int size, unsigned int mult) |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 31 | { |
| 32 | struct statfs sf; |
| 33 | |
| 34 | if (statfs(path, &sf)) { |
| 35 | tst_brkm(TBROK | TERRNO, cleanup, |
| 36 | "tst_fs_has_free: failed to statfs(%s)", path); |
| 37 | } |
| 38 | |
Cyril Hrubis | 707c68e | 2014-05-07 19:07:53 +0200 | [diff] [blame] | 39 | if ((uint64_t)sf.f_bavail * sf.f_bsize >= (uint64_t)size * mult) |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 40 | return 1; |
| 41 | |
| 42 | return 0; |
| 43 | } |