From b0d0fe3dc61c075ef2eaeba8adc03bb8ee0c4a38 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 21 Jul 2005 21:33:26 +0000 Subject: [PATCH] Add emulation of statvfs and fstatvfs based on statfs / fstatfs. --- lib/libc/include/libc_private.h | 7 +++- lib/libc/sys/Makefile.inc | 3 +- lib/libc/sys/__cvtstatvfs.c | 90 +++++++++++++++++++++++++++++++++++++++++ lib/libc/sys/fstatvfs.c | 53 ++++++++++++++++++++++++ lib/libc/sys/statvfs.c | 53 ++++++++++++++++++++++++ sys/sys/statvfs.h | 8 ++-- 6 files changed, 207 insertions(+), 7 deletions(-) create mode 100644 lib/libc/sys/__cvtstatvfs.c create mode 100644 lib/libc/sys/fstatvfs.c create mode 100644 lib/libc/sys/statvfs.c diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index 488bfa472f..c4f0219771 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/include/libc_private.h,v 1.3 1999/08/27 23:59:47 peter Exp $ - * $DragonFly: src/lib/libc/include/libc_private.h,v 1.6 2005/05/11 19:46:55 dillon Exp $ + * $DragonFly: src/lib/libc/include/libc_private.h,v 1.7 2005/07/21 21:33:26 joerg Exp $ * * Private definitions for libc, libc_r and libpthread. * @@ -78,4 +78,9 @@ int _fseeko(FILE *, __off_t, int); int __get_errno_GS_offset(void); void *__get_errno_GOT_ptr(void); +struct statfs; +struct statvfs; + +void __cvtstatvfs(const struct statfs *, struct statvfs *); + #endif /* _LIBC_PRIVATE_H_ */ diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 86bfe41257..a55c65c761 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,6 +1,6 @@ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # $FreeBSD: src/lib/libc/sys/Makefile.inc,v 1.75.2.7 2003/04/22 17:31:18 trhodes Exp $ -# $DragonFly: src/lib/libc/sys/Makefile.inc,v 1.14 2005/05/03 15:49:17 joerg Exp $ +# $DragonFly: src/lib/libc/sys/Makefile.inc,v 1.15 2005/07/21 21:33:26 joerg Exp $ # sys sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/sys ${.CURDIR}/../libc/sys @@ -18,6 +18,7 @@ # Sources common to both syscall interfaces: SRCS+= ftruncate.c lseek.c mmap.c pread.c pwrite.c truncate.c +SRCS+= __cvtstatvfs.c fstatvfs.c statvfs.c # Add machine dependent asm sources: SRCS+=${MDASM} diff --git a/lib/libc/sys/__cvtstatvfs.c b/lib/libc/sys/__cvtstatvfs.c new file mode 100644 index 0000000000..38e3903a70 --- /dev/null +++ b/lib/libc/sys/__cvtstatvfs.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Joerg Sonnenberger . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/lib/libc/sys/__cvtstatvfs.c,v 1.1 2005/07/21 21:33:26 joerg Exp $ + */ + +#include +#include +#include + +#include + +#include "libc_private.h" + +void +__cvtstatvfs(const struct statfs *in, struct statvfs *out) +{ + memset(out, 0, sizeof(*out)); + + out->f_bsize = in->f_bsize; + out->f_frsize = in->f_bsize; + out->f_blocks = in->f_blocks; + out->f_bfree = in->f_bfree; + out->f_bavail = in->f_bavail; + out->f_files = in->f_files; + out->f_ffree = in->f_ffree; + /* + * XXX + * This field counts the number of available inodes to non-root + * users, but this information is not available via statfs. + * Just ignore this issue by returning the totoal number instead. + */ + out->f_favail = in->f_ffree; + /* + * XXX + * This field has a different meaning for statfs and statvfs. + * For the former it is the cookie exported for NFS and not + * intended for normal userland use. + */ + out->f_fsid = 0; + + out->f_flag = 0; + if (in->f_flags & MNT_RDONLY) + out->f_flag |= ST_RDONLY; + if (in->f_flags & MNT_NOSUID) + out->f_flag |= ST_NOSUID; + out->f_namemax = 0; + out->f_owner = in->f_owner; + /* + * XXX + * statfs contains the type as string, statvfs expects it as + * enumeration. + */ + out->f_type = 0; + + out->f_syncreads = in->f_syncreads; + out->f_syncwrites = in->f_syncwrites; + out->f_asyncreads = in->f_asyncreads; + out->f_asyncwrites = in->f_asyncwrites; +} diff --git a/lib/libc/sys/fstatvfs.c b/lib/libc/sys/fstatvfs.c new file mode 100644 index 0000000000..d953efa847 --- /dev/null +++ b/lib/libc/sys/fstatvfs.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Joerg Sonnenberger . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/lib/libc/sys/fstatvfs.c,v 1.1 2005/07/21 21:33:26 joerg Exp $ + */ + +#include +#include +#include + +#include "libc_private.h" + +int +fstatvfs(int fd, struct statvfs *vfs) +{ + struct statfs sfs; + + if (fstatfs(fd, &sfs)) + return(-1); + + __cvtstatvfs(&sfs, vfs); + return(0); +} diff --git a/lib/libc/sys/statvfs.c b/lib/libc/sys/statvfs.c new file mode 100644 index 0000000000..b21e347762 --- /dev/null +++ b/lib/libc/sys/statvfs.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Joerg Sonnenberger . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/lib/libc/sys/statvfs.c,v 1.1 2005/07/21 21:33:26 joerg Exp $ + */ + +#include +#include +#include + +#include "libc_private.h" + +int +statvfs(const char * __restrict path, struct statvfs * __restrict vfs) +{ + struct statfs sfs; + + if (statfs(path, &sfs)) + return(-1); + + __cvtstatvfs(&sfs, vfs); + return(0); +} diff --git a/sys/sys/statvfs.h b/sys/sys/statvfs.h index 17296965e8..c12673ccb6 100644 --- a/sys/sys/statvfs.h +++ b/sys/sys/statvfs.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/statvfs.h,v 1.3 2005/06/05 12:16:53 joerg Exp $ + * $DragonFly: src/sys/sys/statvfs.h,v 1.4 2005/07/21 21:33:26 joerg Exp $ */ #ifndef _SYS_STATVFS_H_ @@ -48,7 +48,7 @@ struct statvfs { unsigned long f_bsize; /* file system block size */ - unsigned long f_frsize; /* fundamental file system */ + unsigned long f_frsize; /* fundamental file system block size */ fsblkcnt_t f_blocks; /* total number of blocks on fs */ fsblkcnt_t f_bfree; /* total number of free blocks */ fsblkcnt_t f_bavail; /* total number of available blocks */ @@ -74,9 +74,7 @@ struct statvfs { #define ST_RDONLY 0x1 /* fs is read-only */ #define ST_NOSUID 0x2 /* fs does not support ST_ISUID or ST_ISGID */ -#if 0 int fstatvfs(int, struct statvfs *); -int statvfs(const char *__restrict, struct statvfs *__restrict); -#endif +int statvfs(const char * __restrict, struct statvfs * __restrict); #endif /* _SYS_STATVFS_H_ */ -- 2.11.4.GIT