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 (c) 1998-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include <sys/isa_defs.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include <sys/statvfs.h>
34 #include <sys/sysmacros.h>
35 #include "libproc.h"
36 
37 #ifdef _LP64
38 static void
statvfs_32_to_n(statvfs32_t * src,statvfs_t * dest)39 statvfs_32_to_n(statvfs32_t *src, statvfs_t *dest)
40 {
41 	dest->f_bsize = src->f_bsize;
42 	dest->f_frsize = src->f_frsize;
43 	dest->f_blocks = src->f_blocks;
44 	dest->f_bfree = src->f_bfree;
45 	dest->f_bavail = src->f_bavail;
46 	dest->f_files = src->f_files;
47 	dest->f_ffree = src->f_ffree;
48 	dest->f_favail = src->f_favail;
49 	dest->f_fsid = src->f_fsid;
50 	(void) memcpy(dest->f_basetype, src->f_basetype,
51 		sizeof (dest->f_basetype));
52 	dest->f_flag = src->f_flag;
53 	dest->f_namemax = src->f_namemax;
54 	(void) memcpy(dest->f_fstr, src->f_fstr,
55 		sizeof (dest->f_fstr));
56 }
57 #endif	/* _LP64 */
58 
59 /*
60  * statvfs() system call -- executed by subject process
61  */
62 int
pr_statvfs(struct ps_prochandle * Pr,const char * path,statvfs_t * buf)63 pr_statvfs(struct ps_prochandle *Pr, const char *path, statvfs_t *buf)
64 {
65 	sysret_t rval;			/* return value from statvfs() */
66 	argdes_t argd[2];		/* arg descriptors for statvfs() */
67 	argdes_t *adp = &argd[0];	/* first argument */
68 	int error;
69 #ifdef _LP64
70 	statvfs32_t statvfs32;
71 #endif	/* _LP64 */
72 
73 	if (Pr == NULL)		/* no subject process */
74 		return (statvfs(path, buf));
75 
76 	adp->arg_value = 0;
77 	adp->arg_object = (void *)path;
78 	adp->arg_type = AT_BYREF;
79 	adp->arg_inout = AI_INPUT;
80 	adp->arg_size = strlen(path)+1;
81 	adp++;			/* move to buffer argument */
82 
83 	adp->arg_value = 0;
84 	adp->arg_type = AT_BYREF;
85 	adp->arg_inout = AI_OUTPUT;
86 #ifdef _LP64
87 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
88 		adp->arg_object = &statvfs32;
89 		adp->arg_size = sizeof (statvfs32);
90 	} else {
91 		adp->arg_object = buf;
92 		adp->arg_size = sizeof (*buf);
93 	}
94 #else	/* _LP64 */
95 	adp->arg_object = buf;
96 	adp->arg_size = sizeof (*buf);
97 #endif	/* _LP64 */
98 
99 	error = Psyscall(Pr, &rval, SYS_statvfs, 2, &argd[0]);
100 
101 	if (error) {
102 		errno = (error > 0)? error : ENOSYS;
103 		return (-1);
104 	}
105 #ifdef _LP64
106 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
107 		statvfs_32_to_n(&statvfs32, buf);
108 #endif	/* _LP64 */
109 	return (0);
110 }
111 
112 /*
113  * fstatvfs() system call -- executed by subject process
114  */
115 int
pr_fstatvfs(struct ps_prochandle * Pr,int fd,statvfs_t * buf)116 pr_fstatvfs(struct ps_prochandle *Pr, int fd, statvfs_t *buf)
117 {
118 	sysret_t rval;			/* return value from fstatvfs() */
119 	argdes_t argd[2];		/* arg descriptors for fstatvfs() */
120 	argdes_t *adp = &argd[0];	/* first argument */
121 	int error;
122 #ifdef _LP64
123 	statvfs32_t statvfs32;
124 #endif	/* _LP64 */
125 
126 	if (Pr == NULL)		/* no subject process */
127 		return (fstatvfs(fd, buf));
128 
129 	adp->arg_value = fd;
130 	adp->arg_object = NULL;
131 	adp->arg_type = AT_BYVAL;
132 	adp->arg_inout = AI_INPUT;
133 	adp->arg_size = 0;
134 	adp++;			/* move to buffer argument */
135 
136 	adp->arg_value = 0;
137 	adp->arg_type = AT_BYREF;
138 	adp->arg_inout = AI_OUTPUT;
139 #ifdef _LP64
140 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
141 		adp->arg_object = &statvfs32;
142 		adp->arg_size = sizeof (statvfs32);
143 	} else {
144 		adp->arg_object = buf;
145 		adp->arg_size = sizeof (*buf);
146 	}
147 #else	/* _LP64 */
148 	adp->arg_object = buf;
149 	adp->arg_size = sizeof (*buf);
150 #endif	/* _LP64 */
151 
152 	error = Psyscall(Pr, &rval, SYS_fstatvfs, 2, &argd[0]);
153 
154 	if (error) {
155 		errno = (error > 0)? error : ENOSYS;
156 		return (-1);
157 	}
158 #ifdef _LP64
159 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
160 		statvfs_32_to_n(&statvfs32, buf);
161 #endif	/* _LP64 */
162 	return (0);
163 }
164