diff options
author | phk <phk@FreeBSD.org> | 2003-04-12 08:34:40 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2003-04-12 08:34:40 +0000 |
commit | e9d1c65d22261411dd6170529ca7f925989dca05 (patch) | |
tree | 789d291ca01de94508cdbf44ca93727387ca9c33 /sys | |
parent | 0aeffee15b90eaf9e1bf857750489faaac5eea25 (diff) | |
download | FreeBSD-src-e9d1c65d22261411dd6170529ca7f925989dca05.zip FreeBSD-src-e9d1c65d22261411dd6170529ca7f925989dca05.tar.gz |
Move the functions for encoding decoding struct dos_partition into
a separate .c file so they can be used from userland as well.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/conf/files | 1 | ||||
-rw-r--r-- | sys/conf/files.i386 | 1 | ||||
-rw-r--r-- | sys/conf/files.ia64 | 1 | ||||
-rw-r--r-- | sys/geom/geom_mbr.c | 20 | ||||
-rw-r--r-- | sys/geom/geom_mbr_enc.c | 72 |
5 files changed, 77 insertions, 18 deletions
diff --git a/sys/conf/files b/sys/conf/files index 4486d24..6b520f1 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -897,6 +897,7 @@ geom/geom_gpt.c optional geom_gpt geom/geom_io.c standard geom/geom_kern.c standard geom/geom_mbr.c optional geom_mbr +geom/geom_mbr_enc.c optional geom_mbr geom/geom_mirror.c optional geom_mirror geom/geom_pc98.c optional geom_pc98 geom/geom_slice.c standard diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 611b953..2468b87 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -148,6 +148,7 @@ dev/syscons/syscons.c optional sc dev/syscons/sysmouse.c optional sc geom/geom_bsd.c standard geom/geom_mbr.c standard +geom/geom_mbr_enc.c standard gnu/i386/fpemul/div_small.s optional gpl_math_emulate \ warning "kernel contains GPL contaminated math emulator" gnu/i386/fpemul/errors.c optional gpl_math_emulate diff --git a/sys/conf/files.ia64 b/sys/conf/files.ia64 index 7a7fb26..3ec6d85 100644 --- a/sys/conf/files.ia64 +++ b/sys/conf/files.ia64 @@ -95,6 +95,7 @@ dev/syscons/sysmouse.c optional sc geom/geom_bsd.c standard geom/geom_gpt.c standard geom/geom_mbr.c standard +geom/geom_mbr_enc.c standard isa/atkbd_isa.c optional atkbd isa/atkbdc_isa.c optional atkbdc isa/fd.c optional fdc diff --git a/sys/geom/geom_mbr.c b/sys/geom/geom_mbr.c index 05d6d45..4c81ec7 100644 --- a/sys/geom/geom_mbr.c +++ b/sys/geom/geom_mbr.c @@ -85,22 +85,6 @@ g_mbr_print(int i, struct dos_partition *dp) printf(" s:%d l:%d\n", dp->dp_start, dp->dp_size); } -static void -g_dec_dos_partition(u_char *ptr, struct dos_partition *d) -{ - - d->dp_flag = ptr[0]; - d->dp_shd = ptr[1]; - d->dp_ssect = ptr[2]; - d->dp_scyl = ptr[3]; - d->dp_typ = ptr[4]; - d->dp_ehd = ptr[5]; - d->dp_esect = ptr[6]; - d->dp_ecyl = ptr[7]; - d->dp_start = le32dec(ptr + 8); - d->dp_size = le32dec(ptr + 12); -} - struct g_mbr_softc { int type [NDOSPART]; u_int sectorsize; @@ -121,7 +105,7 @@ g_mbr_modify(struct g_geom *gp, struct g_mbr_softc *ms, u_char *sec0) dp = ndp; for (i = 0; i < NDOSPART; i++) { - g_dec_dos_partition( + dos_partition_dec( sec0 + DOSPARTOFF + i * sizeof(struct dos_partition), dp + i); if (bootverbose) @@ -428,7 +412,7 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) break; for (i = 0; i < NDOSPART; i++) - g_dec_dos_partition( + dos_partition_dec( buf + DOSPARTOFF + i * sizeof(struct dos_partition), dp + i); g_free(buf); diff --git a/sys/geom/geom_mbr_enc.c b/sys/geom/geom_mbr_enc.c new file mode 100644 index 0000000..b5d560a --- /dev/null +++ b/sys/geom/geom_mbr_enc.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Functions to encode or decode struct dos_partition into a bytestream + * of correct endianess and packing. These functions do no validation + * or sanity checking, they only pack/unpack the fields correctly. + * + * NB! This file must be usable both in kernel and userland. + * + */ + +#include <sys/types.h> +#include <sys/diskmbr.h> +#include <sys/endian.h> + +void +dos_partition_dec(void const *pp, struct dos_partition *d) +{ + unsigned char const *p = pp; + + d->dp_flag = p[0]; + d->dp_shd = p[1]; + d->dp_ssect = p[2]; + d->dp_scyl = p[3]; + d->dp_typ = p[4]; + d->dp_ehd = p[5]; + d->dp_esect = p[6]; + d->dp_ecyl = p[7]; + d->dp_start = le32dec(p + 8); + d->dp_size = le32dec(p + 12); +} + +void +dos_partition_enc(void *pp, struct dos_partition *d) +{ + unsigned char *p = pp; + + p[0] = d->dp_flag; + p[1] = d->dp_shd; + p[2] = d->dp_ssect; + p[3] = d->dp_scyl; + p[4] = d->dp_typ; + p[5] = d->dp_ehd; + p[6] = d->dp_esect; + p[7] = d->dp_ecyl; + le32enc(p + 8, d->dp_start); + le32enc(p + 12, d->dp_size); +} |