Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1108 → Rev 1117

/FreeBSD/geom_nbsd/trunk/src/geom_nbsd_enc.c
1,4 → 1,9
/*-
* Copyright 2005, Anatoli Klassen <anatoli@aksoft.net>
* All rights reserved.
*
* The code is based on code of geom_bsd module by Poul-Henning Kamp.
*
* Copyright (c) 2002 Poul-Henning Kamp
* Copyright (c) 2002 Networks Associates Technology, Inc.
* All rights reserved.
34,23 → 39,16
*/
 
/*
* Functions to encode and decode struct disklabel and struct partition into
* Functions to decode struct disklabel and struct partition into
* a bytestream of little endianess and correct packing.
*
* NB! This file must be usable both in kernel and userland.
*/
 
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/sys/geom/geom_bsd_enc.c,v 1.6 2005/01/06 18:27:29 imp Exp $");
 
#include <sys/types.h>
#include <sys/endian.h>
#include <sys/errno.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
 
#include "disklabel.h"
 
82,6 → 80,9
}
 
d->d_npartitions = le16dec(ptr + 138);
if (maxpart > NBSD_MAXPARTITIONS) {
return(EINVAL);
}
if (d->d_npartitions > maxpart) {
return(EINVAL);
}
128,70 → 129,8
d->d_npartitions = le16dec(ptr + 138);
d->d_bbsize = le32dec(ptr + 140);
d->d_sbsize = le32dec(ptr + 144);
for (i = 0; i < NBSD_MAXPARTITIONS; i++)
for (i = 0; i < d->d_npartitions; i++)
nbsd_partition_le_dec(ptr + 148 + 16 * i, &d->d_partitions[i]);
return(0);
}
 
void
nbsd_partition_le_enc(u_char *ptr, struct partition *d)
{
le32enc(ptr + 0, d->p_size);
le32enc(ptr + 4, d->p_offset);
le32enc(ptr + 8, d->p_fsize);
ptr[12] = d->p_fstype;
ptr[13] = d->p_frag;
le16enc(ptr + 14, d->p_cpg);
}
 
void
nbsd_disklabel_le_enc(u_char *ptr, struct disklabel *d)
{
int i;
u_char *p, *pe;
uint16_t sum;
 
le32enc(ptr + 0, d->d_magic);
le16enc(ptr + 4, d->d_type);
le16enc(ptr + 6, d->d_subtype);
bcopy(d->d_typename, ptr + 8, 16);
bcopy(d->d_packname, ptr + 24, 16);
le32enc(ptr + 40, d->d_secsize);
le32enc(ptr + 44, d->d_nsectors);
le32enc(ptr + 48, d->d_ntracks);
le32enc(ptr + 52, d->d_ncylinders);
le32enc(ptr + 56, d->d_secpercyl);
le32enc(ptr + 60, d->d_secperunit);
le16enc(ptr + 64, d->d_sparespertrack);
le16enc(ptr + 66, d->d_sparespercyl);
le32enc(ptr + 68, d->d_acylinders);
le16enc(ptr + 72, d->d_rpm);
le16enc(ptr + 74, d->d_interleave);
le16enc(ptr + 76, d->d_trackskew);
le16enc(ptr + 78, d->d_cylskew);
le32enc(ptr + 80, d->d_headswitch);
le32enc(ptr + 84, d->d_trkseek);
le32enc(ptr + 88, d->d_flags);
le32enc(ptr + 92, d->d_drivedata[0]);
le32enc(ptr + 96, d->d_drivedata[1]);
le32enc(ptr + 100, d->d_drivedata[2]);
le32enc(ptr + 104, d->d_drivedata[3]);
le32enc(ptr + 108, d->d_drivedata[4]);
le32enc(ptr + 112, d->d_spare[0]);
le32enc(ptr + 116, d->d_spare[1]);
le32enc(ptr + 120, d->d_spare[2]);
le32enc(ptr + 124, d->d_spare[3]);
le32enc(ptr + 128, d->d_spare[4]);
le32enc(ptr + 132, d->d_magic2);
le16enc(ptr + 136, 0);
le16enc(ptr + 138, d->d_npartitions);
le32enc(ptr + 140, d->d_bbsize);
le32enc(ptr + 144, d->d_sbsize);
for (i = 0; i < d->d_npartitions; i++)
nbsd_partition_le_enc(ptr + 148 + 16 * i, &d->d_partitions[i]);
pe = ptr + 148 + 16 * d->d_npartitions;
sum = 0;
for (p = ptr; p < pe; p += 2)
sum ^= le16dec(p);
le16enc(ptr + 136, sum);
}