FreeBSD/sys/geom/geom_sunlabel_enc.c
/*
 * Encode the relevant fields into a sun disklabel, compute new checksum.
 */
Encode the relevant fields into a sun disklabel, compute new checksum.
Encode the relevant fields into a sun disklabel compute new checksum .
void
sunlabel_enc(void *pp, struct sun_disklabel *sl)
{
	uint8_t *p;
	size_t i;
	u_int u;
	p = pp;
	for (i = 0; i < SL_TEXT_SIZEOF; i++)
		p[SL_TEXT + i] = sl->sl_text[i];
	be16enc(p + SL_RPM, sl->sl_rpm);
	be16enc(p + SL_PCYLINDERS, sl->sl_pcylinders);
	be16enc(p + SL_SPARESPERCYL, sl->sl_sparespercyl);
	be16enc(p + SL_INTERLEAVE, sl->sl_interleave);
	be16enc(p + SL_NCYLINDERS, sl->sl_ncylinders);
	be16enc(p + SL_ACYLINDERS, sl->sl_acylinders);
	be16enc(p + SL_NTRACKS, sl->sl_ntracks);
	be16enc(p + SL_NSECTORS, sl->sl_nsectors);
	for (i = 0; i < SUN_NPART; i++) {
		be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_CYLOFFSET,
		    sl->sl_part[i].sdkp_cyloffset);
		be32enc(p + SL_PART + (i * SDKP_SIZEOF) + SDKP_NSECTORS,
		    sl->sl_part[i].sdkp_nsectors);
	}
	be16enc(p + SL_MAGIC, sl->sl_magic);
	if (sl->sl_vtoc_sane == SUN_VTOC_SANE
	    && sl->sl_vtoc_nparts == SUN_NPART) {
		be32enc(p + SL_VTOC_VERS, sl->sl_vtoc_vers);
		be32enc(p + SL_VTOC_SANITY, SUN_VTOC_SANE);
		memcpy(p + SL_VTOC_VOLNAME, sl->sl_vtoc_volname,
		    SUN_VOLNAME_LEN);
		be16enc(p + SL_VTOC_NPART, SUN_NPART);
		for (i = 0; i < SUN_NPART; i++) {
			be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF)
				+ SVTOC_TAG,
				sl->sl_vtoc_map[i].svtoc_tag);
			be16enc(p + SL_VTOC_MAP + (i * SVTOC_SIZEOF)
				+ SVTOC_FLAG,
				sl->sl_vtoc_map[i].svtoc_flag);
		}
	}
	for (i = u = 0; i < SUN_SIZE; i += 2)
		u ^= be16dec(p + i);
	be16enc(p + SL_CKSUM, u);
}
void sunlabel_enc ( void * pp , struct sun_disklabel * sl ) { uint8_t * p ; size_t i ; u_int u ; p = pp ; for ( i = 0 ; i < SL_TEXT_SIZEOF ; i ++ ) p [ SL_TEXT + i ] = sl -> sl_text [ i ] ; be16enc ( p + SL_RPM , sl -> sl_rpm ) ; be16enc ( p + SL_PCYLINDERS , sl -> sl_pcylinders ) ; be16enc ( p + SL_SPARESPERCYL , sl -> sl_sparespercyl ) ; be16enc ( p + SL_INTERLEAVE , sl -> sl_interleave ) ; be16enc ( p + SL_NCYLINDERS , sl -> sl_ncylinders ) ; be16enc ( p + SL_ACYLINDERS , sl -> sl_acylinders ) ; be16enc ( p + SL_NTRACKS , sl -> sl_ntracks ) ; be16enc ( p + SL_NSECTORS , sl -> sl_nsectors ) ; for ( i = 0 ; i < SUN_NPART ; i ++ ) { be32enc ( p + SL_PART + ( i * SDKP_SIZEOF ) + SDKP_CYLOFFSET , sl -> sl_part [ i ] . sdkp_cyloffset ) ; be32enc ( p + SL_PART + ( i * SDKP_SIZEOF ) + SDKP_NSECTORS , sl -> sl_part [ i ] . sdkp_nsectors ) ; } be16enc ( p + SL_MAGIC , sl -> sl_magic ) ; if ( sl -> sl_vtoc_sane == SUN_VTOC_SANE && sl -> sl_vtoc_nparts == SUN_NPART ) { be32enc ( p + SL_VTOC_VERS , sl -> sl_vtoc_vers ) ; be32enc ( p + SL_VTOC_SANITY , SUN_VTOC_SANE ) ; memcpy ( p + SL_VTOC_VOLNAME , sl -> sl_vtoc_volname , SUN_VOLNAME_LEN ) ; be16enc ( p + SL_VTOC_NPART , SUN_NPART ) ; for ( i = 0 ; i < SUN_NPART ; i ++ ) { be16enc ( p + SL_VTOC_MAP + ( i * SVTOC_SIZEOF ) + SVTOC_TAG , sl -> sl_vtoc_map [ i ] . svtoc_tag ) ; be16enc ( p + SL_VTOC_MAP + ( i * SVTOC_SIZEOF ) + SVTOC_FLAG , sl -> sl_vtoc_map [ i ] . svtoc_flag ) ; } } for ( i = u = 0 ; i < SUN_SIZE ; i += 2 ) u ^= be16dec ( p + i ) ; be16enc ( p + SL_CKSUM , u ) ; }
Encode the relevant fields into a sun disklabel, compute new checksum.
Encode the relevant fields into a sun disklabel compute new checksum .
/*
		 * Write SVR4-compatible VTOC elements.
		 */