1 /* $Id: bsd-statvfs.c,v 1.2 2014/01/17 07:10:59 dtucker Exp $ */
4 * Copyright (c) 2008,2014 Darren Tucker <dtucker@zip.com.au>
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.
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 MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #if !defined(HAVE_STATVFS) || !defined(HAVE_FSTATVFS)
23 #include <sys/param.h>
24 #ifdef HAVE_SYS_MOUNT_H
25 # include <sys/mount.h>
31 copy_statfs_to_statvfs(struct statvfs *to, struct statfs *from)
33 to->f_bsize = from->f_bsize;
34 to->f_frsize = from->f_bsize; /* no exact equivalent */
35 to->f_blocks = from->f_blocks;
36 to->f_bfree = from->f_bfree;
37 to->f_bavail = from->f_bavail;
38 to->f_files = from->f_files;
39 to->f_ffree = from->f_ffree;
40 to->f_favail = from->f_ffree; /* no exact equivalent */
41 to->f_fsid = 0; /* XXX fix me */
42 to->f_flag = from->f_flags;
43 to->f_namemax = MNAMELEN;
47 int statvfs(const char *path, struct statvfs *buf)
52 memset(&fs, 0, sizeof(fs));
53 if (statfs(path, &fs) == -1)
55 copy_statfs_to_statvfs(buf, &fs);
64 # ifndef HAVE_FSTATVFS
65 int fstatvfs(int fd, struct statvfs *buf)
70 memset(&fs, 0, sizeof(fs));
71 if (fstatfs(fd, &fs) == -1)
73 copy_statfs_to_statvfs(buf, &fs);