xref: /illumos-gate/usr/src/uts/common/io/l_strplumb.c (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn  * Common Development and Distribution License (the "License").
69acbbeafSnn  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include	<sys/param.h>
277c478bd9Sstevel@tonic-gate #include	<sys/types.h>
287c478bd9Sstevel@tonic-gate #include	<sys/user.h>
297c478bd9Sstevel@tonic-gate #include	<sys/vfs.h>
307c478bd9Sstevel@tonic-gate #include	<sys/vnode.h>
317c478bd9Sstevel@tonic-gate #include	<sys/file.h>
327c478bd9Sstevel@tonic-gate #include	<sys/stream.h>
337c478bd9Sstevel@tonic-gate #include	<sys/stropts.h>
347c478bd9Sstevel@tonic-gate #include	<sys/strsubr.h>
357c478bd9Sstevel@tonic-gate #include	<sys/dlpi.h>
367c478bd9Sstevel@tonic-gate #include	<sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include	<sys/socket.h>
387c478bd9Sstevel@tonic-gate #include	<sys/sockio.h>
397c478bd9Sstevel@tonic-gate #include	<sys/cmn_err.h>
407c478bd9Sstevel@tonic-gate #include	<net/if.h>
417c478bd9Sstevel@tonic-gate #include	<sys/sad.h>
427c478bd9Sstevel@tonic-gate #include	<sys/kstr.h>
437c478bd9Sstevel@tonic-gate #include	<sys/ddi.h>
447c478bd9Sstevel@tonic-gate #include	<sys/sunddi.h>
457c478bd9Sstevel@tonic-gate #include	<sys/sunldi.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include	<sys/cred.h>
487c478bd9Sstevel@tonic-gate #include	<sys/sysmacros.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include	<sys/modctl.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Routines to allow strplumb() legitimate access
547c478bd9Sstevel@tonic-gate  * to the kernel.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate int
kstr_open(major_t maj,minor_t min,vnode_t ** vpp,int * fd)577c478bd9Sstevel@tonic-gate kstr_open(major_t maj, minor_t min, vnode_t **vpp, int *fd)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	vnode_t		*vp;
607c478bd9Sstevel@tonic-gate 	int		error;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	vp = makespecvp(makedevice(maj, min), VCHR);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	/*
657c478bd9Sstevel@tonic-gate 	 * Fix for 4170365: only allocate file descriptor entry
667c478bd9Sstevel@tonic-gate 	 * if file descriptor is to be returned; otherwise VOP_OPEN.
677c478bd9Sstevel@tonic-gate 	 */
687c478bd9Sstevel@tonic-gate 	if (fd != NULL)
697c478bd9Sstevel@tonic-gate 		error = fassign(&vp, FREAD|FWRITE, fd);
707c478bd9Sstevel@tonic-gate 	else
71*da6c28aaSamw 		error = VOP_OPEN(&vp, FREAD|FWRITE, CRED(), NULL);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/*
747c478bd9Sstevel@tonic-gate 	 * Must set vpp after calling fassign()/VOP_OPEN()
757c478bd9Sstevel@tonic-gate 	 * since `vp' might change if it's a clone driver.
767c478bd9Sstevel@tonic-gate 	 */
777c478bd9Sstevel@tonic-gate 	if (vpp != NULL)
787c478bd9Sstevel@tonic-gate 		*vpp = vp;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	return (error);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate int
kstr_plink(vnode_t * vp,int fd,int * mux_id)847c478bd9Sstevel@tonic-gate kstr_plink(vnode_t *vp, int fd, int *mux_id)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	int	id;
877c478bd9Sstevel@tonic-gate 	int	error;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if (error = strioctl(vp, I_PLINK, (intptr_t)fd, 0, K_TO_K, CRED(), &id))
907c478bd9Sstevel@tonic-gate 		return (error);
917c478bd9Sstevel@tonic-gate 	if (mux_id)
927c478bd9Sstevel@tonic-gate 		*mux_id = id;
937c478bd9Sstevel@tonic-gate 	return (0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate int
kstr_unplink(vnode_t * vp,int mux_id)977c478bd9Sstevel@tonic-gate kstr_unplink(vnode_t *vp, int mux_id)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	int	rval;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_PUNLINK, (intptr_t)mux_id, 0,
1027c478bd9Sstevel@tonic-gate 	    K_TO_K, CRED(), &rval));
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate int
kstr_push(vnode_t * vp,char * mod)1067c478bd9Sstevel@tonic-gate kstr_push(vnode_t *vp, char *mod)
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate 	int	rval;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_PUSH, (intptr_t)mod, 0, K_TO_K, CRED(), &rval));
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate int
kstr_pop(vnode_t * vp)1147c478bd9Sstevel@tonic-gate kstr_pop(vnode_t *vp)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	int	rval;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_POP, 0, 0, K_TO_K, CRED(), &rval));
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate int
kstr_close(vnode_t * vp,int fd)1227c478bd9Sstevel@tonic-gate kstr_close(vnode_t *vp, int fd)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	int ret;
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	if (vp == (vnode_t *)NULL && fd == -1)
1277c478bd9Sstevel@tonic-gate 		return (EINVAL);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if (fd != -1) {
1307c478bd9Sstevel@tonic-gate 		if (closeandsetf(fd, NULL) == 0) {
1317c478bd9Sstevel@tonic-gate 			return (0);
1327c478bd9Sstevel@tonic-gate 		} else {
1337c478bd9Sstevel@tonic-gate 			return (EINVAL);
1347c478bd9Sstevel@tonic-gate 		}
1357c478bd9Sstevel@tonic-gate 	} else {
136*da6c28aaSamw 		ret = VOP_CLOSE(vp, FREAD|FWRITE, 1, (offset_t)0, CRED(), NULL);
1377c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
1387c478bd9Sstevel@tonic-gate 		return (ret);
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate int
kstr_ioctl(struct vnode * vp,int cmd,intptr_t arg)1437c478bd9Sstevel@tonic-gate kstr_ioctl(struct vnode *vp, int cmd, intptr_t arg)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	int	rval;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	return (strioctl(vp, cmd, arg, 0, K_TO_K, CRED(), &rval));
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Optionally send data (if smp set) and optionally receive data (if rmp is
1527c478bd9Sstevel@tonic-gate  * set). If timeo is NULL the reception will sleep until a message is
1537c478bd9Sstevel@tonic-gate  * received; otherwise the sleep is limited to the specified amount of time.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate int
kstr_msg(vnode_t * vp,mblk_t * smp,mblk_t ** rmp,timestruc_t * timeo)1567c478bd9Sstevel@tonic-gate kstr_msg(vnode_t *vp, mblk_t *smp, mblk_t **rmp, timestruc_t *timeo)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	int			error;
1597c478bd9Sstevel@tonic-gate 	clock_t			timout;	/* milliseconds */
1607c478bd9Sstevel@tonic-gate 	uchar_t 		pri;
1617c478bd9Sstevel@tonic-gate 	int 			pflag;
1627c478bd9Sstevel@tonic-gate 	rval_t			rval;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (rmp == NULL && timeo != NULL &&
1657c478bd9Sstevel@tonic-gate 	    (timeo->tv_sec != 0 || timeo->tv_nsec != 0))
1667c478bd9Sstevel@tonic-gate 		return (EINVAL);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	if (smp == NULL && rmp == NULL)
1697c478bd9Sstevel@tonic-gate 		return (EINVAL);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	if (smp != NULL) {
1727c478bd9Sstevel@tonic-gate 		/* Send message while honoring flow control */
1737c478bd9Sstevel@tonic-gate 		(void) kstrputmsg(vp, smp, NULL, 0, 0,
1747c478bd9Sstevel@tonic-gate 		    MSG_BAND | MSG_HOLDSIG | MSG_IGNERROR, 0);
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (rmp == NULL) {
1787c478bd9Sstevel@tonic-gate 		/* No reply wanted by caller */
1797c478bd9Sstevel@tonic-gate 		return (0);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * Convert from nanoseconds to milliseconds.
1847c478bd9Sstevel@tonic-gate 	 */
1857c478bd9Sstevel@tonic-gate 	if (timeo != NULL) {
1867c478bd9Sstevel@tonic-gate 		timout = timeo->tv_sec * 1000 + timeo->tv_nsec / 1000000;
1877c478bd9Sstevel@tonic-gate 		if (timout > INT_MAX)
1887c478bd9Sstevel@tonic-gate 			return (EINVAL);
1897c478bd9Sstevel@tonic-gate 	} else
1907c478bd9Sstevel@tonic-gate 		timout = -1;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/* Wait for timeout millseconds for a message */
1937c478bd9Sstevel@tonic-gate 	pflag = MSG_ANY;
1947c478bd9Sstevel@tonic-gate 	pri = 0;
1957c478bd9Sstevel@tonic-gate 	*rmp = NULL;
1967c478bd9Sstevel@tonic-gate 	error = kstrgetmsg(vp, rmp, NULL, &pri, &pflag, timout, &rval);
1977c478bd9Sstevel@tonic-gate 	/* Callers use *rmp == NULL to determine that there was a timeout */
1987c478bd9Sstevel@tonic-gate 	if (error == ETIME)
1997c478bd9Sstevel@tonic-gate 		error = 0;
2007c478bd9Sstevel@tonic-gate 	return (error);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #define	SAD_ADM	"/devices/pseudo/sad@0:admin"
2047c478bd9Sstevel@tonic-gate #define	SAD_USR	"/devices/pseudo/sad@0:user"
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * It is the callers responsibility to make sure that "mods"
2087c478bd9Sstevel@tonic-gate  * conforms to what is required. We do not check it here.
2097c478bd9Sstevel@tonic-gate  *
2107c478bd9Sstevel@tonic-gate  * "maj", "min", and "lastmin" are value-result parameters.
2117c478bd9Sstevel@tonic-gate  * for SET_AUTOPUSH, "anchor" should be set to the place in the stream
2127c478bd9Sstevel@tonic-gate  *	to put the anchor, or NULL if no anchor needs to be set.
2137c478bd9Sstevel@tonic-gate  * for GET_AUTOPUSH, "anchor" should point to a uint_t to store the
2147c478bd9Sstevel@tonic-gate  *	position of the anchor at, or NULL if the caller is not interested.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate int
kstr_autopush(int op,major_t * maj,minor_t * min,minor_t * lastmin,uint_t * anchor,char * mods[])2177c478bd9Sstevel@tonic-gate kstr_autopush(int op, major_t *maj, minor_t *min, minor_t *lastmin,
2187c478bd9Sstevel@tonic-gate     uint_t *anchor, char *mods[])
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate 	ldi_handle_t	lh;
2217c478bd9Sstevel@tonic-gate 	ldi_ident_t	li;
2227c478bd9Sstevel@tonic-gate 	struct strapush	push;
2237c478bd9Sstevel@tonic-gate 	int		i, error, rval;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	li = ldi_ident_from_anon();
2267c478bd9Sstevel@tonic-gate 	if (op == SET_AUTOPUSH || op == CLR_AUTOPUSH) {
2277c478bd9Sstevel@tonic-gate 		error = ldi_open_by_name(SAD_ADM, FREAD|FWRITE,
2289acbbeafSnn 		    kcred, &lh, li);
2297c478bd9Sstevel@tonic-gate 		if (error) {
2307c478bd9Sstevel@tonic-gate 			printf("kstr_autopush: open failed error %d\n", error);
2317c478bd9Sstevel@tonic-gate 			ldi_ident_release(li);
2327c478bd9Sstevel@tonic-gate 			return (error);
2337c478bd9Sstevel@tonic-gate 		}
2347c478bd9Sstevel@tonic-gate 	} else	{
2357c478bd9Sstevel@tonic-gate 		error = ldi_open_by_name(SAD_USR, FREAD|FWRITE,
2369acbbeafSnn 		    kcred, &lh, li);
2377c478bd9Sstevel@tonic-gate 		if (error) {
2387c478bd9Sstevel@tonic-gate 			printf("kstr_autopush: open failed error %d\n", error);
2397c478bd9Sstevel@tonic-gate 			ldi_ident_release(li);
2407c478bd9Sstevel@tonic-gate 			return (error);
2417c478bd9Sstevel@tonic-gate 		}
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 	ldi_ident_release(li);
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	switch (op) {
2467c478bd9Sstevel@tonic-gate 	case GET_AUTOPUSH:
2477c478bd9Sstevel@tonic-gate 		/* Get autopush information */
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
2507c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_GAP, (intptr_t)&push,
2539acbbeafSnn 		    FKIOCTL, kcred, &rval);
2547c478bd9Sstevel@tonic-gate 		if (error) {
2551110f384Sedp 			printf("kstr_autopush: "
2561110f384Sedp 			    "ioctl(GET_AUTOPUSH) failed, error %d\n", error);
2579acbbeafSnn 			(void) ldi_close(lh, FREAD|FWRITE, kcred);
2587c478bd9Sstevel@tonic-gate 			return (error);
2597c478bd9Sstevel@tonic-gate 		}
2607c478bd9Sstevel@tonic-gate 		switch (push.sap_cmd) {
2617c478bd9Sstevel@tonic-gate 		case SAP_ONE:
2627c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2637c478bd9Sstevel@tonic-gate 			*min = push.sap_minor;
2647c478bd9Sstevel@tonic-gate 			*lastmin = 0;
2657c478bd9Sstevel@tonic-gate 			break;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 		case SAP_RANGE:
2687c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2697c478bd9Sstevel@tonic-gate 			*min = push.sap_minor;
2707c478bd9Sstevel@tonic-gate 			*lastmin = push.sap_lastminor;
2717c478bd9Sstevel@tonic-gate 			break;
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 		case SAP_ALL:
2747c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2757c478bd9Sstevel@tonic-gate 			*min = (minor_t)-1;
2767c478bd9Sstevel@tonic-gate 			break;
2777c478bd9Sstevel@tonic-gate 		}
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		if (anchor != NULL)
2807c478bd9Sstevel@tonic-gate 			*anchor = push.sap_anchor;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		if (push.sap_npush > 1) {
2837c478bd9Sstevel@tonic-gate 			for (i = 0; i < push.sap_npush &&
2847c478bd9Sstevel@tonic-gate 			    mods[i] != NULL; i++)
2857c478bd9Sstevel@tonic-gate 				(void) strcpy(mods[i], push.sap_list[i]);
2867c478bd9Sstevel@tonic-gate 			mods[i] = NULL;
2877c478bd9Sstevel@tonic-gate 		}
2889acbbeafSnn 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
2897c478bd9Sstevel@tonic-gate 		return (0);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	case CLR_AUTOPUSH:
2927c478bd9Sstevel@tonic-gate 		/* Remove autopush information */
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 		push.sap_cmd = SAP_CLEAR;
2957c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
2967c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_SAP, (intptr_t)&push,
2999acbbeafSnn 		    FKIOCTL, kcred, &rval);
3007c478bd9Sstevel@tonic-gate 		if (error) {
3011110f384Sedp 			printf("kstr_autopush: "
3021110f384Sedp 			    "ioctl(CLR_AUTOPUSH) failed, error %d\n", error);
3037c478bd9Sstevel@tonic-gate 		}
3049acbbeafSnn 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3057c478bd9Sstevel@tonic-gate 		return (error);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	case SET_AUTOPUSH:
3087c478bd9Sstevel@tonic-gate 		/* Set autopush information */
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 		if (*min == (minor_t)-1) {
3117c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_ALL;
3127c478bd9Sstevel@tonic-gate 		} else if (*lastmin == 0) {
3137c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_ONE;
3147c478bd9Sstevel@tonic-gate 		} else	{
3157c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_RANGE;
3167c478bd9Sstevel@tonic-gate 		}
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		if (anchor != NULL)
3197c478bd9Sstevel@tonic-gate 			push.sap_anchor = *anchor;
3207c478bd9Sstevel@tonic-gate 		else
3217c478bd9Sstevel@tonic-gate 			push.sap_anchor = 0;
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
3247c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
3257c478bd9Sstevel@tonic-gate 		if (lastmin)
3267c478bd9Sstevel@tonic-gate 			push.sap_lastminor = *lastmin;
3277c478bd9Sstevel@tonic-gate 		else
3287c478bd9Sstevel@tonic-gate 			push.sap_lastminor = 0;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 		/* pain */
3317c478bd9Sstevel@tonic-gate 		for (i = 0; i < MAXAPUSH && mods[i] != (char *)NULL; i++) {
3327c478bd9Sstevel@tonic-gate 			(void) strcpy(push.sap_list[i], mods[i]);
3337c478bd9Sstevel@tonic-gate 		}
3347c478bd9Sstevel@tonic-gate 		push.sap_npush = i;
3357c478bd9Sstevel@tonic-gate 		push.sap_list[i][0] = '\0';
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_SAP, (intptr_t)&push,
3389acbbeafSnn 		    FKIOCTL, kcred, &rval);
3397c478bd9Sstevel@tonic-gate 		if (error) {
3401110f384Sedp 			printf("kstr_autopush: "
3411110f384Sedp 			    "ioctl(SET_AUTOPUSH) failed, error %d\n", error);
3427c478bd9Sstevel@tonic-gate 		}
3439acbbeafSnn 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3447c478bd9Sstevel@tonic-gate 		return (error);
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	default:
3479acbbeafSnn 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3487c478bd9Sstevel@tonic-gate 		return (EINVAL);
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate }
351