xref: /illumos-gate/usr/src/ucblib/libucb/port/gen/statfs.c (revision 8c0b080c8ed055a259d8cd26b9f005211c6a9753)
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 /*LINTLIBRARY*/
17 
18 #include <sys/types.h>
19 #include <errno.h>
20 #include <sys/statvfs.h>
21 #include <sys/vfs.h>
22 
23 #if !defined(_LP64)
24 static void
cnvtvfs64(struct statfs64 * buf,struct statvfs64 * vbuf)25 cnvtvfs64(struct statfs64 *buf, struct statvfs64 *vbuf)
26 {
27 	buf->f_type = 0;
28 	buf->f_bsize = vbuf->f_frsize;
29 	buf->f_blocks = vbuf->f_blocks;
30 	buf->f_bfree = vbuf->f_bfree;
31 	buf->f_bavail = vbuf->f_bavail;
32 	buf->f_files = vbuf->f_files;
33 	buf->f_ffree = vbuf->f_ffree;
34 	buf->f_fsid.val[0] = vbuf->f_fsid;
35 	buf->f_fsid.val[1] = 0;
36 }
37 
38 int
statfs64(char * path,struct statfs64 * buf)39 statfs64(char *path, struct statfs64 *buf)
40 {
41 	int ret;
42 	struct statvfs64 vbuf;
43 
44 	if ((long)buf == -1L) {
45 		errno = EFAULT;
46 		return (-1);
47 	}
48 
49 	if ((ret = statvfs64(path, &vbuf)) != -1)
50 		cnvtvfs64(buf, &vbuf);
51 	return (ret);
52 }
53 
54 int
fstatfs64(int fd,struct statfs64 * buf)55 fstatfs64(int fd, struct statfs64 *buf)
56 {
57 	int ret;
58 	struct statvfs64 vbuf;
59 
60 	if ((ret = fstatvfs64(fd, &vbuf)) != -1)
61 		cnvtvfs64(buf, &vbuf);
62 	return (ret);
63 }
64 #endif
65 
66 static void
cnvtvfs(struct statfs * buf,struct statvfs * vbuf)67 cnvtvfs(struct statfs *buf, struct statvfs *vbuf)
68 {
69 	buf->f_type = 0;
70 	buf->f_bsize = vbuf->f_frsize;
71 	buf->f_blocks = vbuf->f_blocks;
72 	buf->f_bfree = vbuf->f_bfree;
73 	buf->f_bavail = vbuf->f_bavail;
74 	buf->f_files = vbuf->f_files;
75 	buf->f_ffree = vbuf->f_ffree;
76 	buf->f_fsid.val[0] = vbuf->f_fsid;
77 	buf->f_fsid.val[1] = 0;
78 }
79 
80 int
statfs(char * path,struct statfs * buf)81 statfs(char *path, struct statfs *buf)
82 {
83 	int ret;
84 	struct statvfs vbuf;
85 
86 	if ((long)buf == -1L) {
87 		errno = EFAULT;
88 		return (-1);
89 	}
90 
91 	if ((ret = statvfs(path, &vbuf)) != -1)
92 		cnvtvfs(buf, &vbuf);
93 	return (ret);
94 }
95 
96 
97 int
fstatfs(int fd,struct statfs * buf)98 fstatfs(int fd, struct statfs *buf)
99 {
100 	int ret;
101 	struct statvfs vbuf;
102 
103 	if ((ret = fstatvfs(fd, &vbuf)) != -1)
104 		cnvtvfs(buf, &vbuf);
105 	return (ret);
106 }
107