xref: /onnv-gate/usr/src/lib/libbc/libc/sys/common/_statfs.c (revision 722:636b850d4ee9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/vfs.h>
310Sstevel@tonic-gate #include <sys/syscall.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #define FSTYPSZ	16	/* array size for file system type name */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate struct statvfs {
360Sstevel@tonic-gate         u_long  f_bsize;        /* fundamental file system block size */
370Sstevel@tonic-gate         u_long  f_frsize;       /* fragment size */
380Sstevel@tonic-gate         u_long  f_blocks;       /* total # of blocks of f_frsize on fs */
390Sstevel@tonic-gate         u_long  f_bfree;        /* total # of free blocks of f_frsize */
400Sstevel@tonic-gate         u_long  f_bavail;       /* # of free blocks avail to non-superuser */
410Sstevel@tonic-gate         u_long  f_files;        /* total # of file nodes (inodes) */
420Sstevel@tonic-gate         u_long  f_ffree;        /* total # of free file nodes */
430Sstevel@tonic-gate         u_long  f_favail;       /* # of free nodes avail to non-superuser */
440Sstevel@tonic-gate         u_long  f_fsid;         /* file system id (dev for now) */
450Sstevel@tonic-gate         char    f_basetype[FSTYPSZ]; /* target fs type name, null-terminated */
460Sstevel@tonic-gate         u_long  f_flag;         /* bit-mask of flags */
470Sstevel@tonic-gate         u_long  f_namemax;      /* maximum file name length */
480Sstevel@tonic-gate         char    f_fstr[32];     /* filesystem-specific string */
490Sstevel@tonic-gate         u_long  f_filler[16];   /* reserved for future expansion */
500Sstevel@tonic-gate };
510Sstevel@tonic-gate 
52*722Smuffin void	cpstatvfs(struct statfs *, struct statvfs *);
530Sstevel@tonic-gate 
54*722Smuffin int
statfs_com(char * s,struct statfs * b)55*722Smuffin statfs_com(char *s, struct statfs *b)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate 	int    ret;
580Sstevel@tonic-gate 	struct statvfs vfsb;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	if ((ret = _syscall(SYS_statvfs, s, &vfsb)) == 0) {
610Sstevel@tonic-gate 		cpstatvfs(b, &vfsb);
620Sstevel@tonic-gate 	}
630Sstevel@tonic-gate 	return(ret);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate 
66*722Smuffin int
fstatfs(int fd,struct statfs * b)67*722Smuffin fstatfs(int fd, struct statfs *b)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate 	int    ret;
700Sstevel@tonic-gate 	struct statvfs vfsb;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	if ((ret = _syscall(SYS_fstatvfs,fd, &vfsb)) == 0) {
730Sstevel@tonic-gate 		cpstatvfs(b, &vfsb);
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate 	return(ret);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * Common code to copy vfs buf to BSD style buf
800Sstevel@tonic-gate  */
81*722Smuffin void
cpstatvfs(struct statfs * bsdbuf,struct statvfs * vbuf)82*722Smuffin cpstatvfs(struct statfs *bsdbuf, struct statvfs *vbuf)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate 	bsdbuf->f_type = (long) 0;  		/* type of info, zero for now */
850Sstevel@tonic-gate 	bsdbuf->f_bsize = (vbuf->f_frsize != 0) ?
860Sstevel@tonic-gate 	    (long) vbuf->f_frsize: (long) vbuf->f_bsize;
870Sstevel@tonic-gate 	bsdbuf->f_blocks = (long) vbuf->f_blocks;
880Sstevel@tonic-gate 	bsdbuf->f_bfree = (long) vbuf->f_bfree;
890Sstevel@tonic-gate 	bsdbuf->f_bavail = (long) vbuf->f_bavail;
900Sstevel@tonic-gate 	bsdbuf->f_files = (long) vbuf->f_files;
910Sstevel@tonic-gate 	bsdbuf->f_ffree = (long) vbuf->f_ffree;
920Sstevel@tonic-gate 	bsdbuf->f_fsid.val[0] = vbuf->f_fsid;
930Sstevel@tonic-gate 	bsdbuf->f_fsid.val[1] = 0;
940Sstevel@tonic-gate }
95