xref: /onnv-gate/usr/src/ucblib/libucb/port/gen/statfs.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
3*0Sstevel@tonic-gate 
4*0Sstevel@tonic-gate 
5*0Sstevel@tonic-gate /*
6*0Sstevel@tonic-gate  * Copyright (c) 1985 Regents of the University of California.
7*0Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
8*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * Copyright (c) 1988-1997, by Sun Microsystems, Inc.
13*0Sstevel@tonic-gate  * All Rights reserved.
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate /*LINTLIBRARY*/
19*0Sstevel@tonic-gate 
20*0Sstevel@tonic-gate #include <sys/types.h>
21*0Sstevel@tonic-gate #include <errno.h>
22*0Sstevel@tonic-gate #include <sys/statvfs.h>
23*0Sstevel@tonic-gate #include <sys/vfs.h>
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate #if !defined(_LP64)
26*0Sstevel@tonic-gate static void
cnvtvfs64(struct statfs64 * buf,struct statvfs64 * vbuf)27*0Sstevel@tonic-gate cnvtvfs64(struct statfs64 *buf, struct statvfs64 *vbuf)
28*0Sstevel@tonic-gate {
29*0Sstevel@tonic-gate 	buf->f_type = 0;
30*0Sstevel@tonic-gate 	buf->f_bsize = vbuf->f_frsize;
31*0Sstevel@tonic-gate 	buf->f_blocks = vbuf->f_blocks;
32*0Sstevel@tonic-gate 	buf->f_bfree = vbuf->f_bfree;
33*0Sstevel@tonic-gate 	buf->f_bavail = vbuf->f_bavail;
34*0Sstevel@tonic-gate 	buf->f_files = vbuf->f_files;
35*0Sstevel@tonic-gate 	buf->f_ffree = vbuf->f_ffree;
36*0Sstevel@tonic-gate 	buf->f_fsid.val[0] = vbuf->f_fsid;
37*0Sstevel@tonic-gate 	buf->f_fsid.val[1] = 0;
38*0Sstevel@tonic-gate }
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate int
statfs64(char * path,struct statfs64 * buf)41*0Sstevel@tonic-gate statfs64(char *path, struct statfs64 *buf)
42*0Sstevel@tonic-gate {
43*0Sstevel@tonic-gate 	int ret;
44*0Sstevel@tonic-gate 	struct statvfs64 vbuf;
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate 	if ((long)buf == -1L) {
47*0Sstevel@tonic-gate 		errno = EFAULT;
48*0Sstevel@tonic-gate 		return (-1);
49*0Sstevel@tonic-gate 	}
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate 	if ((ret = statvfs64(path, &vbuf)) != -1)
52*0Sstevel@tonic-gate 		cnvtvfs64(buf, &vbuf);
53*0Sstevel@tonic-gate 	return (ret);
54*0Sstevel@tonic-gate }
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate int
fstatfs64(int fd,struct statfs64 * buf)57*0Sstevel@tonic-gate fstatfs64(int fd, struct statfs64 *buf)
58*0Sstevel@tonic-gate {
59*0Sstevel@tonic-gate 	int ret;
60*0Sstevel@tonic-gate 	struct statvfs64 vbuf;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate 	if ((ret = fstatvfs64(fd, &vbuf)) != -1)
63*0Sstevel@tonic-gate 		cnvtvfs64(buf, &vbuf);
64*0Sstevel@tonic-gate 	return (ret);
65*0Sstevel@tonic-gate }
66*0Sstevel@tonic-gate #endif
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate static void
cnvtvfs(struct statfs * buf,struct statvfs * vbuf)69*0Sstevel@tonic-gate cnvtvfs(struct statfs *buf, struct statvfs *vbuf)
70*0Sstevel@tonic-gate {
71*0Sstevel@tonic-gate 	buf->f_type = 0;
72*0Sstevel@tonic-gate 	buf->f_bsize = vbuf->f_frsize;
73*0Sstevel@tonic-gate 	buf->f_blocks = vbuf->f_blocks;
74*0Sstevel@tonic-gate 	buf->f_bfree = vbuf->f_bfree;
75*0Sstevel@tonic-gate 	buf->f_bavail = vbuf->f_bavail;
76*0Sstevel@tonic-gate 	buf->f_files = vbuf->f_files;
77*0Sstevel@tonic-gate 	buf->f_ffree = vbuf->f_ffree;
78*0Sstevel@tonic-gate 	buf->f_fsid.val[0] = vbuf->f_fsid;
79*0Sstevel@tonic-gate 	buf->f_fsid.val[1] = 0;
80*0Sstevel@tonic-gate }
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate int
statfs(char * path,struct statfs * buf)83*0Sstevel@tonic-gate statfs(char *path, struct statfs *buf)
84*0Sstevel@tonic-gate {
85*0Sstevel@tonic-gate 	int ret;
86*0Sstevel@tonic-gate 	struct statvfs vbuf;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	if ((long)buf == -1L) {
89*0Sstevel@tonic-gate 		errno = EFAULT;
90*0Sstevel@tonic-gate 		return (-1);
91*0Sstevel@tonic-gate 	}
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	if ((ret = statvfs(path, &vbuf)) != -1)
94*0Sstevel@tonic-gate 		cnvtvfs(buf, &vbuf);
95*0Sstevel@tonic-gate 	return (ret);
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate int
fstatfs(int fd,struct statfs * buf)100*0Sstevel@tonic-gate fstatfs(int fd, struct statfs *buf)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	int ret;
103*0Sstevel@tonic-gate 	struct statvfs vbuf;
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 	if ((ret = fstatvfs(fd, &vbuf)) != -1)
106*0Sstevel@tonic-gate 		cnvtvfs(buf, &vbuf);
107*0Sstevel@tonic-gate 	return (ret);
108*0Sstevel@tonic-gate }
109