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