summaryrefslogtreecommitdiffstats
path: root/sys/geom
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2011-06-20 12:22:30 +0000
committerae <ae@FreeBSD.org>2011-06-20 12:22:30 +0000
commitf892d9414af8b47d6971e28906e6f4e5470219b9 (patch)
tree0c068b1dec33fccdd49b587116421652c743d092 /sys/geom
parent16ca4a6ef7d361feafdbc67a6ef8e1271f09be45 (diff)
downloadFreeBSD-src-f892d9414af8b47d6971e28906e6f4e5470219b9.zip
FreeBSD-src-f892d9414af8b47d6971e28906e6f4e5470219b9.tar.gz
Change the way how we update bootcode for BSD scheme.
Since the only parameter that we check is size of bootcode, then allow only two sizes: size of boot1 and size of /boot/boot. This partially protects users from losing ability to boot if incorrect bootcode is specified. Requested by: ru
Diffstat (limited to 'sys/geom')
-rw-r--r--sys/geom/part/g_part_bsd.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/sys/geom/part/g_part_bsd.c b/sys/geom/part/g_part_bsd.c
index 269b943..be46775 100644
--- a/sys/geom/part/g_part_bsd.c
+++ b/sys/geom/part/g_part_bsd.c
@@ -46,6 +46,11 @@ __FBSDID("$FreeBSD$");
#include "g_part_if.h"
+#define BOOT1_SIZE 512
+#define LABEL_SIZE 512
+#define BOOT2_OFF (BOOT1_SIZE + LABEL_SIZE)
+#define BOOT2_SIZE (BBSIZE - BOOT2_OFF)
+
FEATURE(geom_part_bsd, "GEOM partitioning class for BSD disklabels");
struct g_part_bsd_table {
@@ -170,22 +175,16 @@ g_part_bsd_bootcode(struct g_part_table *basetable, struct g_part_parms *gpp)
{
struct g_part_bsd_table *table;
const u_char *codeptr;
- size_t hdsz, tlsz;
- size_t codesz, tlofs;
- hdsz = 512;
- tlofs = hdsz + 148 + basetable->gpt_entries * 16;
- tlsz = BBSIZE - tlofs;
+ if (gpp->gpp_codesize != BOOT1_SIZE && gpp->gpp_codesize != BBSIZE)
+ return (ENODEV);
+
table = (struct g_part_bsd_table *)basetable;
- bzero(table->bbarea, hdsz);
- bzero(table->bbarea + tlofs, tlsz);
codeptr = gpp->gpp_codeptr;
- codesz = MIN(hdsz, gpp->gpp_codesize);
- if (codesz > 0)
- bcopy(codeptr, table->bbarea, codesz);
- codesz = MIN(tlsz, gpp->gpp_codesize - tlofs);
- if (codesz > 0)
- bcopy(codeptr + tlofs, table->bbarea + tlofs, codesz);
+ bcopy(codeptr, table->bbarea, BOOT1_SIZE);
+ if (gpp->gpp_codesize == BBSIZE)
+ bcopy(codeptr + BOOT2_OFF, table->bbarea + BOOT2_OFF,
+ BOOT2_SIZE);
return (0);
}
OpenPOWER on IntegriCloud