if (nswapdev == rootdev) nswapdev = NODEV;
setroot(){	register struct swdevt *swp;	register struct device *dv;	register int len, majdev, unit, part;	dev_t nrootdev, nswapdev = NODEV;	char buf[128];	dev_t temp;	struct mountroot_hook *mrhp;	struct device *bootdv;	struct bootpath *bp;#if defined(NFSCLIENT)	extern char *nfsbootdevname;#endif	bp = nbootpath == 0 ? NULL : &bootpath[nbootpath-1];	bootdv = bp == NULL ? NULL : bp->dev;	/*	 * If `swap generic' and we couldn't determine boot device,	 * ask the user.	 */	if (mountroot == NULL && bootdv == NULL)		boothowto |= RB_ASKNAME;	if (boothowto & RB_ASKNAME) {		for (;;) {			printf("root device ");			if (bootdv != NULL)				printf("(default %s%c)",					bootdv->dv_xname,					bootdv->dv_class == DV_DISK						? bp->val[2]+'a' : ' ');			printf(": ");			len = getstr(buf, sizeof(buf));			if (len == 0 && bootdv != NULL) {				strcpy(buf, bootdv->dv_xname);				len = strlen(buf);			}			if (len > 0 && buf[len - 1] == '*') {				buf[--len] = '\0';				dv = getdisk(buf, len, 1, &nrootdev);				if (dv != NULL) {					bootdv = dv;					nswapdev = nrootdev;					goto gotswap;				}			}			dv = getdisk(buf, len, bp?bp->val[2]:0, &nrootdev);			if (dv != NULL) {				bootdv = dv;				break;			}		}		/*		 * because swap must be on same device as root, for		 * network devices this is easy.		 */		if (bootdv->dv_class == DV_IFNET) {			goto gotswap;		}		for (;;) {			printf("swap device ");			if (bootdv != NULL)				printf("(default %s%c)",					bootdv->dv_xname,					bootdv->dv_class == DV_DISK?'b':' ');			printf(": ");			len = getstr(buf, sizeof(buf));			if (len == 0 && bootdv != NULL) {				switch (bootdv->dv_class) {				case DV_IFNET:					nswapdev = NODEV;					break;				case DV_DISK:					nswapdev = MAKEDISKDEV(major(nrootdev),					    DISKUNIT(nrootdev), 1);					break;				case DV_TAPE:				case DV_TTY:				case DV_DULL:				case DV_CPU:					break;				}				break;			}			dv = getdisk(buf, len, 1, &nswapdev);			if (dv) {				if (dv->dv_class == DV_IFNET)					nswapdev = NODEV;				break;			}		}gotswap:		rootdev = nrootdev;		dumpdev = nswapdev;		swdevt[0].sw_dev = nswapdev;		swdevt[1].sw_dev = NODEV;	} else if (mountroot == NULL) {		/*		 * `swap generic': Use the device the ROM told us to use.		 */		majdev = findblkmajor(bootdv);		if (majdev >= 0) {			/*			 * Root and swap are on a disk.			 * val[2] of the boot device is the partition number.			 * Assume swap is on partition b.			 */			part = bp->val[2];			unit = bootdv->dv_unit;			rootdev = MAKEDISKDEV(majdev, unit, part);			nswapdev = dumpdev = MAKEDISKDEV(major(rootdev),			    DISKUNIT(rootdev), 1);		} else {			/*			 * Root and swap are on a net.			 */			nswapdev = dumpdev = NODEV;		}		if (nswapdev == rootdev)			nswapdev = NODEV;		swdevt[0].sw_dev = nswapdev;		swdevt[1].sw_dev = NODEV;	} else {		/*		 * `root DEV swap DEV': honour rootdev/swdevt.		 * rootdev/swdevt/mountroot already properly set.		 */		majdev = major(rootdev);		unit = DISKUNIT(rootdev);		part = DISKPART(rootdev);		goto gotroot;	}	switch (bootdv->dv_class) {#if defined(NFSCLIENT)	case DV_IFNET:		mountroot = nfs_mountroot;		nfsbootdevname = bootdv->dv_xname;		return;#endif	case DV_DISK:		mountroot = dk_mountroot;		majdev = major(rootdev);		unit = DISKUNIT(rootdev);		part = DISKPART(rootdev);		printf("root on %s%c\n", bootdv->dv_xname,		    part + 'a');		break;	default:		printf("can't figure root, hope your kernel is right\n");		return;	}	/*	 * Make the swap partition on the root drive the primary swap.	 */	temp = NODEV;	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {		if (majdev == major(swp->sw_dev) &&		    unit == DISKUNIT(swp->sw_dev)) {			temp = swdevt[0].sw_dev;			swdevt[0].sw_dev = swp->sw_dev;			swp->sw_dev = temp;			break;		}	}	if (swp->sw_dev != NODEV) {		/*		 * If dumpdev was the same as the old primary swap device,		 * move it to the new primary swap device.		 */		if (temp == dumpdev)			dumpdev = swdevt[0].sw_dev;	}gotroot:	/*	 * Find mountroot hook and execute.	 */	for (mrhp = mrh_list.lh_first; mrhp != NULL;	     mrhp = mrhp->mr_link.le_next)		if (mrhp->mr_device == bootdv) {			(*mrhp->mr_func)(bootdv);			break;		}}