lp->d_npartitions = max(RAW_PART, i - 1) + 1;
lp->d_npartitions = max((RAW_PART + 1), i);
cdgetdisklabel(dev, cd, lp, clp, spoofonly)	dev_t dev;	struct cd_softc *cd;	struct disklabel *lp;	struct cpu_disklabel *clp;	int spoofonly;{	char *errstring;	u_int8_t hdr[TOC_HEADER_SZ],  *ent, *toc = NULL;	u_int32_t lba, nlba;	int tocidx, i, n, len, is_data, data_track = -1;	int toc_valid = 0;	bzero(lp, sizeof(struct disklabel));	bzero(clp, sizeof(struct cpu_disklabel));	lp->d_secsize = cd->params.blksize;	lp->d_ntracks = 1;	lp->d_nsectors = 100;	lp->d_ncylinders = (cd->params.disksize / 100) + 1;	lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;	if (lp->d_secpercyl == 0) {		lp->d_secpercyl = 100;		/* as long as it's not 0 - readdisklabel divides by it */	}	if (cd->sc_link->flags & SDEV_ATAPI) {		strncpy(lp->d_typename, "ATAPI CD-ROM", sizeof(lp->d_typename) - 1);		lp->d_type = DTYPE_ATAPI;	} else {		strncpy(lp->d_typename, "SCSI CD-ROM", sizeof(lp->d_typename) - 1);		lp->d_type = DTYPE_SCSI;	}	strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname) - 1);	lp->d_secperunit = cd->params.disksize;	lp->d_rpm = 300;	lp->d_interleave = 1;	lp->d_flags = D_REMOVABLE;	/* XXX - these values for BBSIZE and SBSIZE assume ffs */	lp->d_bbsize = BBSIZE;	lp->d_sbsize = SBSIZE;	lp->d_magic = DISKMAGIC;	lp->d_magic2 = DISKMAGIC;	lp->d_checksum = dkcksum(lp);	/* The raw partition is special.  */	lp->d_partitions[RAW_PART].p_offset = 0;	lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;	lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;	lp->d_npartitions = RAW_PART + 1;	/*	 * Read the TOC and loop throught the individual tracks and lay them	 * out in our disklabel.  If there is a data track, call the generic	 * disklabel read routine.  XXX should we move all data tracks up front	 * before any other tracks?	 */	bzero(hdr, sizeof(hdr));	if (cd_read_toc(cd, 0, 0, hdr, TOC_HEADER_SZ, 0))		goto done;	n = hdr[TOC_HEADER_ENDING_TRACK] - hdr[TOC_HEADER_STARTING_TRACK] + 1;	if (n <= 0)		goto done;	/* n + 1 because of leadout track */	len = TOC_HEADER_SZ + (n + 1) * TOC_ENTRY_SZ;	MALLOC(toc, u_int8_t *, len, M_TEMP, M_WAITOK);	if (cd_read_toc (cd, CD_LBA_FORMAT, 0, toc, len, 0))		goto done;	/* Create the partition table.  */	/* Probably should sanity-check the drive's values */	toc_valid = 1;  	ent = toc + TOC_HEADER_SZ;	lba = ((cd->sc_link->quirks & ADEV_LITTLETOC) ?	    ent[TOC_ENTRY_MSF_LBA] | ent[TOC_ENTRY_MSF_LBA + 1] << 8 |	    ent[TOC_ENTRY_MSF_LBA + 2] << 16 |	    ent[TOC_ENTRY_MSF_LBA + 3] << 24 :	    ent[TOC_ENTRY_MSF_LBA] << 24 | ent[TOC_ENTRY_MSF_LBA + 1] << 16 |	    ent[TOC_ENTRY_MSF_LBA + 2] << 8 | ent[TOC_ENTRY_MSF_LBA + 3]);	i = 0;	for (tocidx = 1; tocidx <= n; tocidx++) {		is_data = ent[TOC_ENTRY_CONTROL_ADDR_TYPE] & 4;		ent += TOC_ENTRY_SZ;		nlba = ((cd->sc_link->quirks & ADEV_LITTLETOC) ?			ent[TOC_ENTRY_MSF_LBA] |			ent[TOC_ENTRY_MSF_LBA + 1] << 8 |			ent[TOC_ENTRY_MSF_LBA + 2] << 16 |			ent[TOC_ENTRY_MSF_LBA + 3] << 24 :			ent[TOC_ENTRY_MSF_LBA] << 24 |			ent[TOC_ENTRY_MSF_LBA + 1] << 16 |			ent[TOC_ENTRY_MSF_LBA + 2] << 8 |			ent[TOC_ENTRY_MSF_LBA + 3]);		lp->d_partitions[i].p_fstype =			is_data ? FS_UNUSED : FS_OTHER;		lp->d_partitions[i].p_offset = lba;		lp->d_partitions[i].p_size = nlba - lba;		lba = nlba;		if (is_data) { 			if (data_track == -1)				data_track = i;			i++;			if (i == RAW_PART)				i++;			if (i >= MAXPARTITIONS)				break;		}	}	if (i < MAXPARTITIONS)		bzero(&lp->d_partitions[i], sizeof(lp->d_partitions[i]));	lp->d_npartitions = max(RAW_PART, i - 1) + 1;done:	if (toc)		FREE(toc, M_TEMP);	/* We have a data track, look in there for a real disklabel.  */	if (data_track != -1 || !toc_valid) {		errstring = readdisklabel(CDLABELDEV(dev),		    cdstrategy, lp, clp, spoofonly);		/*if (errstring)			printf("%s: %s\n", cd->sc_dev.dv_xname, errstring);*/	}}