1 /* 2 * Copyright (c) 2014 Fujitsu Ltd. 3 * Author: Xiaoguang Wang <wangxg.fnst (at) 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" 27 #include "tst_fs.h" 28 29 int tst_fs_has_free_(void (*cleanup)(void), const char *path, 30 unsigned int size, unsigned int mult) 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 return 0; 38 } 39 40 if ((uint64_t)sf.f_bavail * sf.f_bsize >= (uint64_t)size * mult) 41 return 1; 42 43 return 0; 44 } 45