GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/gen/statvfs.c Lines: 0 25 0.0 %
Date: 2017-11-07 Branches: 0 12 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: statvfs.c,v 1.2 2015/01/16 16:48:51 deraadt Exp $	*/
2
3
/*
4
 * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 */
18
19
#include <sys/types.h>
20
#include <sys/mount.h>
21
#include <sys/statvfs.h>
22
23
static void
24
cvt_statfs_to_statvfs(const struct statfs *fsp, struct statvfs *vfsp)
25
{
26
	vfsp->f_bsize = fsp->f_iosize; /* XXX */
27
	vfsp->f_frsize = fsp->f_bsize; /* XXX */
28
29
	vfsp->f_blocks = fsp->f_blocks;
30
	vfsp->f_bfree = fsp->f_bfree;
31
	vfsp->f_bavail = fsp->f_bavail < 0 ? 0 : fsp->f_bavail;
32
33
	vfsp->f_files = fsp->f_files;
34
	vfsp->f_ffree = fsp->f_ffree;
35
	vfsp->f_favail = fsp->f_favail < 0 ? 0 : fsp->f_favail;
36
37
	vfsp->f_fsid = fsp->f_fsid.val[0]; /* XXX */
38
	vfsp->f_flag = 0;
39
	if (fsp->f_flags & MNT_RDONLY)
40
		vfsp->f_flag |= ST_RDONLY;
41
	if (fsp->f_flags & MNT_NOSUID)
42
		vfsp->f_flag |= ST_NOSUID;
43
	vfsp->f_namemax = fsp->f_namemax;
44
}
45
46
int
47
fstatvfs(int fd, struct statvfs *p)
48
{
49
	struct statfs sb;
50
	int ret;
51
52
	ret = fstatfs(fd, &sb);
53
	if (ret == 0)
54
		cvt_statfs_to_statvfs(&sb, p);
55
	return (ret);
56
}
57
58
int
59
statvfs(const char *path, struct statvfs *p)
60
{
61
	struct statfs sb;
62
	int ret;
63
64
	ret = statfs(path, &sb);
65
	if (ret == 0)
66
		cvt_statfs_to_statvfs(&sb, p);
67
	return (ret);
68
}
69