2 * Copyright 2002 Massachusetts Institute of Technology
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include "namespace.h"
34 #include <sys/param.h>
35 #include <sys/mount.h>
36 #include <sys/statvfs.h>
41 #include "un-namespace.h"
43 static int sfs2svfs(const struct statfs *from, struct statvfs *to);
46 fstatvfs(int fd, struct statvfs *result)
52 rv = _fstatfs(fd, &sfs);
56 rv = sfs2svfs(&sfs, result);
61 * Whether pathconf's -1 return means error or unlimited does not
62 * make any difference in this best-effort implementation.
64 pcval = _fpathconf(fd, _PC_NAME_MAX);
66 result->f_namemax = ~0UL;
68 result->f_namemax = (unsigned long)pcval;
73 statvfs(const char * __restrict path, struct statvfs * __restrict result)
79 rv = statfs(path, &sfs);
83 sfs2svfs(&sfs, result);
86 * Whether pathconf's -1 return means error or unlimited does not
87 * make any difference in this best-effort implementation.
89 pcval = pathconf(path, _PC_NAME_MAX);
91 result->f_namemax = ~0UL;
93 result->f_namemax = (unsigned long)pcval;
98 sfs2svfs(const struct statfs *from, struct statvfs *to)
100 static const struct statvfs zvfs;
104 if (from->f_flags & MNT_RDONLY)
105 to->f_flag |= ST_RDONLY;
106 if (from->f_flags & MNT_NOSUID)
107 to->f_flag |= ST_NOSUID;
109 /* XXX should we clamp negative values? */
110 #define COPY(field) \
112 to->field = from->field; \
113 if (from->field != to->field) { \
124 to->f_bsize = from->f_iosize;
125 to->f_frsize = from->f_bsize;
126 to->f_favail = to->f_ffree;
136 main(int argc, char **argv)
140 if (statvfs(argv[1], &buf) < 0)
143 #define SHOW(field) \
144 printf(#field ": %ju\n", (uintmax_t)buf.field)
155 printf("f_flag: %lx\n", (unsigned long)buf.f_flag);