diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/sys/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/sys/statvfs.c | 68 |
2 files changed, 70 insertions, 2 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 338c7d525e4..87c98516d2e 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.83 2008/01/05 02:11:44 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.84 2008/03/16 19:44:34 otto Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -27,7 +27,7 @@ DPSRCS+= Lint_Ovfork.c Lint_brk.c Lint_exect.c Lint_fork.c \ # with old syscall interfaces. SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \ timer_create.c timer_delete.c timer_getoverrun.c timer_gettime.c \ - timer_settime.c pread.c preadv.c pwrite.c pwritev.c + timer_settime.c pread.c preadv.c pwrite.c pwritev.c statvfs.c # stack protector helper functions SRCS+= stack_protector.c diff --git a/lib/libc/sys/statvfs.c b/lib/libc/sys/statvfs.c new file mode 100644 index 00000000000..71bbccd2146 --- /dev/null +++ b/lib/libc/sys/statvfs.c @@ -0,0 +1,68 @@ +/* $OpenBSD: statvfs.c,v 1.1 2008/03/16 19:44:34 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); +} + |