summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2008-03-22 19:18:43 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2008-03-22 19:18:43 +0000
commit2068db5ce3fd5591f587c184b5e88f45b8f8328d (patch)
treeb3a8fbcd737e5223a58c00b81a87f0a10e9b7730 /lib/libc/gen
parent8a3788f16668826aaed4f977cbcb571dcdcb1d02 (diff)
move statvfs.c to gen, since it is not a syscall; ok deraadt@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/Makefile.inc15
-rw-r--r--lib/libc/gen/statvfs.c69
2 files changed, 77 insertions, 7 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index af58fcf77c2..8db506298ff 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.39 2005/10/03 10:57:16 jmc Exp $
+# $OpenBSD: Makefile.inc,v 1.40 2008/03/22 19:18:42 otto Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen ${LIBCSRCDIR}/gen
@@ -16,8 +16,8 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \
raise.c readdir.c readpassphrase.c rewinddir.c scandir.c \
seekdir.c setdomainname.c sethostname.c setjmperr.c setmode.c \
setproctitle.c siginterrupt.c siglist.c signal.c signame.c \
- sigsetops.c sleep.c strtofflags.c sysconf.c sysctl.c syslog.c \
- telldir.c time.c times.c timezone.c tolower_.c ttyname.c \
+ sigsetops.c sleep.c statvfs.c strtofflags.c sysconf.c sysctl.c \
+ syslog.c telldir.c time.c times.c timezone.c tolower_.c ttyname.c \
ttyslot.c toupper_.c ualarm.c uname.c unvis.c usleep.c \
utime.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c \
warnx.c vwarn.c vwarnx.c verr.c verrx.c
@@ -55,10 +55,10 @@ MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \
isprint.3 ispunct.3 isspace.3 isupper.3 isxdigit.3 ldexp.3 lockf.3 \
login_cap.3 modf.3 nice.3 nlist.3 pause.3 popen.3 psignal.3 pw_dup.3 \
pwcache.3 raise.3 readpassphrase.3 scandir.3 setjmp.3 setmode.3 \
- setproctitle.3 siginterrupt.3 signal.3 sigsetops.3 sleep.3 sysconf.3 \
- sysctl.3 strtofflags.3 syslog.3 time.3 times.3 timezone.3 toascii.3 \
- tolower.3 toupper.3 ttyname.3 ualarm.3 uname.3 unvis.3 usleep.3 \
- utime.3 valloc.3 vis.3
+ setproctitle.3 siginterrupt.3 signal.3 sigsetops.3 sleep.3 statvfs.3 \
+ sysconf.3 sysctl.3 strtofflags.3 syslog.3 time.3 times.3 timezone.3 \
+ toascii.3 tolower.3 toupper.3 ttyname.3 ualarm.3 uname.3 unvis.3 \
+ usleep.3 utime.3 valloc.3 vis.3
MLINKS+=auth_subr.3 auth_open.3 auth_subr.3 auth_call.3 auth_subr.3 \
auth_challenge.3 auth_subr.3 auth_check_change.3 auth_subr.3 \
@@ -123,6 +123,7 @@ MLINKS+=setmode.3 getmode.3
MLINKS+=sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \
sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \
sigsetops.3 sigismember.3
+MLINKS+=statvfs.3 fstatvfs.3
MLINKS+=strtofflags.3 fflagstostr.3
MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \
syslog.3 vsyslog.3 syslog.3 syslog_r.3 syslog.3 closelog_r.3 \
diff --git a/lib/libc/gen/statvfs.c b/lib/libc/gen/statvfs.c
new file mode 100644
index 00000000000..f4f7807b3cf
--- /dev/null
+++ b/lib/libc/gen/statvfs.c
@@ -0,0 +1,69 @@
+/* $OpenBSD: statvfs.c,v 1.1 2008/03/22 19:18:42 otto Exp $ */
+
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/statvfs.h>
+
+static void
+cvt_statfs_to_statvfs(const struct statfs *fsp, struct statvfs *vfsp)
+{
+ vfsp->f_bsize = fsp->f_iosize; /* XXX */
+ vfsp->f_frsize = fsp->f_bsize; /* XXX */
+
+ vfsp->f_blocks = fsp->f_blocks;
+ vfsp->f_bfree = fsp->f_bfree;
+ vfsp->f_bavail = fsp->f_bavail < 0 ? 0 : fsp->f_bavail;
+
+ vfsp->f_files = fsp->f_files;
+ vfsp->f_ffree = fsp->f_ffree;
+ vfsp->f_favail = fsp->f_favail < 0 ? 0 : fsp->f_favail;
+
+ vfsp->f_fsid = fsp->f_fsid.val[0]; /* XXX */
+ vfsp->f_flag = 0;
+ if (fsp->f_flags & MNT_RDONLY)
+ vfsp->f_flag |= ST_RDONLY;
+ if (fsp->f_flags & MNT_NOSUID)
+ vfsp->f_flag |= ST_NOSUID;
+ vfsp->f_namemax = fsp->f_namemax;
+}
+
+int
+fstatvfs(int fd, struct statvfs *p)
+{
+ struct statfs sb;
+ int ret;
+
+ ret = fstatfs(fd, &sb);
+ if (ret == 0)
+ cvt_statfs_to_statvfs(&sb, p);
+ return (ret);
+}
+
+int
+statvfs(const char *path, struct statvfs *p)
+{
+ struct statfs sb;
+ int ret;
+
+ ret = statfs(path, &sb);
+ if (ret == 0)
+ cvt_statfs_to_statvfs(&sb, p);
+ return (ret);
+}
+