xref: /titanic_50/usr/src/uts/common/io/l_strplumb.c (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
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
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include	<sys/param.h>
297c478bd9Sstevel@tonic-gate #include	<sys/types.h>
307c478bd9Sstevel@tonic-gate #include	<sys/user.h>
317c478bd9Sstevel@tonic-gate #include	<sys/vfs.h>
327c478bd9Sstevel@tonic-gate #include	<sys/vnode.h>
337c478bd9Sstevel@tonic-gate #include	<sys/file.h>
347c478bd9Sstevel@tonic-gate #include	<sys/stream.h>
357c478bd9Sstevel@tonic-gate #include	<sys/stropts.h>
367c478bd9Sstevel@tonic-gate #include	<sys/strsubr.h>
377c478bd9Sstevel@tonic-gate #include	<sys/dlpi.h>
387c478bd9Sstevel@tonic-gate #include	<sys/vnode.h>
397c478bd9Sstevel@tonic-gate #include	<sys/socket.h>
407c478bd9Sstevel@tonic-gate #include	<sys/sockio.h>
417c478bd9Sstevel@tonic-gate #include	<sys/cmn_err.h>
427c478bd9Sstevel@tonic-gate #include	<net/if.h>
437c478bd9Sstevel@tonic-gate #include	<sys/sad.h>
447c478bd9Sstevel@tonic-gate #include	<sys/kstr.h>
457c478bd9Sstevel@tonic-gate #include	<sys/ddi.h>
467c478bd9Sstevel@tonic-gate #include	<sys/sunddi.h>
477c478bd9Sstevel@tonic-gate #include	<sys/sunldi.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include	<sys/cred.h>
507c478bd9Sstevel@tonic-gate #include	<sys/sysmacros.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include	<sys/modctl.h>
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Routines to allow strplumb() legitimate access
567c478bd9Sstevel@tonic-gate  * to the kernel.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate int
kstr_open(major_t maj,minor_t min,vnode_t ** vpp,int * fd)597c478bd9Sstevel@tonic-gate kstr_open(major_t maj, minor_t min, vnode_t **vpp, int *fd)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	vnode_t		*vp;
627c478bd9Sstevel@tonic-gate 	int		error;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	vp = makespecvp(makedevice(maj, min), VCHR);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/*
677c478bd9Sstevel@tonic-gate 	 * Fix for 4170365: only allocate file descriptor entry
687c478bd9Sstevel@tonic-gate 	 * if file descriptor is to be returned; otherwise VOP_OPEN.
697c478bd9Sstevel@tonic-gate 	 */
707c478bd9Sstevel@tonic-gate 	if (fd != NULL)
717c478bd9Sstevel@tonic-gate 		error = fassign(&vp, FREAD|FWRITE, fd);
727c478bd9Sstevel@tonic-gate 	else
73*da6c28aaSamw 		error = VOP_OPEN(&vp, FREAD|FWRITE, CRED(), NULL);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	/*
767c478bd9Sstevel@tonic-gate 	 * Must set vpp after calling fassign()/VOP_OPEN()
777c478bd9Sstevel@tonic-gate 	 * since `vp' might change if it's a clone driver.
787c478bd9Sstevel@tonic-gate 	 */
797c478bd9Sstevel@tonic-gate 	if (vpp != NULL)
807c478bd9Sstevel@tonic-gate 		*vpp = vp;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	return (error);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate int
kstr_plink(vnode_t * vp,int fd,int * mux_id)867c478bd9Sstevel@tonic-gate kstr_plink(vnode_t *vp, int fd, int *mux_id)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate 	int	id;
897c478bd9Sstevel@tonic-gate 	int	error;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	if (error = strioctl(vp, I_PLINK, (intptr_t)fd, 0, K_TO_K, CRED(), &id))
927c478bd9Sstevel@tonic-gate 		return (error);
937c478bd9Sstevel@tonic-gate 	if (mux_id)
947c478bd9Sstevel@tonic-gate 		*mux_id = id;
957c478bd9Sstevel@tonic-gate 	return (0);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate int
kstr_unplink(vnode_t * vp,int mux_id)997c478bd9Sstevel@tonic-gate kstr_unplink(vnode_t *vp, int mux_id)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	int	rval;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_PUNLINK, (intptr_t)mux_id, 0,
1047c478bd9Sstevel@tonic-gate 	    K_TO_K, CRED(), &rval));
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate int
kstr_push(vnode_t * vp,char * mod)1087c478bd9Sstevel@tonic-gate kstr_push(vnode_t *vp, char *mod)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate 	int	rval;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_PUSH, (intptr_t)mod, 0, K_TO_K, CRED(), &rval));
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate int
kstr_pop(vnode_t * vp)1167c478bd9Sstevel@tonic-gate kstr_pop(vnode_t *vp)
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate 	int	rval;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	return (strioctl(vp, I_POP, 0, 0, K_TO_K, CRED(), &rval));
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate int
kstr_close(vnode_t * vp,int fd)1247c478bd9Sstevel@tonic-gate kstr_close(vnode_t *vp, int fd)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	int ret;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	if (vp == (vnode_t *)NULL && fd == -1)
1297c478bd9Sstevel@tonic-gate 		return (EINVAL);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	if (fd != -1) {
1327c478bd9Sstevel@tonic-gate 		if (closeandsetf(fd, NULL) == 0) {
1337c478bd9Sstevel@tonic-gate 			return (0);
1347c478bd9Sstevel@tonic-gate 		} else {
1357c478bd9Sstevel@tonic-gate 			return (EINVAL);
1367c478bd9Sstevel@tonic-gate 		}
1377c478bd9Sstevel@tonic-gate 	} else {
138*da6c28aaSamw 		ret = VOP_CLOSE(vp, FREAD|FWRITE, 1, (offset_t)0, CRED(), NULL);
1397c478bd9Sstevel@tonic-gate 		VN_RELE(vp);
1407c478bd9Sstevel@tonic-gate 		return (ret);
1417c478bd9Sstevel@tonic-gate 	}
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate int
kstr_ioctl(struct vnode * vp,int cmd,intptr_t arg)1457c478bd9Sstevel@tonic-gate kstr_ioctl(struct vnode *vp, int cmd, intptr_t arg)
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate 	int	rval;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	return (strioctl(vp, cmd, arg, 0, K_TO_K, CRED(), &rval));
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * Optionally send data (if smp set) and optionally receive data (if rmp is
1547c478bd9Sstevel@tonic-gate  * set). If timeo is NULL the reception will sleep until a message is
1557c478bd9Sstevel@tonic-gate  * received; otherwise the sleep is limited to the specified amount of time.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate int
kstr_msg(vnode_t * vp,mblk_t * smp,mblk_t ** rmp,timestruc_t * timeo)1587c478bd9Sstevel@tonic-gate kstr_msg(vnode_t *vp, mblk_t *smp, mblk_t **rmp, timestruc_t *timeo)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	int			error;
1617c478bd9Sstevel@tonic-gate 	clock_t			timout;	/* milliseconds */
1627c478bd9Sstevel@tonic-gate 	uchar_t 		pri;
1637c478bd9Sstevel@tonic-gate 	int 			pflag;
1647c478bd9Sstevel@tonic-gate 	rval_t			rval;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	if (rmp == NULL && timeo != NULL &&
1677c478bd9Sstevel@tonic-gate 	    (timeo->tv_sec != 0 || timeo->tv_nsec != 0))
1687c478bd9Sstevel@tonic-gate 		return (EINVAL);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	if (smp == NULL && rmp == NULL)
1717c478bd9Sstevel@tonic-gate 		return (EINVAL);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	if (smp != NULL) {
1747c478bd9Sstevel@tonic-gate 		/* Send message while honoring flow control */
1757c478bd9Sstevel@tonic-gate 		(void) kstrputmsg(vp, smp, NULL, 0, 0,
1767c478bd9Sstevel@tonic-gate 		    MSG_BAND | MSG_HOLDSIG | MSG_IGNERROR, 0);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (rmp == NULL) {
1807c478bd9Sstevel@tonic-gate 		/* No reply wanted by caller */
1817c478bd9Sstevel@tonic-gate 		return (0);
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	/*
1857c478bd9Sstevel@tonic-gate 	 * Convert from nanoseconds to milliseconds.
1867c478bd9Sstevel@tonic-gate 	 */
1877c478bd9Sstevel@tonic-gate 	if (timeo != NULL) {
1887c478bd9Sstevel@tonic-gate 		timout = timeo->tv_sec * 1000 + timeo->tv_nsec / 1000000;
1897c478bd9Sstevel@tonic-gate 		if (timout > INT_MAX)
1907c478bd9Sstevel@tonic-gate 			return (EINVAL);
1917c478bd9Sstevel@tonic-gate 	} else
1927c478bd9Sstevel@tonic-gate 		timout = -1;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/* Wait for timeout millseconds for a message */
1957c478bd9Sstevel@tonic-gate 	pflag = MSG_ANY;
1967c478bd9Sstevel@tonic-gate 	pri = 0;
1977c478bd9Sstevel@tonic-gate 	*rmp = NULL;
1987c478bd9Sstevel@tonic-gate 	error = kstrgetmsg(vp, rmp, NULL, &pri, &pflag, timout, &rval);
1997c478bd9Sstevel@tonic-gate 	/* Callers use *rmp == NULL to determine that there was a timeout */
2007c478bd9Sstevel@tonic-gate 	if (error == ETIME)
2017c478bd9Sstevel@tonic-gate 		error = 0;
2027c478bd9Sstevel@tonic-gate 	return (error);
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define	SAD_ADM	"/devices/pseudo/sad@0:admin"
2067c478bd9Sstevel@tonic-gate #define	SAD_USR	"/devices/pseudo/sad@0:user"
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * It is the callers responsibility to make sure that "mods"
2107c478bd9Sstevel@tonic-gate  * conforms to what is required. We do not check it here.
2117c478bd9Sstevel@tonic-gate  *
2127c478bd9Sstevel@tonic-gate  * "maj", "min", and "lastmin" are value-result parameters.
2137c478bd9Sstevel@tonic-gate  * for SET_AUTOPUSH, "anchor" should be set to the place in the stream
2147c478bd9Sstevel@tonic-gate  *	to put the anchor, or NULL if no anchor needs to be set.
2157c478bd9Sstevel@tonic-gate  * for GET_AUTOPUSH, "anchor" should point to a uint_t to store the
2167c478bd9Sstevel@tonic-gate  *	position of the anchor at, or NULL if the caller is not interested.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate int
kstr_autopush(int op,major_t * maj,minor_t * min,minor_t * lastmin,uint_t * anchor,char * mods[])2197c478bd9Sstevel@tonic-gate kstr_autopush(int op, major_t *maj, minor_t *min, minor_t *lastmin,
2207c478bd9Sstevel@tonic-gate     uint_t *anchor, char *mods[])
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate 	ldi_handle_t	lh;
2237c478bd9Sstevel@tonic-gate 	ldi_ident_t	li;
2247c478bd9Sstevel@tonic-gate 	struct strapush	push;
2257c478bd9Sstevel@tonic-gate 	int		i, error, rval;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	li = ldi_ident_from_anon();
2287c478bd9Sstevel@tonic-gate 	if (op == SET_AUTOPUSH || op == CLR_AUTOPUSH) {
2297c478bd9Sstevel@tonic-gate 		error = ldi_open_by_name(SAD_ADM, FREAD|FWRITE,
2309acbbeafSnn35248 		    kcred, &lh, li);
2317c478bd9Sstevel@tonic-gate 		if (error) {
2327c478bd9Sstevel@tonic-gate 			printf("kstr_autopush: open failed error %d\n", error);
2337c478bd9Sstevel@tonic-gate 			ldi_ident_release(li);
2347c478bd9Sstevel@tonic-gate 			return (error);
2357c478bd9Sstevel@tonic-gate 		}
2367c478bd9Sstevel@tonic-gate 	} else	{
2377c478bd9Sstevel@tonic-gate 		error = ldi_open_by_name(SAD_USR, FREAD|FWRITE,
2389acbbeafSnn35248 		    kcred, &lh, li);
2397c478bd9Sstevel@tonic-gate 		if (error) {
2407c478bd9Sstevel@tonic-gate 			printf("kstr_autopush: open failed error %d\n", error);
2417c478bd9Sstevel@tonic-gate 			ldi_ident_release(li);
2427c478bd9Sstevel@tonic-gate 			return (error);
2437c478bd9Sstevel@tonic-gate 		}
2447c478bd9Sstevel@tonic-gate 	}
2457c478bd9Sstevel@tonic-gate 	ldi_ident_release(li);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	switch (op) {
2487c478bd9Sstevel@tonic-gate 	case GET_AUTOPUSH:
2497c478bd9Sstevel@tonic-gate 		/* Get autopush information */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
2527c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_GAP, (intptr_t)&push,
2559acbbeafSnn35248 		    FKIOCTL, kcred, &rval);
2567c478bd9Sstevel@tonic-gate 		if (error) {
2571110f384Sedp 			printf("kstr_autopush: "
2581110f384Sedp 			    "ioctl(GET_AUTOPUSH) failed, error %d\n", error);
2599acbbeafSnn35248 			(void) ldi_close(lh, FREAD|FWRITE, kcred);
2607c478bd9Sstevel@tonic-gate 			return (error);
2617c478bd9Sstevel@tonic-gate 		}
2627c478bd9Sstevel@tonic-gate 		switch (push.sap_cmd) {
2637c478bd9Sstevel@tonic-gate 		case SAP_ONE:
2647c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2657c478bd9Sstevel@tonic-gate 			*min = push.sap_minor;
2667c478bd9Sstevel@tonic-gate 			*lastmin = 0;
2677c478bd9Sstevel@tonic-gate 			break;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		case SAP_RANGE:
2707c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2717c478bd9Sstevel@tonic-gate 			*min = push.sap_minor;
2727c478bd9Sstevel@tonic-gate 			*lastmin = push.sap_lastminor;
2737c478bd9Sstevel@tonic-gate 			break;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 		case SAP_ALL:
2767c478bd9Sstevel@tonic-gate 			*maj = push.sap_major;
2777c478bd9Sstevel@tonic-gate 			*min = (minor_t)-1;
2787c478bd9Sstevel@tonic-gate 			break;
2797c478bd9Sstevel@tonic-gate 		}
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 		if (anchor != NULL)
2827c478bd9Sstevel@tonic-gate 			*anchor = push.sap_anchor;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		if (push.sap_npush > 1) {
2857c478bd9Sstevel@tonic-gate 			for (i = 0; i < push.sap_npush &&
2867c478bd9Sstevel@tonic-gate 			    mods[i] != NULL; i++)
2877c478bd9Sstevel@tonic-gate 				(void) strcpy(mods[i], push.sap_list[i]);
2887c478bd9Sstevel@tonic-gate 			mods[i] = NULL;
2897c478bd9Sstevel@tonic-gate 		}
2909acbbeafSnn35248 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
2917c478bd9Sstevel@tonic-gate 		return (0);
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	case CLR_AUTOPUSH:
2947c478bd9Sstevel@tonic-gate 		/* Remove autopush information */
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 		push.sap_cmd = SAP_CLEAR;
2977c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
2987c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_SAP, (intptr_t)&push,
3019acbbeafSnn35248 		    FKIOCTL, kcred, &rval);
3027c478bd9Sstevel@tonic-gate 		if (error) {
3031110f384Sedp 			printf("kstr_autopush: "
3041110f384Sedp 			    "ioctl(CLR_AUTOPUSH) failed, error %d\n", error);
3057c478bd9Sstevel@tonic-gate 		}
3069acbbeafSnn35248 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3077c478bd9Sstevel@tonic-gate 		return (error);
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	case SET_AUTOPUSH:
3107c478bd9Sstevel@tonic-gate 		/* Set autopush information */
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		if (*min == (minor_t)-1) {
3137c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_ALL;
3147c478bd9Sstevel@tonic-gate 		} else if (*lastmin == 0) {
3157c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_ONE;
3167c478bd9Sstevel@tonic-gate 		} else	{
3177c478bd9Sstevel@tonic-gate 			push.sap_cmd = SAP_RANGE;
3187c478bd9Sstevel@tonic-gate 		}
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		if (anchor != NULL)
3217c478bd9Sstevel@tonic-gate 			push.sap_anchor = *anchor;
3227c478bd9Sstevel@tonic-gate 		else
3237c478bd9Sstevel@tonic-gate 			push.sap_anchor = 0;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 		push.sap_minor = *min;
3267c478bd9Sstevel@tonic-gate 		push.sap_major = *maj;
3277c478bd9Sstevel@tonic-gate 		if (lastmin)
3287c478bd9Sstevel@tonic-gate 			push.sap_lastminor = *lastmin;
3297c478bd9Sstevel@tonic-gate 		else
3307c478bd9Sstevel@tonic-gate 			push.sap_lastminor = 0;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 		/* pain */
3337c478bd9Sstevel@tonic-gate 		for (i = 0; i < MAXAPUSH && mods[i] != (char *)NULL; i++) {
3347c478bd9Sstevel@tonic-gate 			(void) strcpy(push.sap_list[i], mods[i]);
3357c478bd9Sstevel@tonic-gate 		}
3367c478bd9Sstevel@tonic-gate 		push.sap_npush = i;
3377c478bd9Sstevel@tonic-gate 		push.sap_list[i][0] = '\0';
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 		error = ldi_ioctl(lh, SAD_SAP, (intptr_t)&push,
3409acbbeafSnn35248 		    FKIOCTL, kcred, &rval);
3417c478bd9Sstevel@tonic-gate 		if (error) {
3421110f384Sedp 			printf("kstr_autopush: "
3431110f384Sedp 			    "ioctl(SET_AUTOPUSH) failed, error %d\n", error);
3447c478bd9Sstevel@tonic-gate 		}
3459acbbeafSnn35248 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3467c478bd9Sstevel@tonic-gate 		return (error);
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	default:
3499acbbeafSnn35248 		(void) ldi_close(lh, FREAD|FWRITE, kcred);
3507c478bd9Sstevel@tonic-gate 		return (EINVAL);
3517c478bd9Sstevel@tonic-gate 	}
3527c478bd9Sstevel@tonic-gate }
353