summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-statvfs.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2014-01-17 18:10:58 +1100
committerDarren Tucker <dtucker@zip.com.au>2014-01-17 18:10:58 +1100
commita5cf1e220def07290260e4125e74f41ac75cf88d (patch)
tree990b73a34c1f425de38cccf83e2aa386ec7a6af1 /openbsd-compat/bsd-statvfs.c
parent1357d71d7b6d269969520aaa3e84d312ec971d5b (diff)
- (dtucker) [configure.ac openbsd-compat/bsd-statvfs.c
openbsd-compat/bsd-statvfs.h] Implement enough of statvfs on top of statfs to be useful (and for the regression tests to pass) on platforms that have statfs and fstatfs. ok djm@
Diffstat (limited to 'openbsd-compat/bsd-statvfs.c')
-rw-r--r--openbsd-compat/bsd-statvfs.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/openbsd-compat/bsd-statvfs.c b/openbsd-compat/bsd-statvfs.c
index 844d5b464..2b1da80ec 100644
--- a/openbsd-compat/bsd-statvfs.c
+++ b/openbsd-compat/bsd-statvfs.c
@@ -1,7 +1,7 @@
1/* $Id: bsd-statvfs.c,v 1.1 2008/06/08 17:32:29 dtucker Exp $ */ 1/* $Id: bsd-statvfs.c,v 1.2 2014/01/17 07:10:59 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 Darren Tucker <dtucker@zip.com.au> 4 * Copyright (c) 2008,2014 Darren Tucker <dtucker@zip.com.au>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 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 7 * purpose with or without fee is hereby granted, provided that the above
@@ -18,20 +18,65 @@
18 18
19#include "includes.h" 19#include "includes.h"
20 20
21#if !defined(HAVE_STATVFS) || !defined(HAVE_FSTATVFS)
22
23#include <sys/param.h>
24#ifdef HAVE_SYS_MOUNT_H
25# include <sys/mount.h>
26#endif
27
21#include <errno.h> 28#include <errno.h>
22 29
23#ifndef HAVE_STATVFS 30static void
31copy_statfs_to_statvfs(struct statvfs *to, struct statfs *from)
32{
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;
44}
45
46# ifndef HAVE_STATVFS
24int statvfs(const char *path, struct statvfs *buf) 47int statvfs(const char *path, struct statvfs *buf)
25{ 48{
49# ifdef HAVE_STATFS
50 struct statfs fs;
51
52 memset(&fs, 0, sizeof(fs));
53 if (statfs(path, &fs) == -1)
54 return -1;
55 copy_statfs_to_statvfs(buf, &fs);
56 return 0;
57# else
26 errno = ENOSYS; 58 errno = ENOSYS;
27 return -1; 59 return -1;
60# endif
28} 61}
29#endif 62# endif
30 63
31#ifndef HAVE_FSTATVFS 64# ifndef HAVE_FSTATVFS
32int fstatvfs(int fd, struct statvfs *buf) 65int fstatvfs(int fd, struct statvfs *buf)
33{ 66{
67# ifdef HAVE_FSTATFS
68 struct statfs fs;
69
70 memset(&fs, 0, sizeof(fs));
71 if (fstatfs(fd, &fs) == -1)
72 return -1;
73 copy_statfs_to_statvfs(buf, &fs);
74 return 0;
75# else
34 errno = ENOSYS; 76 errno = ENOSYS;
35 return -1; 77 return -1;
78# endif
36} 79}
80# endif
81
37#endif 82#endif