/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003 Poul-Henning Kamp4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/* Functions to encode or decode struct dos_partition into a bytestream29* of correct endianness and packing. These functions do no validation30* or sanity checking, they only pack/unpack the fields correctly.31*32* NB! This file must be usable both in kernel and userland.33*/3435#include <sys/types.h>36#include <sys/diskmbr.h>37#include <sys/endian.h>3839#include "fdisk_mbr_enc.h"4041void42dos_partition_dec(void const *pp, struct dos_partition *d)43{44unsigned char const *p = pp;4546d->dp_flag = p[0];47d->dp_shd = p[1];48d->dp_ssect = p[2];49d->dp_scyl = p[3];50d->dp_typ = p[4];51d->dp_ehd = p[5];52d->dp_esect = p[6];53d->dp_ecyl = p[7];54d->dp_start = le32dec(p + 8);55d->dp_size = le32dec(p + 12);56}5758void59dos_partition_enc(void *pp, struct dos_partition *d)60{61unsigned char *p = pp;6263p[0] = d->dp_flag;64p[1] = d->dp_shd;65p[2] = d->dp_ssect;66p[3] = d->dp_scyl;67p[4] = d->dp_typ;68p[5] = d->dp_ehd;69p[6] = d->dp_esect;70p[7] = d->dp_ecyl;71le32enc(p + 8, d->dp_start);72le32enc(p + 12, d->dp_size);73}747576