FreeBSD/sys/geom/geom_sunlabel_enc.c
/*
 * Decode the relevant fields of a sun disk label, and return zero if the
 * magic and checksum works out OK.
 */
Decode the relevant fields of a sun disk label, and return zero if the
magic and checksum works out OK.
Decode the relevant fields of a sun disk label and return zero if the magic and checksum works out OK .
int
sunlabel_dec(void const *pp, struct sun_disklabel *sl)
{
	const uint8_t *p;
	size_t i;
	u_int u;
	uint32_t vtocsane;
	uint16_t npart;
	p = pp;
	for (i = 0; i < sizeof(sl->sl_text); i++)
		sl->sl_text[i] = p[SL_TEXT + i];
	sl->sl_rpm = be16dec(p + SL_RPM);
	sl->sl_pcylinders = be16dec(p + SL_PCYLINDERS);
	sl->sl_sparespercyl = be16dec(p + SL_SPARESPERCYL);
	sl->sl_interleave = be16dec(p + SL_INTERLEAVE);
	sl->sl_ncylinders = be16dec(p + SL_NCYLINDERS);
	sl->sl_acylinders = be16dec(p + SL_ACYLINDERS);
	sl->sl_ntracks = be16dec(p + SL_NTRACKS);
	sl->sl_nsectors = be16dec(p + SL_NSECTORS);
	for (i = 0; i < SUN_NPART; i++) {
		sl->sl_part[i].sdkp_cyloffset = be32dec(p + SL_PART +
		    (i * SDKP_SIZEOF) + SDKP_CYLOFFSET);
		sl->sl_part[i].sdkp_nsectors = be32dec(p + SL_PART +
		    (i * SDKP_SIZEOF) + SDKP_NSECTORS);
	}
	sl->sl_magic = be16dec(p + SL_MAGIC);
	vtocsane = be32dec(p + SL_VTOC_SANITY);
	npart = be16dec(p + SL_VTOC_NPART);
	if (vtocsane == SUN_VTOC_SANE && npart == SUN_NPART) {
		sl->sl_vtoc_sane = vtocsane;
		sl->sl_vtoc_vers = be32dec(p + SL_VTOC_VERS);
		memcpy(sl->sl_vtoc_volname, p + SL_VTOC_VOLNAME,
		    SUN_VOLNAME_LEN);
		sl->sl_vtoc_nparts = SUN_NPART;
		for (i = 0; i < SUN_NPART; i++) {
			sl->sl_vtoc_map[i].svtoc_tag = be16dec(p +
				SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_TAG);
			sl->sl_vtoc_map[i].svtoc_flag = be16dec(p +
				SL_VTOC_MAP + (i * SVTOC_SIZEOF) + SVTOC_FLAG);
		}
	}
	for (i = u = 0; i < SUN_SIZE; i += 2)
		u ^= be16dec(p + i);
	if (u == 0 && sl->sl_magic == SUN_DKMAGIC)
		return (0);
	else
		return (EINVAL);
}
int sunlabel_dec ( void const * pp , struct sun_disklabel * sl ) { const uint8_t * p ; size_t i ; u_int u ; uint32_t vtocsane ; uint16_t npart ; p = pp ; for ( i = 0 ; i < sizeof ( sl -> sl_text ) ; i ++ ) sl -> sl_text [ i ] = p [ SL_TEXT + i ] ; sl -> sl_rpm = be16dec ( p + SL_RPM ) ; sl -> sl_pcylinders = be16dec ( p + SL_PCYLINDERS ) ; sl -> sl_sparespercyl = be16dec ( p + SL_SPARESPERCYL ) ; sl -> sl_interleave = be16dec ( p + SL_INTERLEAVE ) ; sl -> sl_ncylinders = be16dec ( p + SL_NCYLINDERS ) ; sl -> sl_acylinders = be16dec ( p + SL_ACYLINDERS ) ; sl -> sl_ntracks = be16dec ( p + SL_NTRACKS ) ; sl -> sl_nsectors = be16dec ( p + SL_NSECTORS ) ; for ( i = 0 ; i < SUN_NPART ; i ++ ) { sl -> sl_part [ i ] . sdkp_cyloffset = be32dec ( p + SL_PART + ( i * SDKP_SIZEOF ) + SDKP_CYLOFFSET ) ; sl -> sl_part [ i ] . sdkp_nsectors = be32dec ( p + SL_PART + ( i * SDKP_SIZEOF ) + SDKP_NSECTORS ) ; } sl -> sl_magic = be16dec ( p + SL_MAGIC ) ; vtocsane = be32dec ( p + SL_VTOC_SANITY ) ; npart = be16dec ( p + SL_VTOC_NPART ) ; if ( vtocsane == SUN_VTOC_SANE && npart == SUN_NPART ) { sl -> sl_vtoc_sane = vtocsane ; sl -> sl_vtoc_vers = be32dec ( p + SL_VTOC_VERS ) ; memcpy ( sl -> sl_vtoc_volname , p + SL_VTOC_VOLNAME , SUN_VOLNAME_LEN ) ; sl -> sl_vtoc_nparts = SUN_NPART ; for ( i = 0 ; i < SUN_NPART ; i ++ ) { sl -> sl_vtoc_map [ i ] . svtoc_tag = be16dec ( p + SL_VTOC_MAP + ( i * SVTOC_SIZEOF ) + SVTOC_TAG ) ; sl -> sl_vtoc_map [ i ] . svtoc_flag = be16dec ( p + SL_VTOC_MAP + ( i * SVTOC_SIZEOF ) + SVTOC_FLAG ) ; } } for ( i = u = 0 ; i < SUN_SIZE ; i += 2 ) u ^= be16dec ( p + i ) ; if ( u == 0 && sl -> sl_magic == SUN_DKMAGIC ) return ( 0 ) ; else return ( EINVAL ) ; }
Decode the relevant fields of a sun disk label, and return zero if the
 magic and checksum works out OK.
Decode the relevant fields of a sun disk label and return zero if the magic and checksum works out OK .
/*
		 * Seems we've got SVR4-compatible VTOC information
		 * as well, decode it.
		 */