1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <sys/types.h>
30 #include <sys/vfs.h>
31 #include <sys/syscall.h>
32
33 #define FSTYPSZ 16 /* array size for file system type name */
34
35 struct statvfs {
36 u_long f_bsize; /* fundamental file system block size */
37 u_long f_frsize; /* fragment size */
38 u_long f_blocks; /* total # of blocks of f_frsize on fs */
39 u_long f_bfree; /* total # of free blocks of f_frsize */
40 u_long f_bavail; /* # of free blocks avail to non-superuser */
41 u_long f_files; /* total # of file nodes (inodes) */
42 u_long f_ffree; /* total # of free file nodes */
43 u_long f_favail; /* # of free nodes avail to non-superuser */
44 u_long f_fsid; /* file system id (dev for now) */
45 char f_basetype[FSTYPSZ]; /* target fs type name, null-terminated */
46 u_long f_flag; /* bit-mask of flags */
47 u_long f_namemax; /* maximum file name length */
48 char f_fstr[32]; /* filesystem-specific string */
49 u_long f_filler[16]; /* reserved for future expansion */
50 };
51
52 void cpstatvfs(struct statfs *, struct statvfs *);
53
54 int
statfs_com(char * s,struct statfs * b)55 statfs_com(char *s, struct statfs *b)
56 {
57 int ret;
58 struct statvfs vfsb;
59
60 if ((ret = _syscall(SYS_statvfs, s, &vfsb)) == 0) {
61 cpstatvfs(b, &vfsb);
62 }
63 return(ret);
64 }
65
66 int
fstatfs(int fd,struct statfs * b)67 fstatfs(int fd, struct statfs *b)
68 {
69 int ret;
70 struct statvfs vfsb;
71
72 if ((ret = _syscall(SYS_fstatvfs,fd, &vfsb)) == 0) {
73 cpstatvfs(b, &vfsb);
74 }
75 return(ret);
76 }
77
78 /*
79 * Common code to copy vfs buf to BSD style buf
80 */
81 void
cpstatvfs(struct statfs * bsdbuf,struct statvfs * vbuf)82 cpstatvfs(struct statfs *bsdbuf, struct statvfs *vbuf)
83 {
84 bsdbuf->f_type = (long) 0; /* type of info, zero for now */
85 bsdbuf->f_bsize = (vbuf->f_frsize != 0) ?
86 (long) vbuf->f_frsize: (long) vbuf->f_bsize;
87 bsdbuf->f_blocks = (long) vbuf->f_blocks;
88 bsdbuf->f_bfree = (long) vbuf->f_bfree;
89 bsdbuf->f_bavail = (long) vbuf->f_bavail;
90 bsdbuf->f_files = (long) vbuf->f_files;
91 bsdbuf->f_ffree = (long) vbuf->f_ffree;
92 bsdbuf->f_fsid.val[0] = vbuf->f_fsid;
93 bsdbuf->f_fsid.val[1] = 0;
94 }
95