xref: /titanic_44/usr/src/cmd/fs.d/cachefs/cfsd/cfsd_kmod.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Source file for the cfsd_kmod class.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <stddef.h>
36*7c478bd9Sstevel@tonic-gate #include <string.h>
37*7c478bd9Sstevel@tonic-gate #include <errno.h>
38*7c478bd9Sstevel@tonic-gate #include <unistd.h>
39*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/cred.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h>
49*7c478bd9Sstevel@tonic-gate #include <mdbug/mdbug.h>
50*7c478bd9Sstevel@tonic-gate #include "cfsd.h"
51*7c478bd9Sstevel@tonic-gate #include "cfsd_kmod.h"
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * copy_cred (copy dl_cred_t followed by a list of gid_t)
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate static void
copy_cred(dl_cred_t * dst,const dl_cred_t * src)58*7c478bd9Sstevel@tonic-gate copy_cred(dl_cred_t *dst, const dl_cred_t *src)
59*7c478bd9Sstevel@tonic-gate {
60*7c478bd9Sstevel@tonic-gate 	int n = src->cr_ngroups;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 	if (n > NGROUPS_MAX_DEFAULT)
63*7c478bd9Sstevel@tonic-gate 		n = NGROUPS_MAX_DEFAULT;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	(void) memcpy(dst, src, sizeof (*dst) + (n - 1) * sizeof (gid_t));
66*7c478bd9Sstevel@tonic-gate 	dst->cr_ngroups = n;
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
71*7c478bd9Sstevel@tonic-gate  *			cfsd_kmod_create
72*7c478bd9Sstevel@tonic-gate  *
73*7c478bd9Sstevel@tonic-gate  * Description:
74*7c478bd9Sstevel@tonic-gate  * Arguments:
75*7c478bd9Sstevel@tonic-gate  * Returns:
76*7c478bd9Sstevel@tonic-gate  * Preconditions:
77*7c478bd9Sstevel@tonic-gate  */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate cfsd_kmod_object_t *
cfsd_kmod_create(void)80*7c478bd9Sstevel@tonic-gate cfsd_kmod_create(void)
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	cfsd_kmod_object_t *kmod_object_p;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	dbug_enter("cfsd_kmod_create");
85*7c478bd9Sstevel@tonic-gate 	kmod_object_p = cfsd_calloc(sizeof (cfsd_kmod_object_t));
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 	kmod_object_p->i_fd = -1;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	dbug_leave("cfsd_kmod_create");
90*7c478bd9Sstevel@tonic-gate 	return (kmod_object_p);
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /*
94*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
95*7c478bd9Sstevel@tonic-gate  *			cfsd_kmod_destory
96*7c478bd9Sstevel@tonic-gate  *
97*7c478bd9Sstevel@tonic-gate  * Description:
98*7c478bd9Sstevel@tonic-gate  * Arguments:
99*7c478bd9Sstevel@tonic-gate  * Returns:
100*7c478bd9Sstevel@tonic-gate  * Preconditions:
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate void
cfsd_kmod_destroy(cfsd_kmod_object_t * kmod_object_p)105*7c478bd9Sstevel@tonic-gate cfsd_kmod_destroy(cfsd_kmod_object_t *kmod_object_p)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate 	dbug_enter("cfsd_kmod_destroy");
108*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	/* clean up old stuff */
111*7c478bd9Sstevel@tonic-gate 	kmod_shutdown(kmod_object_p);
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	cfsd_free(kmod_object_p);
114*7c478bd9Sstevel@tonic-gate 	dbug_leave("cfsd_kmod_destroy");
115*7c478bd9Sstevel@tonic-gate }
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
119*7c478bd9Sstevel@tonic-gate  *			kmod_setup
120*7c478bd9Sstevel@tonic-gate  *
121*7c478bd9Sstevel@tonic-gate  * Description:
122*7c478bd9Sstevel@tonic-gate  * Arguments:
123*7c478bd9Sstevel@tonic-gate  *	path
124*7c478bd9Sstevel@tonic-gate  * Returns:
125*7c478bd9Sstevel@tonic-gate  *	Returns ...
126*7c478bd9Sstevel@tonic-gate  * Preconditions:
127*7c478bd9Sstevel@tonic-gate  *	precond(path)
128*7c478bd9Sstevel@tonic-gate  */
129*7c478bd9Sstevel@tonic-gate int
kmod_setup(cfsd_kmod_object_t * kmod_object_p,const char * path)130*7c478bd9Sstevel@tonic-gate kmod_setup(cfsd_kmod_object_t *kmod_object_p, const char *path)
131*7c478bd9Sstevel@tonic-gate {
132*7c478bd9Sstevel@tonic-gate 	int xx;
133*7c478bd9Sstevel@tonic-gate 	int error;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_setup");
136*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
137*7c478bd9Sstevel@tonic-gate 	dbug_precond(path);
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	/* clean up old stuff */
140*7c478bd9Sstevel@tonic-gate 	kmod_shutdown(kmod_object_p);
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	/* try to open the file */
143*7c478bd9Sstevel@tonic-gate 	dbug_assert(kmod_object_p->i_fd == -1);
144*7c478bd9Sstevel@tonic-gate 	kmod_object_p->i_fd = open(path, O_RDONLY);
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	/* return result */
147*7c478bd9Sstevel@tonic-gate 	if (kmod_object_p->i_fd == -1) {
148*7c478bd9Sstevel@tonic-gate 		xx = errno;
149*7c478bd9Sstevel@tonic-gate 		dbug_print(("err", "open of %s failed %d", path, xx));
150*7c478bd9Sstevel@tonic-gate 	} else {
151*7c478bd9Sstevel@tonic-gate 		xx = 0;
152*7c478bd9Sstevel@tonic-gate 		strlcpy(kmod_object_p->i_path, path,
153*7c478bd9Sstevel@tonic-gate 		    sizeof (kmod_object_p->i_path));
154*7c478bd9Sstevel@tonic-gate 		dbug_print(("info", "opened %s on fd %d", path,
155*7c478bd9Sstevel@tonic-gate 		    kmod_object_p->i_fd));
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 		/* tell the cachefs kmod we are here */
158*7c478bd9Sstevel@tonic-gate 		xx = kmod_doioctl(kmod_object_p, CFSDCMD_DAEMONID,
159*7c478bd9Sstevel@tonic-gate 		    NULL, 0, NULL, 0);
160*7c478bd9Sstevel@tonic-gate 		if (xx) {
161*7c478bd9Sstevel@tonic-gate 			error = errno;
162*7c478bd9Sstevel@tonic-gate 			dbug_print(("ioctl", "daemonid error %d", error));
163*7c478bd9Sstevel@tonic-gate 		}
164*7c478bd9Sstevel@tonic-gate 	}
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_setup");
167*7c478bd9Sstevel@tonic-gate 	return (xx);
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  *			kmod_shutdown
172*7c478bd9Sstevel@tonic-gate  *
173*7c478bd9Sstevel@tonic-gate  * Description:
174*7c478bd9Sstevel@tonic-gate  * Arguments:
175*7c478bd9Sstevel@tonic-gate  * Returns:
176*7c478bd9Sstevel@tonic-gate  * Preconditions:
177*7c478bd9Sstevel@tonic-gate  */
178*7c478bd9Sstevel@tonic-gate void
kmod_shutdown(cfsd_kmod_object_t * kmod_object_p)179*7c478bd9Sstevel@tonic-gate kmod_shutdown(cfsd_kmod_object_t *kmod_object_p)
180*7c478bd9Sstevel@tonic-gate {
181*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_shutdown");
182*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate 	/* close down the old fd if necessary */
185*7c478bd9Sstevel@tonic-gate 	if (kmod_object_p->i_fd >= 0) {
186*7c478bd9Sstevel@tonic-gate 		if (close(kmod_object_p->i_fd))
187*7c478bd9Sstevel@tonic-gate 			dbug_print(("err", "cannot close kmod fd, %d", errno));
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate 	kmod_object_p->i_fd = -1;
190*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_shutdown");
191*7c478bd9Sstevel@tonic-gate }
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate /*
194*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
195*7c478bd9Sstevel@tonic-gate  *			kmod_xwait
196*7c478bd9Sstevel@tonic-gate  *
197*7c478bd9Sstevel@tonic-gate  * Description:
198*7c478bd9Sstevel@tonic-gate  * Arguments:
199*7c478bd9Sstevel@tonic-gate  * Returns:
200*7c478bd9Sstevel@tonic-gate  *	Returns ...
201*7c478bd9Sstevel@tonic-gate  * Preconditions:
202*7c478bd9Sstevel@tonic-gate  */
203*7c478bd9Sstevel@tonic-gate int
kmod_xwait(cfsd_kmod_object_t * kmod_object_p)204*7c478bd9Sstevel@tonic-gate kmod_xwait(cfsd_kmod_object_t *kmod_object_p)
205*7c478bd9Sstevel@tonic-gate {
206*7c478bd9Sstevel@tonic-gate 	int xx;
207*7c478bd9Sstevel@tonic-gate 	int error = 0;
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_xwait");
210*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_XWAIT, NULL, 0, NULL, 0);
213*7c478bd9Sstevel@tonic-gate 	if (xx)
214*7c478bd9Sstevel@tonic-gate 		error = errno;
215*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
216*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_xwait");
217*7c478bd9Sstevel@tonic-gate 	return (error);
218*7c478bd9Sstevel@tonic-gate }
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate /*
221*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
222*7c478bd9Sstevel@tonic-gate  *			kmod_stateget
223*7c478bd9Sstevel@tonic-gate  *
224*7c478bd9Sstevel@tonic-gate  * Description:
225*7c478bd9Sstevel@tonic-gate  * Arguments:
226*7c478bd9Sstevel@tonic-gate  * Returns:
227*7c478bd9Sstevel@tonic-gate  *	Returns ...
228*7c478bd9Sstevel@tonic-gate  * Preconditions:
229*7c478bd9Sstevel@tonic-gate  */
230*7c478bd9Sstevel@tonic-gate int
kmod_stateget(cfsd_kmod_object_t * kmod_object_p)231*7c478bd9Sstevel@tonic-gate kmod_stateget(cfsd_kmod_object_t *kmod_object_p)
232*7c478bd9Sstevel@tonic-gate {
233*7c478bd9Sstevel@tonic-gate 	int state;
234*7c478bd9Sstevel@tonic-gate 	int xx;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_stateget");
237*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_STATEGET, NULL, 0, &state,
240*7c478bd9Sstevel@tonic-gate 	    sizeof (state));
241*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, state %d", xx, state));
242*7c478bd9Sstevel@tonic-gate 	if (xx == -1) {
243*7c478bd9Sstevel@tonic-gate 		/* XXX do what? */
244*7c478bd9Sstevel@tonic-gate 		dbug_assert(0);
245*7c478bd9Sstevel@tonic-gate 	}
246*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_stateget");
247*7c478bd9Sstevel@tonic-gate 	return (state);
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate /*
251*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
252*7c478bd9Sstevel@tonic-gate  *			kmod_stateset
253*7c478bd9Sstevel@tonic-gate  *
254*7c478bd9Sstevel@tonic-gate  * Description:
255*7c478bd9Sstevel@tonic-gate  * Arguments:
256*7c478bd9Sstevel@tonic-gate  *	state
257*7c478bd9Sstevel@tonic-gate  * Returns:
258*7c478bd9Sstevel@tonic-gate  *	Returns ...
259*7c478bd9Sstevel@tonic-gate  * Preconditions:
260*7c478bd9Sstevel@tonic-gate  */
261*7c478bd9Sstevel@tonic-gate int
kmod_stateset(cfsd_kmod_object_t * kmod_object_p,int state)262*7c478bd9Sstevel@tonic-gate kmod_stateset(cfsd_kmod_object_t *kmod_object_p, int state)
263*7c478bd9Sstevel@tonic-gate {
264*7c478bd9Sstevel@tonic-gate 	int xx;
265*7c478bd9Sstevel@tonic-gate 	int error = 0;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_stateset");
268*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_STATESET, &state,
271*7c478bd9Sstevel@tonic-gate 	    sizeof (state), NULL, 0);
272*7c478bd9Sstevel@tonic-gate 	if (xx)
273*7c478bd9Sstevel@tonic-gate 		error = errno;
274*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, state set to %d", xx, state));
275*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_stateset");
276*7c478bd9Sstevel@tonic-gate 	return (error);
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate /*
280*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
281*7c478bd9Sstevel@tonic-gate  *			kmod_exists
282*7c478bd9Sstevel@tonic-gate  *
283*7c478bd9Sstevel@tonic-gate  * Description:
284*7c478bd9Sstevel@tonic-gate  * Arguments:
285*7c478bd9Sstevel@tonic-gate  *	cidp
286*7c478bd9Sstevel@tonic-gate  * Returns:
287*7c478bd9Sstevel@tonic-gate  *	Returns ...
288*7c478bd9Sstevel@tonic-gate  * Preconditions:
289*7c478bd9Sstevel@tonic-gate  *	precond(cidp)
290*7c478bd9Sstevel@tonic-gate  */
291*7c478bd9Sstevel@tonic-gate int
kmod_exists(cfsd_kmod_object_t * kmod_object_p,cfs_cid_t * cidp)292*7c478bd9Sstevel@tonic-gate kmod_exists(cfsd_kmod_object_t *kmod_object_p, cfs_cid_t *cidp)
293*7c478bd9Sstevel@tonic-gate {
294*7c478bd9Sstevel@tonic-gate 	int xx;
295*7c478bd9Sstevel@tonic-gate 	int error = 0;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_exists");
298*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
299*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_EXISTS, cidp,
302*7c478bd9Sstevel@tonic-gate 	    sizeof (cfs_cid_t), NULL, 0);
303*7c478bd9Sstevel@tonic-gate 	if (xx)
304*7c478bd9Sstevel@tonic-gate 		error = errno;
305*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
306*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   cid %08x", cidp->cid_fileno));
307*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_exists");
308*7c478bd9Sstevel@tonic-gate 	return (error);
309*7c478bd9Sstevel@tonic-gate }
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate /*
312*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
313*7c478bd9Sstevel@tonic-gate  *			kmod_lostfound
314*7c478bd9Sstevel@tonic-gate  *
315*7c478bd9Sstevel@tonic-gate  * Description:
316*7c478bd9Sstevel@tonic-gate  * Arguments:
317*7c478bd9Sstevel@tonic-gate  *	cidp
318*7c478bd9Sstevel@tonic-gate  * Returns:
319*7c478bd9Sstevel@tonic-gate  *	Returns ...
320*7c478bd9Sstevel@tonic-gate  * Preconditions:
321*7c478bd9Sstevel@tonic-gate  *	precond(cidp)
322*7c478bd9Sstevel@tonic-gate  */
323*7c478bd9Sstevel@tonic-gate int
kmod_lostfound(cfsd_kmod_object_t * kmod_object_p,cfs_cid_t * cidp,const char * namep,char * newnamep)324*7c478bd9Sstevel@tonic-gate kmod_lostfound(cfsd_kmod_object_t *kmod_object_p, cfs_cid_t *cidp,
325*7c478bd9Sstevel@tonic-gate 	const char *namep, char *newnamep)
326*7c478bd9Sstevel@tonic-gate {
327*7c478bd9Sstevel@tonic-gate 	cachefsio_lostfound_arg_t info;
328*7c478bd9Sstevel@tonic-gate 	cachefsio_lostfound_return_t ret;
329*7c478bd9Sstevel@tonic-gate 	int error = 0;
330*7c478bd9Sstevel@tonic-gate 	int xx;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_lostfound");
333*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
334*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
335*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
336*7c478bd9Sstevel@tonic-gate 	dbug_precond(newnamep);
337*7c478bd9Sstevel@tonic-gate 	dbug_precond(strlen(namep) < (size_t)MAXNAMELEN);
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 	info.lf_cid = *cidp;
340*7c478bd9Sstevel@tonic-gate 	strlcpy(info.lf_name, namep, sizeof (info.lf_name));
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_LOSTFOUND, &info,
343*7c478bd9Sstevel@tonic-gate 	    sizeof (info), &ret, sizeof (ret));
344*7c478bd9Sstevel@tonic-gate 	if (xx)
345*7c478bd9Sstevel@tonic-gate 		error = errno;
346*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
347*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   cid %08x", cidp->cid_fileno));
348*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   suggested name '%s'", namep));
349*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
350*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   new name '%s'", ret.lf_name));
351*7c478bd9Sstevel@tonic-gate 		dbug_assert(strlen(ret.lf_name) < (size_t)MAXNAMELEN);
352*7c478bd9Sstevel@tonic-gate 		if (newnamep)
353*7c478bd9Sstevel@tonic-gate 			strlcpy(newnamep, ret.lf_name, MAXNAMELEN);
354*7c478bd9Sstevel@tonic-gate 	}
355*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_lostfound");
356*7c478bd9Sstevel@tonic-gate 	return (error);
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate #if 0
360*7c478bd9Sstevel@tonic-gate /*
361*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
362*7c478bd9Sstevel@tonic-gate  *			kmod_lostfoundall
363*7c478bd9Sstevel@tonic-gate  *
364*7c478bd9Sstevel@tonic-gate  * Description:
365*7c478bd9Sstevel@tonic-gate  * Arguments:
366*7c478bd9Sstevel@tonic-gate  * Returns:
367*7c478bd9Sstevel@tonic-gate  *	Returns ...
368*7c478bd9Sstevel@tonic-gate  * Preconditions:
369*7c478bd9Sstevel@tonic-gate  */
370*7c478bd9Sstevel@tonic-gate int
371*7c478bd9Sstevel@tonic-gate kmod_lostfoundall(cfsd_kmod_object_t *kmod_object_p)
372*7c478bd9Sstevel@tonic-gate {
373*7c478bd9Sstevel@tonic-gate 	int error = 0;
374*7c478bd9Sstevel@tonic-gate 	int xx = -1;
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_lostfoundall");
377*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate 	/* xx = ioctl(kmod_object_p->i_fd, CACHEFSIO_LOSTFOUNDALL, 0); */
380*7c478bd9Sstevel@tonic-gate 	if (xx)
381*7c478bd9Sstevel@tonic-gate 		error = errno;
382*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
383*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_lostfoundall");
384*7c478bd9Sstevel@tonic-gate 	return (error);
385*7c478bd9Sstevel@tonic-gate }
386*7c478bd9Sstevel@tonic-gate /*
387*7c478bd9Sstevel@tonic-gate  *			kmod_rofs
388*7c478bd9Sstevel@tonic-gate  *
389*7c478bd9Sstevel@tonic-gate  * Description:
390*7c478bd9Sstevel@tonic-gate  * Arguments:
391*7c478bd9Sstevel@tonic-gate  * Returns:
392*7c478bd9Sstevel@tonic-gate  *	Returns ...
393*7c478bd9Sstevel@tonic-gate  * Preconditions:
394*7c478bd9Sstevel@tonic-gate  */
395*7c478bd9Sstevel@tonic-gate int
396*7c478bd9Sstevel@tonic-gate kmod_rofs(cfsd_kmod_object_t *kmod_object_p)
397*7c478bd9Sstevel@tonic-gate {
398*7c478bd9Sstevel@tonic-gate 	int error = 0;
399*7c478bd9Sstevel@tonic-gate 	int xx = -1;
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_rofs");
402*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	/* xx = ioctl(kmod_object_p->i_fd, CACHEFSIO_ROFS, 0); */
405*7c478bd9Sstevel@tonic-gate 	if (xx)
406*7c478bd9Sstevel@tonic-gate 		error = errno;
407*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
408*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_rofs");
409*7c478bd9Sstevel@tonic-gate 	return (error);
410*7c478bd9Sstevel@tonic-gate }
411*7c478bd9Sstevel@tonic-gate #endif
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate /*
414*7c478bd9Sstevel@tonic-gate  *			kmod_rootfid
415*7c478bd9Sstevel@tonic-gate  *
416*7c478bd9Sstevel@tonic-gate  * Description:
417*7c478bd9Sstevel@tonic-gate  *	Fills in fidp with the fid of the root of the file system.
418*7c478bd9Sstevel@tonic-gate  * Arguments:
419*7c478bd9Sstevel@tonic-gate  *	fidp
420*7c478bd9Sstevel@tonic-gate  * Returns:
421*7c478bd9Sstevel@tonic-gate  *	Returns 0 for success, errno value for an error
422*7c478bd9Sstevel@tonic-gate  * Preconditions:
423*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
424*7c478bd9Sstevel@tonic-gate  */
425*7c478bd9Sstevel@tonic-gate int
kmod_rootfid(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * fidp)426*7c478bd9Sstevel@tonic-gate kmod_rootfid(cfsd_kmod_object_t *kmod_object_p, cfs_fid_t *fidp)
427*7c478bd9Sstevel@tonic-gate {
428*7c478bd9Sstevel@tonic-gate 	int error = 0;
429*7c478bd9Sstevel@tonic-gate 	int xx;
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_rootfid");
432*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
433*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_ROOTFID, NULL, 0, fidp,
436*7c478bd9Sstevel@tonic-gate 	    sizeof (*fidp));
437*7c478bd9Sstevel@tonic-gate 	if (xx)
438*7c478bd9Sstevel@tonic-gate 		error = errno;
439*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
440*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_rootfid");
441*7c478bd9Sstevel@tonic-gate 	return (error);
442*7c478bd9Sstevel@tonic-gate }
443*7c478bd9Sstevel@tonic-gate 
444*7c478bd9Sstevel@tonic-gate 
445*7c478bd9Sstevel@tonic-gate /*
446*7c478bd9Sstevel@tonic-gate  *			kmod_getstats
447*7c478bd9Sstevel@tonic-gate  *
448*7c478bd9Sstevel@tonic-gate  * Description:
449*7c478bd9Sstevel@tonic-gate  * Arguments:
450*7c478bd9Sstevel@tonic-gate  *	gsp
451*7c478bd9Sstevel@tonic-gate  * Returns:
452*7c478bd9Sstevel@tonic-gate  *	Returns ...
453*7c478bd9Sstevel@tonic-gate  * Preconditions:
454*7c478bd9Sstevel@tonic-gate  *	precond(gsp)
455*7c478bd9Sstevel@tonic-gate  */
456*7c478bd9Sstevel@tonic-gate int
kmod_getstats(cfsd_kmod_object_t * kmod_object_p,cachefsio_getstats_t * gsp)457*7c478bd9Sstevel@tonic-gate kmod_getstats(cfsd_kmod_object_t *kmod_object_p, cachefsio_getstats_t *gsp)
458*7c478bd9Sstevel@tonic-gate {
459*7c478bd9Sstevel@tonic-gate 	int error = 0;
460*7c478bd9Sstevel@tonic-gate 	int xx;
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_getstats");
463*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 	dbug_precond(gsp);
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_GETSTATS, NULL, 0, gsp,
468*7c478bd9Sstevel@tonic-gate 	    sizeof (*gsp));
469*7c478bd9Sstevel@tonic-gate 	if (xx)
470*7c478bd9Sstevel@tonic-gate 		error = errno;
471*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
472*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "total blocks %d", gsp->gs_total));
473*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "gc blocks %d", gsp->gs_gc));
474*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "active blocks %d", gsp->gs_active));
475*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "packed blocks %d", gsp->gs_packed));
476*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "free blocks %d", gsp->gs_free));
477*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "gctime %x", gsp->gs_gctime));
478*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_getstats");
479*7c478bd9Sstevel@tonic-gate 	return (error);
480*7c478bd9Sstevel@tonic-gate }
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate /*
483*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
484*7c478bd9Sstevel@tonic-gate  *			kmod_getinfo
485*7c478bd9Sstevel@tonic-gate  *
486*7c478bd9Sstevel@tonic-gate  * Description:
487*7c478bd9Sstevel@tonic-gate  * Arguments:
488*7c478bd9Sstevel@tonic-gate  *	filep
489*7c478bd9Sstevel@tonic-gate  * Returns:
490*7c478bd9Sstevel@tonic-gate  *	Returns ...
491*7c478bd9Sstevel@tonic-gate  * Preconditions:
492*7c478bd9Sstevel@tonic-gate  *	precond(filep)
493*7c478bd9Sstevel@tonic-gate  *	precond(infop)
494*7c478bd9Sstevel@tonic-gate  */
495*7c478bd9Sstevel@tonic-gate int
kmod_getinfo(cfsd_kmod_object_t * kmod_object_p,cfs_cid_t * filep,cachefsio_getinfo_t * infop)496*7c478bd9Sstevel@tonic-gate kmod_getinfo(cfsd_kmod_object_t *kmod_object_p, cfs_cid_t *filep,
497*7c478bd9Sstevel@tonic-gate 	cachefsio_getinfo_t *infop)
498*7c478bd9Sstevel@tonic-gate {
499*7c478bd9Sstevel@tonic-gate 	int error = 0;
500*7c478bd9Sstevel@tonic-gate 	int xx;
501*7c478bd9Sstevel@tonic-gate 
502*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_getinfo");
503*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
504*7c478bd9Sstevel@tonic-gate 
505*7c478bd9Sstevel@tonic-gate 	dbug_precond(filep);
506*7c478bd9Sstevel@tonic-gate 	dbug_precond(infop);
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_GETINFO, filep,
509*7c478bd9Sstevel@tonic-gate 	    sizeof (*filep), infop, sizeof (*infop));
510*7c478bd9Sstevel@tonic-gate 	if (xx)
511*7c478bd9Sstevel@tonic-gate 		error = errno;
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
514*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   file cid %08x", filep->cid_fileno));
515*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
516*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   modified %d  seq %d",
517*7c478bd9Sstevel@tonic-gate 		    infop->gi_modified, infop->gi_seq));
518*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   name \"%s\"", infop->gi_name));
519*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   parent cid %08x",
520*7c478bd9Sstevel@tonic-gate 		    infop->gi_pcid.cid_fileno));
521*7c478bd9Sstevel@tonic-gate 		infop->gi_attr.va_mask = AT_ALL;
522*7c478bd9Sstevel@tonic-gate 		kmod_print_attr(&infop->gi_attr);
523*7c478bd9Sstevel@tonic-gate 	}
524*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_getinfo");
525*7c478bd9Sstevel@tonic-gate 	return (error);
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate /*
529*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
530*7c478bd9Sstevel@tonic-gate  *			kmod_cidtofid
531*7c478bd9Sstevel@tonic-gate  *
532*7c478bd9Sstevel@tonic-gate  * Description:
533*7c478bd9Sstevel@tonic-gate  * Arguments:
534*7c478bd9Sstevel@tonic-gate  *	cidp
535*7c478bd9Sstevel@tonic-gate  *	fidp
536*7c478bd9Sstevel@tonic-gate  * Returns:
537*7c478bd9Sstevel@tonic-gate  *	Returns ...
538*7c478bd9Sstevel@tonic-gate  * Preconditions:
539*7c478bd9Sstevel@tonic-gate  *	precond(cidp)
540*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
541*7c478bd9Sstevel@tonic-gate  */
542*7c478bd9Sstevel@tonic-gate int
kmod_cidtofid(cfsd_kmod_object_t * kmod_object_p,cfs_cid_t * cidp,cfs_fid_t * fidp)543*7c478bd9Sstevel@tonic-gate kmod_cidtofid(cfsd_kmod_object_t *kmod_object_p, cfs_cid_t *cidp,
544*7c478bd9Sstevel@tonic-gate 		cfs_fid_t *fidp)
545*7c478bd9Sstevel@tonic-gate {
546*7c478bd9Sstevel@tonic-gate 	int error = 0;
547*7c478bd9Sstevel@tonic-gate 	int xx;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_cidtofid");
550*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
551*7c478bd9Sstevel@tonic-gate 
552*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
553*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_CIDTOFID, cidp, sizeof (*cidp),
556*7c478bd9Sstevel@tonic-gate 	    fidp, sizeof (*fidp));
557*7c478bd9Sstevel@tonic-gate 	if (xx)
558*7c478bd9Sstevel@tonic-gate 		error = errno;
559*7c478bd9Sstevel@tonic-gate 
560*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
561*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   cid %08x", cidp->cid_fileno));
562*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
563*7c478bd9Sstevel@tonic-gate 		kmod_format_fid(kmod_object_p, fidp);
564*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   fid \"%s\"", kmod_object_p->i_fidbuf));
565*7c478bd9Sstevel@tonic-gate 	}
566*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_cidtofid");
567*7c478bd9Sstevel@tonic-gate 	return (error);
568*7c478bd9Sstevel@tonic-gate }
569*7c478bd9Sstevel@tonic-gate 
570*7c478bd9Sstevel@tonic-gate /*
571*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
572*7c478bd9Sstevel@tonic-gate  *			kmod_getattrfid
573*7c478bd9Sstevel@tonic-gate  *
574*7c478bd9Sstevel@tonic-gate  * Description:
575*7c478bd9Sstevel@tonic-gate  * Arguments:
576*7c478bd9Sstevel@tonic-gate  *	fidp
577*7c478bd9Sstevel@tonic-gate  *	credp
578*7c478bd9Sstevel@tonic-gate  *	vattrp
579*7c478bd9Sstevel@tonic-gate  * Returns:
580*7c478bd9Sstevel@tonic-gate  *	Returns ...
581*7c478bd9Sstevel@tonic-gate  * Preconditions:
582*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
583*7c478bd9Sstevel@tonic-gate  *	precond(credp)
584*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
585*7c478bd9Sstevel@tonic-gate  */
586*7c478bd9Sstevel@tonic-gate int
kmod_getattrfid(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * fidp,dl_cred_t * credp,vattr_t * vattrp)587*7c478bd9Sstevel@tonic-gate kmod_getattrfid(cfsd_kmod_object_t *kmod_object_p, cfs_fid_t *fidp,
588*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp, vattr_t *vattrp)
589*7c478bd9Sstevel@tonic-gate {
590*7c478bd9Sstevel@tonic-gate 	int error = 0;
591*7c478bd9Sstevel@tonic-gate 	int xx;
592*7c478bd9Sstevel@tonic-gate 	cachefsio_getattrfid_t info;
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_getattrfid");
595*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
598*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
599*7c478bd9Sstevel@tonic-gate 	dbug_precond(vattrp);
600*7c478bd9Sstevel@tonic-gate 
601*7c478bd9Sstevel@tonic-gate 	info.cg_backfid = *fidp;
602*7c478bd9Sstevel@tonic-gate 
603*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.cg_cred, credp);
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_GETATTRFID, &info,
606*7c478bd9Sstevel@tonic-gate 	    sizeof (info), vattrp, sizeof (*vattrp));
607*7c478bd9Sstevel@tonic-gate 	if (xx)
608*7c478bd9Sstevel@tonic-gate 		error = errno;
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
611*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, fidp);
612*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   fid \"%s\"", kmod_object_p->i_fidbuf));
613*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
614*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
615*7c478bd9Sstevel@tonic-gate 		vattrp->va_mask = AT_ALL;
616*7c478bd9Sstevel@tonic-gate 		kmod_print_attr(vattrp);
617*7c478bd9Sstevel@tonic-gate 	}
618*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_getattrfid");
619*7c478bd9Sstevel@tonic-gate 	return (error);
620*7c478bd9Sstevel@tonic-gate }
621*7c478bd9Sstevel@tonic-gate 
622*7c478bd9Sstevel@tonic-gate /*
623*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
624*7c478bd9Sstevel@tonic-gate  *			kmod_getattrname
625*7c478bd9Sstevel@tonic-gate  *
626*7c478bd9Sstevel@tonic-gate  * Description:
627*7c478bd9Sstevel@tonic-gate  * Arguments:
628*7c478bd9Sstevel@tonic-gate  *	dirp
629*7c478bd9Sstevel@tonic-gate  *	name
630*7c478bd9Sstevel@tonic-gate  *	credp
631*7c478bd9Sstevel@tonic-gate  *	vattrp
632*7c478bd9Sstevel@tonic-gate  *	filep
633*7c478bd9Sstevel@tonic-gate  * Returns:
634*7c478bd9Sstevel@tonic-gate  *	Returns ...
635*7c478bd9Sstevel@tonic-gate  * Preconditions:
636*7c478bd9Sstevel@tonic-gate  *	precond(dirp)
637*7c478bd9Sstevel@tonic-gate  *	precond(name)
638*7c478bd9Sstevel@tonic-gate  *	precond(credp)
639*7c478bd9Sstevel@tonic-gate  */
640*7c478bd9Sstevel@tonic-gate int
kmod_getattrname(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * dirp,const char * name,dl_cred_t * credp,vattr_t * vattrp,cfs_fid_t * filep)641*7c478bd9Sstevel@tonic-gate kmod_getattrname(cfsd_kmod_object_t *kmod_object_p, cfs_fid_t *dirp,
642*7c478bd9Sstevel@tonic-gate 	const char *name, dl_cred_t *credp, vattr_t *vattrp, cfs_fid_t *filep)
643*7c478bd9Sstevel@tonic-gate {
644*7c478bd9Sstevel@tonic-gate 	cachefsio_getattrname_arg_t info;
645*7c478bd9Sstevel@tonic-gate 	cachefsio_getattrname_return_t ret;
646*7c478bd9Sstevel@tonic-gate 	int error = 0;
647*7c478bd9Sstevel@tonic-gate 	int xx;
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_getattrname");
650*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
651*7c478bd9Sstevel@tonic-gate 
652*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirp);
653*7c478bd9Sstevel@tonic-gate 	dbug_precond(name);
654*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
655*7c478bd9Sstevel@tonic-gate 
656*7c478bd9Sstevel@tonic-gate 	info.cg_dir = *dirp;
657*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(name) < (size_t)MAXNAMELEN);
658*7c478bd9Sstevel@tonic-gate 	strlcpy(info.cg_name, name, sizeof (info.cg_name));
659*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.cg_cred, credp);
660*7c478bd9Sstevel@tonic-gate 
661*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_GETATTRNAME, &info,
662*7c478bd9Sstevel@tonic-gate 	    sizeof (info), &ret, sizeof (ret));
663*7c478bd9Sstevel@tonic-gate 	if (xx)
664*7c478bd9Sstevel@tonic-gate 		error = errno;
665*7c478bd9Sstevel@tonic-gate 
666*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
667*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirp);
668*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid \"%s\"", kmod_object_p->i_fidbuf));
669*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", info.cg_name));
670*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
671*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
672*7c478bd9Sstevel@tonic-gate 		ret.cg_attr.va_mask = AT_ALL;
673*7c478bd9Sstevel@tonic-gate 		kmod_print_attr(&ret.cg_attr);
674*7c478bd9Sstevel@tonic-gate 		kmod_format_fid(kmod_object_p, &ret.cg_fid);
675*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   file fid \"%s\"",
676*7c478bd9Sstevel@tonic-gate 		    kmod_object_p->i_fidbuf));
677*7c478bd9Sstevel@tonic-gate 		if (vattrp)
678*7c478bd9Sstevel@tonic-gate 			*vattrp = ret.cg_attr;
679*7c478bd9Sstevel@tonic-gate 		if (filep)
680*7c478bd9Sstevel@tonic-gate 			*filep = ret.cg_fid;
681*7c478bd9Sstevel@tonic-gate 	}
682*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_getattrname");
683*7c478bd9Sstevel@tonic-gate 	return (error);
684*7c478bd9Sstevel@tonic-gate }
685*7c478bd9Sstevel@tonic-gate 
686*7c478bd9Sstevel@tonic-gate /*
687*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
688*7c478bd9Sstevel@tonic-gate  *			kmod_create
689*7c478bd9Sstevel@tonic-gate  *
690*7c478bd9Sstevel@tonic-gate  * Description:
691*7c478bd9Sstevel@tonic-gate  * Arguments:
692*7c478bd9Sstevel@tonic-gate  *	dirp
693*7c478bd9Sstevel@tonic-gate  *	namep
694*7c478bd9Sstevel@tonic-gate  *	vattrp
695*7c478bd9Sstevel@tonic-gate  *	exclusive
696*7c478bd9Sstevel@tonic-gate  *	mode
697*7c478bd9Sstevel@tonic-gate  *	credp
698*7c478bd9Sstevel@tonic-gate  *	newfidp
699*7c478bd9Sstevel@tonic-gate  *	mtimep
700*7c478bd9Sstevel@tonic-gate  *	ctimep
701*7c478bd9Sstevel@tonic-gate  * Returns:
702*7c478bd9Sstevel@tonic-gate  *	Returns ...
703*7c478bd9Sstevel@tonic-gate  * Preconditions:
704*7c478bd9Sstevel@tonic-gate  *	precond(dirp)
705*7c478bd9Sstevel@tonic-gate  *	precond(namep)
706*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
707*7c478bd9Sstevel@tonic-gate  *	precond(credp)
708*7c478bd9Sstevel@tonic-gate  */
709*7c478bd9Sstevel@tonic-gate int
kmod_create(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * dirp,const char * namep,const cfs_cid_t * cidp,vattr_t * vattrp,int exclusive,int mode,dl_cred_t * credp,cfs_fid_t * newfidp,cfs_timestruc_t * ctimep,cfs_timestruc_t * mtimep)710*7c478bd9Sstevel@tonic-gate kmod_create(cfsd_kmod_object_t *kmod_object_p,
711*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *dirp,
712*7c478bd9Sstevel@tonic-gate 	const char *namep,
713*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
714*7c478bd9Sstevel@tonic-gate 	vattr_t *vattrp,
715*7c478bd9Sstevel@tonic-gate 	int exclusive,
716*7c478bd9Sstevel@tonic-gate 	int mode,
717*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp,
718*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *newfidp,
719*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
720*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *mtimep)
721*7c478bd9Sstevel@tonic-gate {
722*7c478bd9Sstevel@tonic-gate 	cachefsio_create_arg_t info;
723*7c478bd9Sstevel@tonic-gate 	cachefsio_create_return_t ret;
724*7c478bd9Sstevel@tonic-gate 	int error = 0;
725*7c478bd9Sstevel@tonic-gate 	int xx;
726*7c478bd9Sstevel@tonic-gate 
727*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_create");
728*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
729*7c478bd9Sstevel@tonic-gate 
730*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirp);
731*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
732*7c478bd9Sstevel@tonic-gate 	dbug_precond(vattrp);
733*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate 	info.cr_backfid = *dirp;
736*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
737*7c478bd9Sstevel@tonic-gate 	strlcpy(info.cr_name, namep, sizeof (info.cr_name));
738*7c478bd9Sstevel@tonic-gate 	if (cidp) {
739*7c478bd9Sstevel@tonic-gate 		info.cr_cid = *cidp;
740*7c478bd9Sstevel@tonic-gate 	} else {
741*7c478bd9Sstevel@tonic-gate 		info.cr_cid.cid_fileno = 0;
742*7c478bd9Sstevel@tonic-gate 		info.cr_cid.cid_flags = 0;
743*7c478bd9Sstevel@tonic-gate 	}
744*7c478bd9Sstevel@tonic-gate 	info.cr_va = *vattrp;
745*7c478bd9Sstevel@tonic-gate 	info.cr_exclusive = exclusive;
746*7c478bd9Sstevel@tonic-gate 	info.cr_mode = mode;
747*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.cr_cred, credp);
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_CREATE, &info, sizeof (info),
750*7c478bd9Sstevel@tonic-gate 	    &ret, sizeof (ret));
751*7c478bd9Sstevel@tonic-gate 	if (xx)
752*7c478bd9Sstevel@tonic-gate 		error = errno;
753*7c478bd9Sstevel@tonic-gate 
754*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
755*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirp);
756*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid \"%s\"", kmod_object_p->i_fidbuf));
757*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s', exclusive %d, mode 0%o",
758*7c478bd9Sstevel@tonic-gate 	    namep, exclusive, mode));
759*7c478bd9Sstevel@tonic-gate 	kmod_print_attr(vattrp);
760*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
761*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
762*7c478bd9Sstevel@tonic-gate 		if (newfidp)
763*7c478bd9Sstevel@tonic-gate 			*newfidp = ret.cr_newfid;
764*7c478bd9Sstevel@tonic-gate 		if (ctimep)
765*7c478bd9Sstevel@tonic-gate 			*ctimep = ret.cr_ctime;
766*7c478bd9Sstevel@tonic-gate 		if (mtimep)
767*7c478bd9Sstevel@tonic-gate 			*mtimep = ret.cr_mtime;
768*7c478bd9Sstevel@tonic-gate 		kmod_format_fid(kmod_object_p, &ret.cr_newfid);
769*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   created file fid \"%s\"",
770*7c478bd9Sstevel@tonic-gate 		    kmod_object_p->i_fidbuf));
771*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x",
772*7c478bd9Sstevel@tonic-gate 		    ret.cr_ctime.tv_sec, ret.cr_ctime.tv_nsec));
773*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   mtime %x %x",
774*7c478bd9Sstevel@tonic-gate 		    ret.cr_mtime.tv_sec, ret.cr_mtime.tv_nsec));
775*7c478bd9Sstevel@tonic-gate 	}
776*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_create");
777*7c478bd9Sstevel@tonic-gate 	return (error);
778*7c478bd9Sstevel@tonic-gate }
779*7c478bd9Sstevel@tonic-gate 
780*7c478bd9Sstevel@tonic-gate /*
781*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
782*7c478bd9Sstevel@tonic-gate  *			kmod_pushback
783*7c478bd9Sstevel@tonic-gate  *
784*7c478bd9Sstevel@tonic-gate  * Description:
785*7c478bd9Sstevel@tonic-gate  * Arguments:
786*7c478bd9Sstevel@tonic-gate  *	filep
787*7c478bd9Sstevel@tonic-gate  *	fidp
788*7c478bd9Sstevel@tonic-gate  *	credp
789*7c478bd9Sstevel@tonic-gate  * Returns:
790*7c478bd9Sstevel@tonic-gate  *	Returns ...
791*7c478bd9Sstevel@tonic-gate  * Preconditions:
792*7c478bd9Sstevel@tonic-gate  *	precond(filep)
793*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
794*7c478bd9Sstevel@tonic-gate  *	precond(credp)
795*7c478bd9Sstevel@tonic-gate  */
796*7c478bd9Sstevel@tonic-gate int
kmod_pushback(cfsd_kmod_object_t * kmod_object_p,cfs_cid_t * filep,cfs_fid_t * fidp,dl_cred_t * credp,cfs_timestruc_t * ctimep,cfs_timestruc_t * mtimep,int update)797*7c478bd9Sstevel@tonic-gate kmod_pushback(cfsd_kmod_object_t *kmod_object_p,
798*7c478bd9Sstevel@tonic-gate 	cfs_cid_t *filep,
799*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *fidp,
800*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp,
801*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
802*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *mtimep,
803*7c478bd9Sstevel@tonic-gate 	int update)
804*7c478bd9Sstevel@tonic-gate {
805*7c478bd9Sstevel@tonic-gate 	cachefsio_pushback_arg_t info;
806*7c478bd9Sstevel@tonic-gate 	cachefsio_pushback_return_t ret;
807*7c478bd9Sstevel@tonic-gate 	int error = 0;
808*7c478bd9Sstevel@tonic-gate 	int xx;
809*7c478bd9Sstevel@tonic-gate 
810*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_pushback");
811*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
812*7c478bd9Sstevel@tonic-gate 
813*7c478bd9Sstevel@tonic-gate 	dbug_precond(filep);
814*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
815*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
816*7c478bd9Sstevel@tonic-gate 
817*7c478bd9Sstevel@tonic-gate 	/* note: update is no longer used */
818*7c478bd9Sstevel@tonic-gate 
819*7c478bd9Sstevel@tonic-gate 	info.pb_cid = *filep;
820*7c478bd9Sstevel@tonic-gate 	info.pb_fid = *fidp;
821*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.pb_cred, credp);
822*7c478bd9Sstevel@tonic-gate 
823*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_PUSHBACK, &info, sizeof (info),
824*7c478bd9Sstevel@tonic-gate 	    &ret, sizeof (ret));
825*7c478bd9Sstevel@tonic-gate 	if (xx)
826*7c478bd9Sstevel@tonic-gate 		error = errno;
827*7c478bd9Sstevel@tonic-gate 
828*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
829*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   cid %08x", filep->cid_fileno));
830*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, fidp);
831*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   fid \"%s\"", kmod_object_p->i_fidbuf));
832*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
833*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
834*7c478bd9Sstevel@tonic-gate 		if (ctimep)
835*7c478bd9Sstevel@tonic-gate 			*ctimep = ret.pb_ctime;
836*7c478bd9Sstevel@tonic-gate 		if (mtimep)
837*7c478bd9Sstevel@tonic-gate 			*mtimep = ret.pb_mtime;
838*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x",
839*7c478bd9Sstevel@tonic-gate 		    ret.pb_ctime.tv_sec, ret.pb_ctime.tv_nsec));
840*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   mtime %x %x",
841*7c478bd9Sstevel@tonic-gate 		    ret.pb_mtime.tv_sec, ret.pb_mtime.tv_nsec));
842*7c478bd9Sstevel@tonic-gate 	}
843*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_pushback");
844*7c478bd9Sstevel@tonic-gate 	return (error);
845*7c478bd9Sstevel@tonic-gate }
846*7c478bd9Sstevel@tonic-gate 
847*7c478bd9Sstevel@tonic-gate 
848*7c478bd9Sstevel@tonic-gate /*
849*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
850*7c478bd9Sstevel@tonic-gate  *			kmod_rename
851*7c478bd9Sstevel@tonic-gate  *
852*7c478bd9Sstevel@tonic-gate  * Description:
853*7c478bd9Sstevel@tonic-gate  * Arguments:
854*7c478bd9Sstevel@tonic-gate  *	olddir
855*7c478bd9Sstevel@tonic-gate  *	oldname
856*7c478bd9Sstevel@tonic-gate  *	newdir
857*7c478bd9Sstevel@tonic-gate  *	newname
858*7c478bd9Sstevel@tonic-gate  *	credp
859*7c478bd9Sstevel@tonic-gate  * Returns:
860*7c478bd9Sstevel@tonic-gate  *	Returns ...
861*7c478bd9Sstevel@tonic-gate  * Preconditions:
862*7c478bd9Sstevel@tonic-gate  *	precond(olddir)
863*7c478bd9Sstevel@tonic-gate  *	precond(oldname)
864*7c478bd9Sstevel@tonic-gate  *	precond(newdir)
865*7c478bd9Sstevel@tonic-gate  *	precond(newname)
866*7c478bd9Sstevel@tonic-gate  *	precond(credp)
867*7c478bd9Sstevel@tonic-gate  */
868*7c478bd9Sstevel@tonic-gate int
kmod_rename(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * olddir,const char * oldname,cfs_fid_t * newdir,const char * newname,const cfs_cid_t * cidp,dl_cred_t * credp,cfs_timestruc_t * ctimep,cfs_timestruc_t * delctimep,const cfs_cid_t * delcidp)869*7c478bd9Sstevel@tonic-gate kmod_rename(cfsd_kmod_object_t *kmod_object_p,
870*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *olddir,
871*7c478bd9Sstevel@tonic-gate 	const char *oldname,
872*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *newdir,
873*7c478bd9Sstevel@tonic-gate 	const char *newname,
874*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
875*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp,
876*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
877*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *delctimep,
878*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *delcidp)
879*7c478bd9Sstevel@tonic-gate {
880*7c478bd9Sstevel@tonic-gate 	cachefsio_rename_arg_t info;
881*7c478bd9Sstevel@tonic-gate 	cachefsio_rename_return_t ret;
882*7c478bd9Sstevel@tonic-gate 	int error = 0;
883*7c478bd9Sstevel@tonic-gate 	int xx;
884*7c478bd9Sstevel@tonic-gate 
885*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_rename");
886*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
887*7c478bd9Sstevel@tonic-gate 
888*7c478bd9Sstevel@tonic-gate 	dbug_precond(olddir);
889*7c478bd9Sstevel@tonic-gate 	dbug_precond(oldname);
890*7c478bd9Sstevel@tonic-gate 	dbug_precond(newdir);
891*7c478bd9Sstevel@tonic-gate 	dbug_precond(newname);
892*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
893*7c478bd9Sstevel@tonic-gate 	dbug_precond(ctimep);
894*7c478bd9Sstevel@tonic-gate 
895*7c478bd9Sstevel@tonic-gate 	info.rn_olddir = *olddir;
896*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(oldname) < (size_t)MAXNAMELEN);
897*7c478bd9Sstevel@tonic-gate 	strlcpy(info.rn_oldname, oldname, sizeof (info.rn_oldname));
898*7c478bd9Sstevel@tonic-gate 	info.rn_newdir = *newdir;
899*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(newname) < (size_t)MAXNAMELEN);
900*7c478bd9Sstevel@tonic-gate 	strlcpy(info.rn_newname, newname, sizeof (info.rn_newname));
901*7c478bd9Sstevel@tonic-gate 	info.rn_cid = *cidp;
902*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.rn_cred, credp);
903*7c478bd9Sstevel@tonic-gate 	info.rn_del_getctime = delctimep ? 1 : 0;
904*7c478bd9Sstevel@tonic-gate 	info.rn_del_cid = *delcidp;
905*7c478bd9Sstevel@tonic-gate 
906*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_RENAME, &info, sizeof (info),
907*7c478bd9Sstevel@tonic-gate 	    &ret, sizeof (ret));
908*7c478bd9Sstevel@tonic-gate 	if (xx)
909*7c478bd9Sstevel@tonic-gate 		error = errno;
910*7c478bd9Sstevel@tonic-gate 
911*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
912*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, olddir);
913*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   old dir fid \"%s\"", kmod_object_p->i_fidbuf));
914*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, newdir);
915*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   new dir fid \"%s\"", kmod_object_p->i_fidbuf));
916*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   old name '%s'  new name '%s'",
917*7c478bd9Sstevel@tonic-gate 	    oldname, newname));
918*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
919*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
920*7c478bd9Sstevel@tonic-gate 		*ctimep = ret.rn_ctime;
921*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x",
922*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_sec, ctimep->tv_nsec));
923*7c478bd9Sstevel@tonic-gate 		if (delctimep) {
924*7c478bd9Sstevel@tonic-gate 			*delctimep = ret.rn_del_ctime;
925*7c478bd9Sstevel@tonic-gate 			dbug_print(("ioctl", "   del ctime %x %x",
926*7c478bd9Sstevel@tonic-gate 			    delctimep->tv_sec, delctimep->tv_nsec));
927*7c478bd9Sstevel@tonic-gate 		}
928*7c478bd9Sstevel@tonic-gate 	}
929*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_rename");
930*7c478bd9Sstevel@tonic-gate 	return (error);
931*7c478bd9Sstevel@tonic-gate }
932*7c478bd9Sstevel@tonic-gate 
933*7c478bd9Sstevel@tonic-gate /*
934*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
935*7c478bd9Sstevel@tonic-gate  *			kmod_setattr
936*7c478bd9Sstevel@tonic-gate  *
937*7c478bd9Sstevel@tonic-gate  * Description:
938*7c478bd9Sstevel@tonic-gate  * Arguments:
939*7c478bd9Sstevel@tonic-gate  *	fidp
940*7c478bd9Sstevel@tonic-gate  *	vattrp
941*7c478bd9Sstevel@tonic-gate  *	flags
942*7c478bd9Sstevel@tonic-gate  *	credp
943*7c478bd9Sstevel@tonic-gate  * Returns:
944*7c478bd9Sstevel@tonic-gate  *	Returns ...
945*7c478bd9Sstevel@tonic-gate  * Preconditions:
946*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
947*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
948*7c478bd9Sstevel@tonic-gate  *	precond(credp)
949*7c478bd9Sstevel@tonic-gate  */
950*7c478bd9Sstevel@tonic-gate int
kmod_setattr(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * fidp,const cfs_cid_t * cidp,vattr_t * vattrp,int flags,dl_cred_t * credp,cfs_timestruc_t * ctimep,cfs_timestruc_t * mtimep)951*7c478bd9Sstevel@tonic-gate kmod_setattr(cfsd_kmod_object_t *kmod_object_p,
952*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *fidp,
953*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
954*7c478bd9Sstevel@tonic-gate 	vattr_t *vattrp,
955*7c478bd9Sstevel@tonic-gate 	int flags,
956*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp,
957*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
958*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *mtimep)
959*7c478bd9Sstevel@tonic-gate {
960*7c478bd9Sstevel@tonic-gate 	cachefsio_setattr_arg_t info;
961*7c478bd9Sstevel@tonic-gate 	cachefsio_setattr_return_t ret;
962*7c478bd9Sstevel@tonic-gate 	int error = 0;
963*7c478bd9Sstevel@tonic-gate 	int xx;
964*7c478bd9Sstevel@tonic-gate 
965*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_setattr");
966*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
967*7c478bd9Sstevel@tonic-gate 
968*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
969*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
970*7c478bd9Sstevel@tonic-gate 	dbug_precond(vattrp);
971*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
972*7c478bd9Sstevel@tonic-gate 	dbug_precond(ctimep);
973*7c478bd9Sstevel@tonic-gate 	dbug_precond(mtimep);
974*7c478bd9Sstevel@tonic-gate 
975*7c478bd9Sstevel@tonic-gate 	info.sa_backfid = *fidp;
976*7c478bd9Sstevel@tonic-gate 	info.sa_cid = *cidp;
977*7c478bd9Sstevel@tonic-gate 	info.sa_vattr = *vattrp;
978*7c478bd9Sstevel@tonic-gate 	info.sa_flags = flags;
979*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.sa_cred, credp);
980*7c478bd9Sstevel@tonic-gate 
981*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_SETATTR, &info, sizeof (info),
982*7c478bd9Sstevel@tonic-gate 	    &ret, sizeof (ret));
983*7c478bd9Sstevel@tonic-gate 	if (xx)
984*7c478bd9Sstevel@tonic-gate 		error = errno;
985*7c478bd9Sstevel@tonic-gate 
986*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
987*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   flags 0x%x", flags));
988*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, fidp);
989*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   fid \"%s\"", kmod_object_p->i_fidbuf));
990*7c478bd9Sstevel@tonic-gate 	kmod_print_attr(vattrp);
991*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
992*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
993*7c478bd9Sstevel@tonic-gate 		*ctimep = ret.sa_ctime;
994*7c478bd9Sstevel@tonic-gate 		*mtimep = ret.sa_mtime;
995*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x", ctimep->tv_sec,
996*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_nsec));
997*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   mtime %x %x", mtimep->tv_sec,
998*7c478bd9Sstevel@tonic-gate 		    mtimep->tv_nsec));
999*7c478bd9Sstevel@tonic-gate 	}
1000*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_setattr");
1001*7c478bd9Sstevel@tonic-gate 	return (error);
1002*7c478bd9Sstevel@tonic-gate }
1003*7c478bd9Sstevel@tonic-gate 
1004*7c478bd9Sstevel@tonic-gate /*
1005*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1006*7c478bd9Sstevel@tonic-gate  *			kmod_setsecattr
1007*7c478bd9Sstevel@tonic-gate  *
1008*7c478bd9Sstevel@tonic-gate  * Description:
1009*7c478bd9Sstevel@tonic-gate  * Arguments:
1010*7c478bd9Sstevel@tonic-gate  *	fidp
1011*7c478bd9Sstevel@tonic-gate  *	aclcnt
1012*7c478bd9Sstevel@tonic-gate  *	dfaclcnt
1013*7c478bd9Sstevel@tonic-gate  *	acl
1014*7c478bd9Sstevel@tonic-gate  *	flags
1015*7c478bd9Sstevel@tonic-gate  *	credp
1016*7c478bd9Sstevel@tonic-gate  * Returns:
1017*7c478bd9Sstevel@tonic-gate  *	Returns ...
1018*7c478bd9Sstevel@tonic-gate  * Preconditions:
1019*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
1020*7c478bd9Sstevel@tonic-gate  *	precond(acl)
1021*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1022*7c478bd9Sstevel@tonic-gate  *	precond(aclcnt + dfaclcnt <= MAX_ACL_ENTRIES)
1023*7c478bd9Sstevel@tonic-gate  */
1024*7c478bd9Sstevel@tonic-gate int
kmod_setsecattr(cfsd_kmod_object_t * kmod_object_p,cfs_fid_t * fidp,const cfs_cid_t * cidp,ulong_t mask,int aclcnt,int dfaclcnt,const aclent_t * acl,dl_cred_t * credp,cfs_timestruc_t * ctimep,cfs_timestruc_t * mtimep)1025*7c478bd9Sstevel@tonic-gate kmod_setsecattr(cfsd_kmod_object_t *kmod_object_p,
1026*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *fidp,
1027*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
1028*7c478bd9Sstevel@tonic-gate 	ulong_t mask,
1029*7c478bd9Sstevel@tonic-gate 	int aclcnt,
1030*7c478bd9Sstevel@tonic-gate 	int dfaclcnt,
1031*7c478bd9Sstevel@tonic-gate 	const aclent_t *acl,
1032*7c478bd9Sstevel@tonic-gate 	dl_cred_t *credp,
1033*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
1034*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *mtimep)
1035*7c478bd9Sstevel@tonic-gate {
1036*7c478bd9Sstevel@tonic-gate 	cachefsio_setsecattr_arg_t info;
1037*7c478bd9Sstevel@tonic-gate 	cachefsio_setsecattr_return_t ret;
1038*7c478bd9Sstevel@tonic-gate 	int error = 0;
1039*7c478bd9Sstevel@tonic-gate 	int xx;
1040*7c478bd9Sstevel@tonic-gate 
1041*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_setsecattr");
1042*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1043*7c478bd9Sstevel@tonic-gate 
1044*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
1045*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
1046*7c478bd9Sstevel@tonic-gate 	dbug_precond(acl);
1047*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1048*7c478bd9Sstevel@tonic-gate 	dbug_precond(ctimep);
1049*7c478bd9Sstevel@tonic-gate 	dbug_precond(mtimep);
1050*7c478bd9Sstevel@tonic-gate 	dbug_precond(aclcnt + dfaclcnt <= MAX_ACL_ENTRIES);
1051*7c478bd9Sstevel@tonic-gate 
1052*7c478bd9Sstevel@tonic-gate 	info.sc_backfid = *fidp;
1053*7c478bd9Sstevel@tonic-gate 	info.sc_cid = *cidp;
1054*7c478bd9Sstevel@tonic-gate 	info.sc_mask = mask;
1055*7c478bd9Sstevel@tonic-gate 	info.sc_aclcnt = aclcnt;
1056*7c478bd9Sstevel@tonic-gate 	info.sc_dfaclcnt = dfaclcnt;
1057*7c478bd9Sstevel@tonic-gate 	memcpy(&info.sc_acl, acl, (aclcnt + dfaclcnt) * sizeof (aclent_t));
1058*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.sc_cred, credp);
1059*7c478bd9Sstevel@tonic-gate 
1060*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_SETSECATTR, &info,
1061*7c478bd9Sstevel@tonic-gate 	    sizeof (info), &ret, sizeof (ret));
1062*7c478bd9Sstevel@tonic-gate 	if (xx)
1063*7c478bd9Sstevel@tonic-gate 		error = errno;
1064*7c478bd9Sstevel@tonic-gate 
1065*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1066*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, fidp);
1067*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   fid \"%s\"", kmod_object_p->i_fidbuf));
1068*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   aclcnt %d dfaclcnt %d", aclcnt, dfaclcnt));
1069*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1070*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
1071*7c478bd9Sstevel@tonic-gate 		*ctimep = ret.sc_ctime;
1072*7c478bd9Sstevel@tonic-gate 		*mtimep = ret.sc_mtime;
1073*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x", ctimep->tv_sec,
1074*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_nsec));
1075*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   mtime %x %x", mtimep->tv_sec,
1076*7c478bd9Sstevel@tonic-gate 		    mtimep->tv_nsec));
1077*7c478bd9Sstevel@tonic-gate 	}
1078*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_setsecattr");
1079*7c478bd9Sstevel@tonic-gate 	return (error);
1080*7c478bd9Sstevel@tonic-gate }
1081*7c478bd9Sstevel@tonic-gate 
1082*7c478bd9Sstevel@tonic-gate /*
1083*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1084*7c478bd9Sstevel@tonic-gate  *			kmod_remove
1085*7c478bd9Sstevel@tonic-gate  *
1086*7c478bd9Sstevel@tonic-gate  * Description:
1087*7c478bd9Sstevel@tonic-gate  * Arguments:
1088*7c478bd9Sstevel@tonic-gate  *	fidp
1089*7c478bd9Sstevel@tonic-gate  *	namep
1090*7c478bd9Sstevel@tonic-gate  *	credp
1091*7c478bd9Sstevel@tonic-gate  *	ctimep
1092*7c478bd9Sstevel@tonic-gate  * Returns:
1093*7c478bd9Sstevel@tonic-gate  *	Returns ...
1094*7c478bd9Sstevel@tonic-gate  * Preconditions:
1095*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
1096*7c478bd9Sstevel@tonic-gate  *	precond(namep)
1097*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1098*7c478bd9Sstevel@tonic-gate  */
1099*7c478bd9Sstevel@tonic-gate int
kmod_remove(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * fidp,const cfs_cid_t * cidp,const char * namep,const dl_cred_t * credp,cfs_timestruc_t * ctimep)1100*7c478bd9Sstevel@tonic-gate kmod_remove(cfsd_kmod_object_t *kmod_object_p,
1101*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *fidp,
1102*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
1103*7c478bd9Sstevel@tonic-gate 	const char *namep,
1104*7c478bd9Sstevel@tonic-gate 	const dl_cred_t *credp,
1105*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep)
1106*7c478bd9Sstevel@tonic-gate {
1107*7c478bd9Sstevel@tonic-gate 	cachefsio_remove_t info;
1108*7c478bd9Sstevel@tonic-gate 	int len;
1109*7c478bd9Sstevel@tonic-gate 	int error = 0;
1110*7c478bd9Sstevel@tonic-gate 	int xx;
1111*7c478bd9Sstevel@tonic-gate 
1112*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_remove");
1113*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1114*7c478bd9Sstevel@tonic-gate 
1115*7c478bd9Sstevel@tonic-gate 	dbug_precond(fidp);
1116*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
1117*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
1118*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1119*7c478bd9Sstevel@tonic-gate 
1120*7c478bd9Sstevel@tonic-gate 	info.rm_fid = *fidp;
1121*7c478bd9Sstevel@tonic-gate 	info.rm_cid = *cidp;
1122*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
1123*7c478bd9Sstevel@tonic-gate 	strlcpy(info.rm_name, namep, sizeof (info.rm_name));
1124*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.rm_cred, credp);
1125*7c478bd9Sstevel@tonic-gate 	info.rm_getctime = ctimep ? 1 : 0;
1126*7c478bd9Sstevel@tonic-gate 
1127*7c478bd9Sstevel@tonic-gate 	if (ctimep)
1128*7c478bd9Sstevel@tonic-gate 		len = sizeof (*ctimep);
1129*7c478bd9Sstevel@tonic-gate 	else
1130*7c478bd9Sstevel@tonic-gate 		len = 0;
1131*7c478bd9Sstevel@tonic-gate 
1132*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_REMOVE, &info, sizeof (info),
1133*7c478bd9Sstevel@tonic-gate 	    ctimep, len);
1134*7c478bd9Sstevel@tonic-gate 	if (xx)
1135*7c478bd9Sstevel@tonic-gate 		error = errno;
1136*7c478bd9Sstevel@tonic-gate 
1137*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1138*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, fidp);
1139*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   fid '%s'", kmod_object_p->i_fidbuf));
1140*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", namep));
1141*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1142*7c478bd9Sstevel@tonic-gate 	if ((xx == 0) && ctimep) {
1143*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x", ctimep->tv_sec,
1144*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_nsec));
1145*7c478bd9Sstevel@tonic-gate 	}
1146*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_remove");
1147*7c478bd9Sstevel@tonic-gate 	return (error);
1148*7c478bd9Sstevel@tonic-gate }
1149*7c478bd9Sstevel@tonic-gate 
1150*7c478bd9Sstevel@tonic-gate /*
1151*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1152*7c478bd9Sstevel@tonic-gate  *			kmod_link
1153*7c478bd9Sstevel@tonic-gate  *
1154*7c478bd9Sstevel@tonic-gate  * Description:
1155*7c478bd9Sstevel@tonic-gate  * Arguments:
1156*7c478bd9Sstevel@tonic-gate  *	dirfidp
1157*7c478bd9Sstevel@tonic-gate  *	namep
1158*7c478bd9Sstevel@tonic-gate  *	filefidp
1159*7c478bd9Sstevel@tonic-gate  *	credp
1160*7c478bd9Sstevel@tonic-gate  *	ctimep
1161*7c478bd9Sstevel@tonic-gate  * Returns:
1162*7c478bd9Sstevel@tonic-gate  *	Returns ...
1163*7c478bd9Sstevel@tonic-gate  * Preconditions:
1164*7c478bd9Sstevel@tonic-gate  *	precond(dirfidp)
1165*7c478bd9Sstevel@tonic-gate  *	precond(namep)
1166*7c478bd9Sstevel@tonic-gate  *	precond(filefidp)
1167*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1168*7c478bd9Sstevel@tonic-gate  */
1169*7c478bd9Sstevel@tonic-gate int
kmod_link(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * dirfidp,const char * namep,const cfs_fid_t * filefidp,const cfs_cid_t * cidp,const dl_cred_t * credp,cfs_timestruc_t * ctimep)1170*7c478bd9Sstevel@tonic-gate kmod_link(cfsd_kmod_object_t *kmod_object_p,
1171*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *dirfidp,
1172*7c478bd9Sstevel@tonic-gate 	const char *namep,
1173*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *filefidp,
1174*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
1175*7c478bd9Sstevel@tonic-gate 	const dl_cred_t *credp,
1176*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep)
1177*7c478bd9Sstevel@tonic-gate {
1178*7c478bd9Sstevel@tonic-gate 	cachefsio_link_t info;
1179*7c478bd9Sstevel@tonic-gate 	int error = 0;
1180*7c478bd9Sstevel@tonic-gate 	int xx;
1181*7c478bd9Sstevel@tonic-gate 
1182*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_link");
1183*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1184*7c478bd9Sstevel@tonic-gate 
1185*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirfidp);
1186*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
1187*7c478bd9Sstevel@tonic-gate 	dbug_precond(filefidp);
1188*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
1189*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1190*7c478bd9Sstevel@tonic-gate 	dbug_precond(ctimep);
1191*7c478bd9Sstevel@tonic-gate 
1192*7c478bd9Sstevel@tonic-gate 	info.ln_dirfid = *dirfidp;
1193*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
1194*7c478bd9Sstevel@tonic-gate 	strlcpy(info.ln_name, namep, sizeof (info.ln_name));
1195*7c478bd9Sstevel@tonic-gate 	info.ln_filefid = *filefidp;
1196*7c478bd9Sstevel@tonic-gate 	info.ln_cid = *cidp;
1197*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.ln_cred, credp);
1198*7c478bd9Sstevel@tonic-gate 
1199*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_LINK, &info, sizeof (info),
1200*7c478bd9Sstevel@tonic-gate 	    ctimep, sizeof (*ctimep));
1201*7c478bd9Sstevel@tonic-gate 	if (xx)
1202*7c478bd9Sstevel@tonic-gate 		error = errno;
1203*7c478bd9Sstevel@tonic-gate 
1204*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1205*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirfidp);
1206*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid '%s'", kmod_object_p->i_fidbuf));
1207*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", namep));
1208*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, filefidp);
1209*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   file fid '%s'", kmod_object_p->i_fidbuf));
1210*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1211*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
1212*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x", ctimep->tv_sec,
1213*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_nsec));
1214*7c478bd9Sstevel@tonic-gate 	}
1215*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_link");
1216*7c478bd9Sstevel@tonic-gate 	return (error);
1217*7c478bd9Sstevel@tonic-gate }
1218*7c478bd9Sstevel@tonic-gate 
1219*7c478bd9Sstevel@tonic-gate /*
1220*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1221*7c478bd9Sstevel@tonic-gate  *			kmod_mkdir
1222*7c478bd9Sstevel@tonic-gate  *
1223*7c478bd9Sstevel@tonic-gate  * Description:
1224*7c478bd9Sstevel@tonic-gate  * Arguments:
1225*7c478bd9Sstevel@tonic-gate  *	dirfidp
1226*7c478bd9Sstevel@tonic-gate  *	namep
1227*7c478bd9Sstevel@tonic-gate  *	vattrp
1228*7c478bd9Sstevel@tonic-gate  *	credp
1229*7c478bd9Sstevel@tonic-gate  *	newfidp
1230*7c478bd9Sstevel@tonic-gate  * Returns:
1231*7c478bd9Sstevel@tonic-gate  *	Returns ...
1232*7c478bd9Sstevel@tonic-gate  * Preconditions:
1233*7c478bd9Sstevel@tonic-gate  *	precond(dirfidp)
1234*7c478bd9Sstevel@tonic-gate  *	precond(namep)
1235*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
1236*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1237*7c478bd9Sstevel@tonic-gate  *	precond(newfidp)
1238*7c478bd9Sstevel@tonic-gate  */
1239*7c478bd9Sstevel@tonic-gate int
kmod_mkdir(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * dirfidp,const char * namep,const cfs_cid_t * cidp,const vattr_t * vattrp,const dl_cred_t * credp,cfs_fid_t * newfidp)1240*7c478bd9Sstevel@tonic-gate kmod_mkdir(cfsd_kmod_object_t *kmod_object_p,
1241*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *dirfidp,
1242*7c478bd9Sstevel@tonic-gate 	const char *namep,
1243*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
1244*7c478bd9Sstevel@tonic-gate 	const vattr_t *vattrp,
1245*7c478bd9Sstevel@tonic-gate 	const dl_cred_t *credp,
1246*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *newfidp)
1247*7c478bd9Sstevel@tonic-gate {
1248*7c478bd9Sstevel@tonic-gate 	cachefsio_mkdir_t info;
1249*7c478bd9Sstevel@tonic-gate 	int error = 0;
1250*7c478bd9Sstevel@tonic-gate 	int xx;
1251*7c478bd9Sstevel@tonic-gate 
1252*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_mkdir");
1253*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1254*7c478bd9Sstevel@tonic-gate 
1255*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirfidp);
1256*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
1257*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
1258*7c478bd9Sstevel@tonic-gate 	dbug_precond(vattrp);
1259*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1260*7c478bd9Sstevel@tonic-gate 	dbug_precond(newfidp);
1261*7c478bd9Sstevel@tonic-gate 
1262*7c478bd9Sstevel@tonic-gate 	info.md_dirfid = *dirfidp;
1263*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
1264*7c478bd9Sstevel@tonic-gate 	strlcpy(info.md_name, namep, sizeof (info.md_name));
1265*7c478bd9Sstevel@tonic-gate 	info.md_cid = *cidp;
1266*7c478bd9Sstevel@tonic-gate 	info.md_vattr = *vattrp;
1267*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.md_cred, credp);
1268*7c478bd9Sstevel@tonic-gate 
1269*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_MKDIR, &info, sizeof (info),
1270*7c478bd9Sstevel@tonic-gate 	    newfidp, sizeof (*newfidp));
1271*7c478bd9Sstevel@tonic-gate 	if (xx)
1272*7c478bd9Sstevel@tonic-gate 		error = errno;
1273*7c478bd9Sstevel@tonic-gate 
1274*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1275*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirfidp);
1276*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid '%s'", kmod_object_p->i_fidbuf));
1277*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", namep));
1278*7c478bd9Sstevel@tonic-gate 	kmod_print_attr(vattrp);
1279*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1280*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
1281*7c478bd9Sstevel@tonic-gate 		kmod_format_fid(kmod_object_p, newfidp);
1282*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   file fid '%s'",
1283*7c478bd9Sstevel@tonic-gate 		    kmod_object_p->i_fidbuf));
1284*7c478bd9Sstevel@tonic-gate 	}
1285*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_mkdir");
1286*7c478bd9Sstevel@tonic-gate 	return (error);
1287*7c478bd9Sstevel@tonic-gate }
1288*7c478bd9Sstevel@tonic-gate 
1289*7c478bd9Sstevel@tonic-gate /*
1290*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1291*7c478bd9Sstevel@tonic-gate  *			kmod_rmdir
1292*7c478bd9Sstevel@tonic-gate  *
1293*7c478bd9Sstevel@tonic-gate  * Description:
1294*7c478bd9Sstevel@tonic-gate  * Arguments:
1295*7c478bd9Sstevel@tonic-gate  *	dirfidp
1296*7c478bd9Sstevel@tonic-gate  *	namep
1297*7c478bd9Sstevel@tonic-gate  *	credp
1298*7c478bd9Sstevel@tonic-gate  * Returns:
1299*7c478bd9Sstevel@tonic-gate  *	Returns ...
1300*7c478bd9Sstevel@tonic-gate  * Preconditions:
1301*7c478bd9Sstevel@tonic-gate  *	precond(dirfidp)
1302*7c478bd9Sstevel@tonic-gate  *	precond(namep)
1303*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1304*7c478bd9Sstevel@tonic-gate  */
1305*7c478bd9Sstevel@tonic-gate int
kmod_rmdir(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * dirfidp,const char * namep,const dl_cred_t * credp)1306*7c478bd9Sstevel@tonic-gate kmod_rmdir(cfsd_kmod_object_t *kmod_object_p,
1307*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *dirfidp,
1308*7c478bd9Sstevel@tonic-gate 	const char *namep,
1309*7c478bd9Sstevel@tonic-gate 	const dl_cred_t *credp)
1310*7c478bd9Sstevel@tonic-gate {
1311*7c478bd9Sstevel@tonic-gate 	cachefsio_rmdir_t info;
1312*7c478bd9Sstevel@tonic-gate 	int error = 0;
1313*7c478bd9Sstevel@tonic-gate 	int xx;
1314*7c478bd9Sstevel@tonic-gate 
1315*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_rmdir");
1316*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1317*7c478bd9Sstevel@tonic-gate 
1318*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirfidp);
1319*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
1320*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1321*7c478bd9Sstevel@tonic-gate 
1322*7c478bd9Sstevel@tonic-gate 	info.rd_dirfid = *dirfidp;
1323*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
1324*7c478bd9Sstevel@tonic-gate 	strlcpy(info.rd_name, namep, sizeof (info.rd_name));
1325*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.rd_cred, credp);
1326*7c478bd9Sstevel@tonic-gate 
1327*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_RMDIR, &info, sizeof (info),
1328*7c478bd9Sstevel@tonic-gate 	    NULL, 0);
1329*7c478bd9Sstevel@tonic-gate 	if (xx)
1330*7c478bd9Sstevel@tonic-gate 		error = errno;
1331*7c478bd9Sstevel@tonic-gate 
1332*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1333*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirfidp);
1334*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid '%s'", kmod_object_p->i_fidbuf));
1335*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", namep));
1336*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1337*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_rmdir");
1338*7c478bd9Sstevel@tonic-gate 	return (error);
1339*7c478bd9Sstevel@tonic-gate }
1340*7c478bd9Sstevel@tonic-gate 
1341*7c478bd9Sstevel@tonic-gate /*
1342*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1343*7c478bd9Sstevel@tonic-gate  *			kmod_symlink
1344*7c478bd9Sstevel@tonic-gate  *
1345*7c478bd9Sstevel@tonic-gate  * Description:
1346*7c478bd9Sstevel@tonic-gate  * Arguments:
1347*7c478bd9Sstevel@tonic-gate  *	dirfidp
1348*7c478bd9Sstevel@tonic-gate  *	namep
1349*7c478bd9Sstevel@tonic-gate  *	linkvalp
1350*7c478bd9Sstevel@tonic-gate  *	vattrp
1351*7c478bd9Sstevel@tonic-gate  *	credp
1352*7c478bd9Sstevel@tonic-gate  *	ctimep
1353*7c478bd9Sstevel@tonic-gate  *	mtimep
1354*7c478bd9Sstevel@tonic-gate  * Returns:
1355*7c478bd9Sstevel@tonic-gate  *	Returns ...
1356*7c478bd9Sstevel@tonic-gate  * Preconditions:
1357*7c478bd9Sstevel@tonic-gate  *	precond(dirfidp)
1358*7c478bd9Sstevel@tonic-gate  *	precond(namep)
1359*7c478bd9Sstevel@tonic-gate  *	precond(linkvalp)
1360*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
1361*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1362*7c478bd9Sstevel@tonic-gate  *	precond(ctimep)
1363*7c478bd9Sstevel@tonic-gate  *	precond(mtimep)
1364*7c478bd9Sstevel@tonic-gate  */
1365*7c478bd9Sstevel@tonic-gate int
kmod_symlink(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * dirfidp,const char * namep,const cfs_cid_t * cidp,const char * linkvalp,const vattr_t * vattrp,const dl_cred_t * credp,cfs_fid_t * newfidp,cfs_timestruc_t * ctimep,cfs_timestruc_t * mtimep)1366*7c478bd9Sstevel@tonic-gate kmod_symlink(cfsd_kmod_object_t *kmod_object_p,
1367*7c478bd9Sstevel@tonic-gate 	const cfs_fid_t *dirfidp,
1368*7c478bd9Sstevel@tonic-gate 	const char *namep,
1369*7c478bd9Sstevel@tonic-gate 	const cfs_cid_t *cidp,
1370*7c478bd9Sstevel@tonic-gate 	const char *linkvalp,
1371*7c478bd9Sstevel@tonic-gate 	const vattr_t *vattrp,
1372*7c478bd9Sstevel@tonic-gate 	const dl_cred_t *credp,
1373*7c478bd9Sstevel@tonic-gate 	cfs_fid_t *newfidp,
1374*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *ctimep,
1375*7c478bd9Sstevel@tonic-gate 	cfs_timestruc_t *mtimep)
1376*7c478bd9Sstevel@tonic-gate {
1377*7c478bd9Sstevel@tonic-gate 	cachefsio_symlink_arg_t info;
1378*7c478bd9Sstevel@tonic-gate 	cachefsio_symlink_return_t ret;
1379*7c478bd9Sstevel@tonic-gate 	int error = 0;
1380*7c478bd9Sstevel@tonic-gate 	int xx;
1381*7c478bd9Sstevel@tonic-gate 
1382*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_symlink");
1383*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1384*7c478bd9Sstevel@tonic-gate 
1385*7c478bd9Sstevel@tonic-gate 	dbug_precond(dirfidp);
1386*7c478bd9Sstevel@tonic-gate 	dbug_precond(namep);
1387*7c478bd9Sstevel@tonic-gate 	dbug_precond(cidp);
1388*7c478bd9Sstevel@tonic-gate 	dbug_precond(linkvalp);
1389*7c478bd9Sstevel@tonic-gate 	dbug_precond(vattrp);
1390*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1391*7c478bd9Sstevel@tonic-gate 	dbug_precond(newfidp);
1392*7c478bd9Sstevel@tonic-gate 	dbug_precond(ctimep);
1393*7c478bd9Sstevel@tonic-gate 	dbug_precond(mtimep);
1394*7c478bd9Sstevel@tonic-gate 
1395*7c478bd9Sstevel@tonic-gate 	info.sy_dirfid = *dirfidp;
1396*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(namep) < (size_t)MAXNAMELEN);
1397*7c478bd9Sstevel@tonic-gate 	strlcpy(info.sy_name, namep, sizeof (info.sy_name));
1398*7c478bd9Sstevel@tonic-gate 	dbug_assert(strlen(linkvalp) < (size_t)MAXPATHLEN);
1399*7c478bd9Sstevel@tonic-gate 	info.sy_cid = *cidp;
1400*7c478bd9Sstevel@tonic-gate 	strlcpy(info.sy_link, linkvalp, sizeof (info.sy_link));
1401*7c478bd9Sstevel@tonic-gate 	info.sy_vattr = *vattrp;
1402*7c478bd9Sstevel@tonic-gate 	copy_cred(&info.sy_cred, credp);
1403*7c478bd9Sstevel@tonic-gate 
1404*7c478bd9Sstevel@tonic-gate 	xx = kmod_doioctl(kmod_object_p, CFSDCMD_SYMLINK, &info, sizeof (info),
1405*7c478bd9Sstevel@tonic-gate 	    &ret, sizeof (ret));
1406*7c478bd9Sstevel@tonic-gate 	if (xx)
1407*7c478bd9Sstevel@tonic-gate 		error = errno;
1408*7c478bd9Sstevel@tonic-gate 
1409*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "returns %d, error %d", xx, error));
1410*7c478bd9Sstevel@tonic-gate 	kmod_format_fid(kmod_object_p, dirfidp);
1411*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   dir fid '%s'", kmod_object_p->i_fidbuf));
1412*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   name '%s'", namep));
1413*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "   link '%s'", linkvalp));
1414*7c478bd9Sstevel@tonic-gate 	kmod_print_attr(vattrp);
1415*7c478bd9Sstevel@tonic-gate 	kmod_print_cred(credp);
1416*7c478bd9Sstevel@tonic-gate 	if (xx == 0) {
1417*7c478bd9Sstevel@tonic-gate 		*ctimep = ret.sy_ctime;
1418*7c478bd9Sstevel@tonic-gate 		*mtimep = ret.sy_mtime;
1419*7c478bd9Sstevel@tonic-gate 		*newfidp = ret.sy_newfid;
1420*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   ctime %x %x", ctimep->tv_sec,
1421*7c478bd9Sstevel@tonic-gate 		    ctimep->tv_nsec));
1422*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   mtime %x %x", mtimep->tv_sec,
1423*7c478bd9Sstevel@tonic-gate 		    mtimep->tv_nsec));
1424*7c478bd9Sstevel@tonic-gate 		kmod_format_fid(kmod_object_p, newfidp);
1425*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "   child fid '%s'",
1426*7c478bd9Sstevel@tonic-gate 		    kmod_object_p->i_fidbuf));
1427*7c478bd9Sstevel@tonic-gate 	}
1428*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_symlink");
1429*7c478bd9Sstevel@tonic-gate 	return (error);
1430*7c478bd9Sstevel@tonic-gate }
1431*7c478bd9Sstevel@tonic-gate #ifndef DBUG_OFF
1432*7c478bd9Sstevel@tonic-gate /*
1433*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1434*7c478bd9Sstevel@tonic-gate  *			kmod_format_fid
1435*7c478bd9Sstevel@tonic-gate  *
1436*7c478bd9Sstevel@tonic-gate  * Description:
1437*7c478bd9Sstevel@tonic-gate  * Arguments:
1438*7c478bd9Sstevel@tonic-gate  *	fidp
1439*7c478bd9Sstevel@tonic-gate  * Returns:
1440*7c478bd9Sstevel@tonic-gate  * Preconditions:
1441*7c478bd9Sstevel@tonic-gate  *	precond(fidp)
1442*7c478bd9Sstevel@tonic-gate  */
1443*7c478bd9Sstevel@tonic-gate void
kmod_format_fid(cfsd_kmod_object_t * kmod_object_p,const cfs_fid_t * fidp)1444*7c478bd9Sstevel@tonic-gate kmod_format_fid(cfsd_kmod_object_t *kmod_object_p, const cfs_fid_t *fidp)
1445*7c478bd9Sstevel@tonic-gate {
1446*7c478bd9Sstevel@tonic-gate 	uint_t val;
1447*7c478bd9Sstevel@tonic-gate 	int index;
1448*7c478bd9Sstevel@tonic-gate 	char format[10];
1449*7c478bd9Sstevel@tonic-gate 	kmod_object_p->i_fidbuf[0] = '\0';
1450*7c478bd9Sstevel@tonic-gate 
1451*7c478bd9Sstevel@tonic-gate 	for (index = 0; index < (int)fidp->fid_len; index += sizeof (uint_t)) {
1452*7c478bd9Sstevel@tonic-gate 		memcpy(&val, &fidp->fid_data[index], sizeof (uint_t));
1453*7c478bd9Sstevel@tonic-gate 		snprintf(format, sizeof (format), "%08x ", val);
1454*7c478bd9Sstevel@tonic-gate 		strlcat(kmod_object_p->i_fidbuf, format,
1455*7c478bd9Sstevel@tonic-gate 		    sizeof (kmod_object_p->i_fidbuf));
1456*7c478bd9Sstevel@tonic-gate 	}
1457*7c478bd9Sstevel@tonic-gate }
1458*7c478bd9Sstevel@tonic-gate 
1459*7c478bd9Sstevel@tonic-gate /*
1460*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1461*7c478bd9Sstevel@tonic-gate  *			kmod_print_cred
1462*7c478bd9Sstevel@tonic-gate  *
1463*7c478bd9Sstevel@tonic-gate  * Description:
1464*7c478bd9Sstevel@tonic-gate  * Arguments:
1465*7c478bd9Sstevel@tonic-gate  *	credp
1466*7c478bd9Sstevel@tonic-gate  * Returns:
1467*7c478bd9Sstevel@tonic-gate  * Preconditions:
1468*7c478bd9Sstevel@tonic-gate  *	precond(credp)
1469*7c478bd9Sstevel@tonic-gate  */
1470*7c478bd9Sstevel@tonic-gate void
kmod_print_cred(const dl_cred_t * credp)1471*7c478bd9Sstevel@tonic-gate kmod_print_cred(const dl_cred_t *credp)
1472*7c478bd9Sstevel@tonic-gate {
1473*7c478bd9Sstevel@tonic-gate 	char buf[100];
1474*7c478bd9Sstevel@tonic-gate 	char format[10];
1475*7c478bd9Sstevel@tonic-gate 	int xx;
1476*7c478bd9Sstevel@tonic-gate 
1477*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_print_cred");
1478*7c478bd9Sstevel@tonic-gate 	dbug_precond(credp);
1479*7c478bd9Sstevel@tonic-gate 
1480*7c478bd9Sstevel@tonic-gate 	buf[0] = '\0';
1481*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "credentials"));
1482*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "  uid %d, gid %d",
1483*7c478bd9Sstevel@tonic-gate 	    credp->cr_uid, credp->cr_gid));
1484*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "  ruid %d, rgid %d, suid %d, sgid %d",
1485*7c478bd9Sstevel@tonic-gate 	    credp->cr_ruid, credp->cr_rgid,
1486*7c478bd9Sstevel@tonic-gate 	    credp->cr_suid, credp->cr_sgid));
1487*7c478bd9Sstevel@tonic-gate 
1488*7c478bd9Sstevel@tonic-gate 	for (xx = 0; xx < credp->cr_ngroups; xx++) {
1489*7c478bd9Sstevel@tonic-gate 		snprintf(format, sizeof (format), " %d", credp->cr_groups[xx]);
1490*7c478bd9Sstevel@tonic-gate 		strlcat(buf, format, sizeof (buf));
1491*7c478bd9Sstevel@tonic-gate 	}
1492*7c478bd9Sstevel@tonic-gate 
1493*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "  ngroups %d,  %s", credp->cr_ngroups, buf));
1494*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_print_cred");
1495*7c478bd9Sstevel@tonic-gate }
1496*7c478bd9Sstevel@tonic-gate 
1497*7c478bd9Sstevel@tonic-gate /*
1498*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1499*7c478bd9Sstevel@tonic-gate  *			kmod_print_attr
1500*7c478bd9Sstevel@tonic-gate  *
1501*7c478bd9Sstevel@tonic-gate  * Description:
1502*7c478bd9Sstevel@tonic-gate  * Arguments:
1503*7c478bd9Sstevel@tonic-gate  *	vattrp
1504*7c478bd9Sstevel@tonic-gate  * Returns:
1505*7c478bd9Sstevel@tonic-gate  * Preconditions:
1506*7c478bd9Sstevel@tonic-gate  *	precond(vattrp)
1507*7c478bd9Sstevel@tonic-gate  */
1508*7c478bd9Sstevel@tonic-gate void
kmod_print_attr(const vattr_t * vp)1509*7c478bd9Sstevel@tonic-gate kmod_print_attr(const vattr_t *vp)
1510*7c478bd9Sstevel@tonic-gate {
1511*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_print_attr");
1512*7c478bd9Sstevel@tonic-gate 	dbug_precond(vp);
1513*7c478bd9Sstevel@tonic-gate 
1514*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "attributes"));
1515*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "  mask 0x%x", vp->va_mask));
1516*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_TYPE)
1517*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  type %d", vp->va_type));
1518*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_MODE)
1519*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  mode 0%o", vp->va_mode));
1520*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_UID)
1521*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  uid %d", vp->va_uid));
1522*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_GID)
1523*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  gid %d", vp->va_gid));
1524*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_FSID)
1525*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  fsid %08x", vp->va_fsid));
1526*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_NODEID)
1527*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  nodeid %08x", vp->va_nodeid));
1528*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_NLINK)
1529*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  nlink %d", vp->va_nlink));
1530*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_SIZE)
1531*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  size %d", vp->va_size));
1532*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_ATIME)
1533*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  atime %08x %08x",
1534*7c478bd9Sstevel@tonic-gate 		    vp->va_atime.tv_sec, vp->va_atime.tv_nsec));
1535*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_MTIME)
1536*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  mtime %08x %08x",
1537*7c478bd9Sstevel@tonic-gate 		    vp->va_mtime.tv_sec, vp->va_mtime.tv_nsec));
1538*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_CTIME)
1539*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  ctime %08x %08x",
1540*7c478bd9Sstevel@tonic-gate 		    vp->va_ctime.tv_sec, vp->va_ctime.tv_nsec));
1541*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_RDEV)
1542*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  rdev %08x", vp->va_rdev));
1543*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_BLKSIZE)
1544*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  blksize %08x", vp->va_blksize));
1545*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_NBLOCKS)
1546*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  nblocks %d", vp->va_nblocks));
1547*7c478bd9Sstevel@tonic-gate 	if (vp->va_mask & AT_SEQ)
1548*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "  seq %d", vp->va_seq));
1549*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_print_attr");
1550*7c478bd9Sstevel@tonic-gate }
1551*7c478bd9Sstevel@tonic-gate #endif /* DBUG_OFF */
1552*7c478bd9Sstevel@tonic-gate /*
1553*7c478bd9Sstevel@tonic-gate  *			kmod_doioctl
1554*7c478bd9Sstevel@tonic-gate  *
1555*7c478bd9Sstevel@tonic-gate  * Description:
1556*7c478bd9Sstevel@tonic-gate  *	Helper routine for others in this file.  Just packages up
1557*7c478bd9Sstevel@tonic-gate  *	arguments and does the ioctl operation.
1558*7c478bd9Sstevel@tonic-gate  * Arguments:
1559*7c478bd9Sstevel@tonic-gate  *	cmd
1560*7c478bd9Sstevel@tonic-gate  *	sdata
1561*7c478bd9Sstevel@tonic-gate  *	slen
1562*7c478bd9Sstevel@tonic-gate  *	rdata
1563*7c478bd9Sstevel@tonic-gate  *	rlen
1564*7c478bd9Sstevel@tonic-gate  * Returns:
1565*7c478bd9Sstevel@tonic-gate  *	Returns the result of the ioctl operation.
1566*7c478bd9Sstevel@tonic-gate  * Preconditions:
1567*7c478bd9Sstevel@tonic-gate  */
1568*7c478bd9Sstevel@tonic-gate int
kmod_doioctl(cfsd_kmod_object_t * kmod_object_p,enum cfsdcmd_cmds cmd,void * sdata,int slen,void * rdata,int rlen)1569*7c478bd9Sstevel@tonic-gate kmod_doioctl(cfsd_kmod_object_t *kmod_object_p,
1570*7c478bd9Sstevel@tonic-gate 	enum cfsdcmd_cmds cmd,
1571*7c478bd9Sstevel@tonic-gate 	void *sdata,
1572*7c478bd9Sstevel@tonic-gate 	int slen,
1573*7c478bd9Sstevel@tonic-gate 	void *rdata,
1574*7c478bd9Sstevel@tonic-gate 	int rlen)
1575*7c478bd9Sstevel@tonic-gate {
1576*7c478bd9Sstevel@tonic-gate 	cachefsio_dcmd_t dcmd;
1577*7c478bd9Sstevel@tonic-gate 	int xx;
1578*7c478bd9Sstevel@tonic-gate 
1579*7c478bd9Sstevel@tonic-gate 	dbug_enter("kmod_doioctl");
1580*7c478bd9Sstevel@tonic-gate 	dbug_precond(kmod_object_p);
1581*7c478bd9Sstevel@tonic-gate 	dcmd.d_cmd = cmd;
1582*7c478bd9Sstevel@tonic-gate 	dcmd.d_sdata = sdata;
1583*7c478bd9Sstevel@tonic-gate 	dcmd.d_slen = slen;
1584*7c478bd9Sstevel@tonic-gate 	dcmd.d_rdata = rdata;
1585*7c478bd9Sstevel@tonic-gate 	dcmd.d_rlen = rlen;
1586*7c478bd9Sstevel@tonic-gate 	dbug_print(("ioctl", "about to do cmd = %d", cmd));
1587*7c478bd9Sstevel@tonic-gate 	xx = ioctl(kmod_object_p->i_fd, CACHEFSIO_DCMD, &dcmd);
1588*7c478bd9Sstevel@tonic-gate 	if (xx) {
1589*7c478bd9Sstevel@tonic-gate 		dbug_print(("ioctl", "ioctl errno = %d", errno));
1590*7c478bd9Sstevel@tonic-gate 	}
1591*7c478bd9Sstevel@tonic-gate 	dbug_leave("kmod_doioctl");
1592*7c478bd9Sstevel@tonic-gate 	return (xx);
1593*7c478bd9Sstevel@tonic-gate }
1594