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