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 "namespace.h"
31 #include <sys/param.h>
32 #include <sys/mount.h>
33 #include <sys/statvfs.h>
38 #include "un-namespace.h"
40 static int sfs2svfs(const struct statfs *from, struct statvfs *to);
43 fstatvfs(int fd, struct statvfs *result)
49 rv = _fstatfs(fd, &sfs);
53 rv = sfs2svfs(&sfs, result);
58 * Whether pathconf's -1 return means error or unlimited does not
59 * make any difference in this best-effort implementation.
61 pcval = _fpathconf(fd, _PC_NAME_MAX);
63 result->f_namemax = ~0UL;
65 result->f_namemax = (unsigned long)pcval;
70 statvfs(const char * __restrict path, struct statvfs * __restrict result)
76 rv = statfs(path, &sfs);
80 sfs2svfs(&sfs, result);
83 * Whether pathconf's -1 return means error or unlimited does not
84 * make any difference in this best-effort implementation.
86 pcval = pathconf(path, _PC_NAME_MAX);
88 result->f_namemax = ~0UL;
90 result->f_namemax = (unsigned long)pcval;
95 sfs2svfs(const struct statfs *from, struct statvfs *to)
97 static const struct statvfs zvfs;
101 if (from->f_flags & MNT_RDONLY)
102 to->f_flag |= ST_RDONLY;
103 if (from->f_flags & MNT_NOSUID)
104 to->f_flag |= ST_NOSUID;
106 /* XXX should we clamp negative values? */
107 #define COPY(field) \
109 to->field = from->field; \
110 if (from->field != to->field) { \
121 to->f_bsize = from->f_iosize;
122 to->f_frsize = from->f_bsize;
123 to->f_favail = to->f_ffree;
133 main(int argc, char **argv)
137 if (statvfs(argv[1], &buf) < 0)
140 #define SHOW(field) \
141 printf(#field ": %ju\n", (uintmax_t)buf.field)
152 printf("f_flag: %lx\n", (unsigned long)buf.f_flag);