blob: 5c1037655f83815d78bf0b8cbd34502218012fa5 [file] [log] [blame]
Xiaoguang Wang46941672014-04-25 10:02:07 +08001/*
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 Hrubisbbdb9f72016-03-16 15:53:57 +010027#include "tst_fs.h"
Xiaoguang Wang46941672014-04-25 10:02:07 +080028
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010029int tst_fs_has_free_(void (*cleanup)(void), const char *path,
30 unsigned int size, unsigned int mult)
Xiaoguang Wang46941672014-04-25 10:02:07 +080031{
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 Hrubis707c68e2014-05-07 19:07:53 +020039 if ((uint64_t)sf.f_bavail * sf.f_bsize >= (uint64_t)size * mult)
Xiaoguang Wang46941672014-04-25 10:02:07 +080040 return 1;
41
42 return 0;
43}