1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2003 Poul-Henning Kamp
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /* Functions to encode or decode struct dos_partition into a bytestream
30 * of correct endianness and packing. These functions do no validation
31 * or sanity checking, they only pack/unpack the fields correctly.
32 *
33 * NB! This file must be usable both in kernel and userland.
34 */
35
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD: releng/12.0/sys/geom/geom_mbr_enc.c 326270 2017-11-27 15:17:37Z pfg $");
38
39 #include <sys/types.h>
40 #include <sys/diskmbr.h>
41 #include <sys/endian.h>
42
43 void
44 dos_partition_dec(void const *pp, struct dos_partition *d)
45 {
46 unsigned char const *p = pp;
47
48 d->dp_flag = p[0];
49 d->dp_shd = p[1];
50 d->dp_ssect = p[2];
51 d->dp_scyl = p[3];
52 d->dp_typ = p[4];
53 d->dp_ehd = p[5];
54 d->dp_esect = p[6];
55 d->dp_ecyl = p[7];
56 d->dp_start = le32dec(p + 8);
57 d->dp_size = le32dec(p + 12);
58 }
59
60 void
61 dos_partition_enc(void *pp, struct dos_partition *d)
62 {
63 unsigned char *p = pp;
64
65 p[0] = d->dp_flag;
66 p[1] = d->dp_shd;
67 p[2] = d->dp_ssect;
68 p[3] = d->dp_scyl;
69 p[4] = d->dp_typ;
70 p[5] = d->dp_ehd;
71 p[6] = d->dp_esect;
72 p[7] = d->dp_ecyl;
73 le32enc(p + 8, d->dp_start);
74 le32enc(p + 12, d->dp_size);
75 }
Cache object: 94d584388d5967c7f28fdee5b7aa36e4
|