Commit 767777b8 authored by Mike Hibler's avatar Mike Hibler

Some re-org to support GPT.

Split out the partition identification code. This part just moves the
MBR support to its own directory.
parent 4eeecd9d
#
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -120,4 +120,4 @@ MERGE_BUILD_SANDBOX = @MERGE_BUILD_SANDBOX@
EXP_VIS_SUPPORT = @EXP_VIS_SUPPORT@
TESTBED_LIBSRCDIR = ${TESTBED_SRCDIR}/clientside/lib
TESTBED_LIBOBJDIR = ${OBJDIR}/clientside/lib
TESTBED_IMAGEZIPSRCDIR = ${OBJDIR}/clientside/os/imagezip
TESTBED_IMAGEZIPSRCDIR = ${TESTBED_SRCDIR}/clientside/os/imagezip
......@@ -84,7 +84,7 @@ subboss:
include $(TESTBED_SRCDIR)/GNUmakerules
FRISBEEDIR = $(TESTBED_IMAGEZIPSRCDIR)
IZSRCDIR = $(TESTBED_IMAGEZIPSRCDIR)
SHAREDOBJS = log.o network.o trace.o utils.o
......@@ -107,7 +107,7 @@ CLIENTLIBS = -lrt -lz $(PTHREADLIBS)
else
CLIENTLIBS = -lz $(PTHREADLIBS)
endif
CLIENTOBJS = client.o frisbee.o checksum.o disksize.o $(SHAREDOBJS)
CLIENTOBJS = client.o frisbee.o mbr.o checksum.o disksize.o $(SHAREDOBJS)
SERVERFLAGS = $(CFLAGS)
SERVERLIBS = $(PTHREADLIBS)
......@@ -152,7 +152,7 @@ endif
CFLAGS = -O2 -g -Wall -fno-builtin-log $(LDSTATIC) $(PTHREADCFLAGS) -DSTATS -DMASTER_SERVER
LDFLAGS = $(LDSTATIC)
IUZFLAGS = -DFRISBEE
IUZFLAGS = -DFRISBEE -I$(IZSRCDIR)
IUZLIBS =
ifeq ($(WITH_CRYPTO),1)
......@@ -257,17 +257,21 @@ log.o: $(SRCDIR)/log.c decls.h log.h
event.o: $(SRCDIR)/event.c decls.h log.h event.h
$(CC) $(EVENTFLAGS) -c $(SRCDIR)/event.c
$(FRISBEEDIR)/imageunzip.c: $(FRISBEEDIR)/imagehdr.h $(FRISBEEDIR)/queue.h $(FRISBEEDIR)/checksum.h
$(FRISBEEDIR)/checksum.c: $(FRISBEEDIR)/imagehdr.h $(FRISBEEDIR)/checksum.h
$(IZSRCDIR)/imageunzip.c: $(IZSRCDIR)/imagehdr.h $(IZSRCDIR)/queue.h $(IZSRCDIR)/checksum.h
$(IZSRCDIR)/checksum.c: $(IZSRCDIR)/imagehdr.h $(IZSRCDIR)/checksum.h
$(IZSRCDIR)/mbr/mbr.c: $(IZSRCDIR)/imagehdr.h $(IZSRCDIR)/sliceinfo.h $(IZSRCDIR)/mbr/mbr.h
disksize.o: $(FRISBEEDIR)/disksize.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -I$(FRISBEEDIR) -o disksize.o $<
disksize.o: $(IZSRCDIR)/disksize.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -o disksize.o $<
checksum.o: $(FRISBEEDIR)/checksum.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -I$(FRISBEEDIR) -o checksum.o $<
checksum.o: $(IZSRCDIR)/checksum.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -o checksum.o $<
frisbee.o: $(FRISBEEDIR)/imageunzip.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -I$(FRISBEEDIR) -o frisbee.o $<
mbr.o: $(IZSRCDIR)/mbr/mbr.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -I$(IZSRCDIR)/mbr -o mbr.o $<
frisbee.o: $(IZSRCDIR)/imageunzip.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -I$(IZSRCDIR) -o frisbee.o $<
client.o: decls.h log.h utils.h trace.h
server.o: decls.h log.h utils.h trace.h
......
......@@ -28,11 +28,18 @@ SUBDIR = $(subst $(TESTBED_SRCDIR)/,,$(SRCDIR))
DISTFILES = global.h imagehdr.h queue.h sliceinfo.h \
imagedump.c imagedump.8 imagezip.c imagezip.8 \
imageunzip.c crc.c checksum.c disksize.c imageunzip.8 \
mbr/*.[hc] gpt/*.[hc] \
extfs/*.[hc] fat/*.[hc] ffs/*.[hc] \
ntfs/*.[hc] hashmap/*.[hc]
EXPANDCOPYRIGHT = /usr/site/lib/copyright/expand-copyr
#
# At least support MBR partitioning
#
WITH_MBR = 1
WITH_GPT = 0
#
# Support encrypted and signed-checksumed images.
# Requires openssl libraries.
......@@ -143,6 +150,21 @@ ifeq ($(WITH_V3COMPAT),1)
CFLAGS += -DWITH_V3COMPAT
endif
# MBR
ifeq ($(WITH_MBR),1)
CFLAGS += -DWITH_MBR
SUBDIRS += mbr
ZIPLIBS += mbr/libmbr.a
UNZIPLIBS += mbr/libmbr.a
endif
# GPT
ifeq ($(WITH_GPT),1)
CFLAGS += -DWITH_GPT
SUBDIRS += gpt
ZIPLIBS += gpt/libgpt.a
endif
# UFS/UFS2
ifeq ($(WITH_FFS),1)
CFLAGS += -DWITH_FFS
......@@ -208,13 +230,13 @@ endif
include $(TESTBED_SRCDIR)/GNUmakerules
imagezip: $(SUBDIRS) imagezip.o disksize.o checksum.o version.o $(ZIPLIBS)
$(CC) $(CFLAGS) imagezip.o disksize.o checksum.o version.o $(ZIPLIBS) $(LIBS) -o imagezip
imagezip: $(SUBDIRS) imagezip.o sliceinfo.o disksize.o checksum.o version.o $(ZIPLIBS)
$(CC) $(CFLAGS) imagezip.o sliceinfo.o disksize.o checksum.o version.o $(ZIPLIBS) $(LIBS) -o imagezip
imagezip.o: imagezip.c
$(CC) -c $(ZIPCFLAGS) -o imagezip.o $<
imageunzip: imageunzip.o disksize.o checksum.o crc.o version.o
imageunzip: mbr imageunzip.o disksize.o checksum.o crc.o version.o
$(CC) $(CFLAGS) imageunzip.o disksize.o checksum.o crc.o version.o $(UNZIPLIBS) -o imageunzip
imageunzip.o: imageunzip.c
......
/*
* Copyright (c) 2000-2012 University of Utah and the Flux Group.
* Copyright (c) 2000-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -49,7 +49,7 @@ extern int fixup_lilo(int slice, int stype, u_int32_t start, u_int32_t size,
* slice, so we have to add the starting sector to everything.
*/
int
read_linuxslice(int slice, int stype, u_int32_t start, u_int32_t size,
read_linuxslice(int slice, iz_type stype, iz_lba start, iz_size size,
char *sname, int infd)
{
#define LINUX_SUPERBLOCK_OFFSET 1024
......@@ -359,7 +359,7 @@ read_ext4group(struct ext4_super_block *super,
* bit of it. The rest of it does not need to be written to disk.
*/
int
read_linuxswap(int slice, int stype, u_int32_t start, u_int32_t size,
read_linuxswap(int slice, iz_type stype, iz_lba start, iz_size size,
char *sname, int infd)
{
if (debug) {
......
/*
* Copyright (c) 2003-2005 University of Utah and the Flux Group.
* Copyright (c) 2003-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -39,7 +39,7 @@ static u_int32_t fat_offset, fat_limit;
static int fatsecpersec;
int
read_fatslice(int slice, int stype, u_int32_t start, u_int32_t size,
read_fatslice(int slice, iz_type stype, iz_lba start, iz_size size,
char *sfilename, int infd)
{
struct bootblock boot;
......
......@@ -66,7 +66,7 @@ static int32_t freecount;
* Operate on a BSD slice
*/
int
read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
read_bsdslice(int slice, iz_type bsdtype, iz_lba start, iz_size size,
char *sname, int infd)
{
int cc, i, rval = 0, npart, absoffset;
......@@ -77,7 +77,7 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
if (debug)
fprintf(stderr, " P%d (%sBSD Slice)\n", slice + 1,
bsdtype == DOSPTYP_386BSD ? "Free" : "Open");
bsdtype == IZTYPE_386BSD ? "Free" : "Open");
if (devlseek(infd, sectobytes(start), SEEK_SET) < 0) {
warn("Could not seek to beginning of BSD slice");
......@@ -148,7 +148,7 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
if (dlabel.label.d_partitions[i].p_size == 0 ||
dlabel.label.d_partitions[i].p_fstype == FS_UNUSED)
continue;
if (bsdtype == DOSPTYP_OPENBSD && i >= 8 && i < 16)
if (bsdtype == IZTYPE_OPENBSD && i >= 8 && i < 16)
continue;
if (dlabel.label.d_partitions[i].p_offset < start) {
fprintf(stderr, "P%d: WARNING: BSD label appears to use relative offsets, adjusting...\n", slice+1);
......@@ -171,7 +171,7 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
* OpenBSD maps the extended DOS partitions as slices 8-15,
* skip them.
*/
if (bsdtype == DOSPTYP_OPENBSD && i >= 8 && i < 16) {
if (bsdtype == IZTYPE_OPENBSD && i >= 8 && i < 16) {
if (debug)
fprintf(stderr, " '%c' skipping, "
"OpenBSD mapping of DOS partition %d\n",
......@@ -234,7 +234,7 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
* extended DOS partitions. Also leave raw partition
* alone as it maps the entire disk (not just slice)
*/
if (bsdtype == DOSPTYP_OPENBSD &&
if (bsdtype == IZTYPE_OPENBSD &&
(i == 2 || (i >= 8 && i < 16)))
continue;
......@@ -247,7 +247,7 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
addfixup(sectobytes(start+LABELSECTOR),
sectobytes(start),
(off_t)sizeof(dlabel.label), &dlabel,
bsdtype == DOSPTYP_OPENBSD ?
bsdtype == IZTYPE_OPENBSD ?
RELOC_OBSDDISKLABEL : RELOC_FBSDDISKLABEL);
}
......
......@@ -46,6 +46,8 @@ extern void savefixups(void);
extern void restorefixups(int isempty);
extern void dumpfixups(int verbose, int count);
extern int parse_mbr(int fd, struct iz_slice *parttab);
extern SLICEMAP_PROCESS_PROTO(read_bsdslice);
extern SLICEMAP_PROCESS_PROTO(read_linuxslice);
extern SLICEMAP_PROCESS_PROTO(read_linuxswap);
......
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = @top_builddir@
SUBDIR = $(subst $(TESTBED_SRCDIR)/,,$(SRCDIR))
MAINDIR = $(SRCDIR)/..
include $(OBJDIR)/Makeconf
CFLAGS += $(SUBDIRCFLAGS) -I$(MAINDIR) -I$(SRCDIR)
all: libgpt.a
include $(TESTBED_SRCDIR)/GNUmakerules
OBJS = gpt.o
gpt.o: gpt.h
gpt.o: $(MAINDIR)/global.h $(MAINDIR)/sliceinfo.h
libgpt.a: $(OBJS)
$(AR) $(ARFLAGS) $@ $?
$(RANLIB) $@
install:
clean:
rm -f libgpt.a $(OBJS)
/*-
* Copyright (c) 2002 Marcel Moolenaar
* 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 ``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 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: head/sys/sys/gpt.h 268256 2014-07-04 15:55:32Z nwhitehorn $
*/
#ifndef _SYS_GPT_H_
#define _SYS_GPT_H_
/* XXX we include the uuid type from sys/uuid.h here to be self contained */
/* Length of a node address (an IEEE 802 address). */
#define _UUID_NODE_LEN 6
/*
* See also:
* http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
* http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
*
* A DCE 1.1 compatible source representation of UUIDs.
*/
struct uuid {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_version;
uint8_t clock_seq_hi_and_reserved;
uint8_t clock_seq_low;
uint8_t node[_UUID_NODE_LEN];
};
struct gpt_hdr {
char hdr_sig[8];
#define GPT_HDR_SIG "EFI PART"
uint32_t hdr_revision;
#define GPT_HDR_REVISION 0x00010000
uint32_t hdr_size;
uint32_t hdr_crc_self;
uint32_t __reserved;
uint64_t hdr_lba_self;
uint64_t hdr_lba_alt;
uint64_t hdr_lba_start;
uint64_t hdr_lba_end;
struct uuid hdr_uuid;
uint64_t hdr_lba_table;
uint32_t hdr_entries;
uint32_t hdr_entsz;
uint32_t hdr_crc_table;
/*
* The header as defined in the EFI spec is not a multiple of 8 bytes
* and given that the alignment requirement is on an 8 byte boundary,
* padding will happen. We make the padding explicit so that we can
* correct the value returned by sizeof() when we put the size of the
* header in field hdr_size, or otherwise use offsetof().
*/
uint32_t padding;
};
struct gpt_ent {
struct uuid ent_type;
struct uuid ent_uuid;
uint64_t ent_lba_start;
uint64_t ent_lba_end;
uint64_t ent_attr;
#define GPT_ENT_ATTR_PLATFORM (1ULL << 0)
#define GPT_ENT_ATTR_BOOTME (1ULL << 59)
#define GPT_ENT_ATTR_BOOTONCE (1ULL << 58)
#define GPT_ENT_ATTR_BOOTFAILED (1ULL << 57)
uint16_t ent_name[36]; /* UTF-16. */
};
#define GPT_ENT_TYPE_UNUSED \
{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}
#define GPT_ENT_TYPE_EFI \
{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}
#define GPT_ENT_TYPE_MBR \
{0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}}
#define GPT_ENT_TYPE_FREEBSD \
{0x516e7cb4,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define GPT_ENT_TYPE_FREEBSD_BOOT \
{0x83bd6b9d,0x7f41,0x11dc,0xbe,0x0b,{0x00,0x15,0x60,0xb8,0x4f,0x0f}}
#define GPT_ENT_TYPE_FREEBSD_NANDFS \
{0x74ba7dd9,0xa689,0x11e1,0xbd,0x04,{0x00,0xe0,0x81,0x28,0x6a,0xcf}}
#define GPT_ENT_TYPE_FREEBSD_SWAP \
{0x516e7cb5,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define GPT_ENT_TYPE_FREEBSD_UFS \
{0x516e7cb6,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define GPT_ENT_TYPE_FREEBSD_VINUM \
{0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define GPT_ENT_TYPE_FREEBSD_ZFS \
{0x516e7cba,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define GPT_ENT_TYPE_PREP_BOOT \
{0x9e1a2d38,0xc612,0x4316,0xaa,0x26,{0x8b,0x49,0x52,0x1e,0x5a,0x8b}}
/*
* The following are unused but documented here to avoid reuse.
*
* GPT_ENT_TYPE_FREEBSD_UFS2 \
* {0x516e7cb7,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
*/
/*
* Foreign partition types that we're likely to encounter. Note that Linux
* apparently choose to share data partitions with MS. I don't what the
* advantage might be. I can see how sharing swap partitions is advantageous
* though.
*/
#define GPT_ENT_TYPE_MS_RESERVED \
{0xe3c9e316,0x0b5c,0x4db8,0x81,0x7d,{0xf9,0x2d,0xf0,0x02,0x15,0xae}}
#define GPT_ENT_TYPE_MS_BASIC_DATA \
{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}
#define GPT_ENT_TYPE_MS_LDM_METADATA \
{0x5808c8aa,0x7e8f,0x42e0,0x85,0xd2,{0xe1,0xe9,0x04,0x34,0xcf,0xb3}}
#define GPT_ENT_TYPE_MS_LDM_DATA \
{0xaf9b60a0,0x1431,0x4f62,0xbc,0x68,{0x33,0x11,0x71,0x4a,0x69,0xad}}
#define GPT_ENT_TYPE_LINUX_DATA \
{0x0fc63daf,0x8483,0x4772,0x8e,0x79,{0x3d,0x69,0xd8,0x47,0x7d,0xe4}}
#define GPT_ENT_TYPE_LINUX_RAID \
{0xa19d880f,0x05fc,0x4d3b,0xa0,0x06,{0x74,0x3f,0x0f,0x84,0x91,0x1e}}
#define GPT_ENT_TYPE_LINUX_SWAP \
{0x0657fd6d,0xa4ab,0x43c4,0x84,0xe5,{0x09,0x33,0xc8,0x4b,0x4f,0x4f}}
#define GPT_ENT_TYPE_LINUX_LVM \
{0xe6d6d379,0xf507,0x44c2,0xa2,0x3c,{0x23,0x8f,0x2a,0x3d,0xf9,0x28}}
#define GPT_ENT_TYPE_VMFS \
{0xaa31e02a,0x400f,0x11db,0x95,0x90,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
#define GPT_ENT_TYPE_VMKDIAG \
{0x9d275380,0x40ad,0x11db,0xbf,0x97,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
#define GPT_ENT_TYPE_VMRESERVED \
{0x9198effc,0x31c0,0x11db,0x8f,0x78,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
#define GPT_ENT_TYPE_VMVSANHDR \
{0x381cfccc,0x7288,0x11e0,0x92,0xee,{0x00,0x0c,0x29,0x11,0xd0,0xb2}}
#define GPT_ENT_TYPE_APPLE_BOOT \
{0x426F6F74,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_HFS \
{0x48465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_UFS \
{0x55465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_ZFS \
{0x6a898cc3,0x1dd2,0x11b2,0x99,0xa6,{0x08,0x00,0x20,0x73,0x66,0x31}}
#define GPT_ENT_TYPE_APPLE_RAID \
{0x52414944,0x0000,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_RAID_OFFLINE \
{0x52414944,0x5f4f,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_LABEL \
{0x4C616265,0x6c00,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_TV_RECOVERY \
{0x5265636f,0x7665,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_NETBSD_FFS \
{0x49f48d5a,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_NETBSD_LFS \
{0x49f48d82,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_NETBSD_SWAP \
{0x49f48d32,0xb10e,0x11dc,0xB9,0x9B,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_NETBSD_RAID \
{0x49f48daa,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_NETBSD_CCD \
{0x2db519c4,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_NETBSD_CGD \
{0x2db519ec,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define GPT_ENT_TYPE_DRAGONFLY_LABEL32 \
{0x9d087404,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_SWAP \
{0x9d58fdbd,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_UFS1 \
{0x9d94ce7c,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_VINUM \
{0x9dd4478f,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_CCD \
{0xdbd5211b,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_LABEL64 \
{0x3d48ce54,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_LEGACY \
{0xbd215ab2,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_HAMMER \
{0x61dc63ac,0x6e38,0x11dc,0x85,0x13,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
#define GPT_ENT_TYPE_DRAGONFLY_HAMMER2 \
{0x5cbb9ad1,0x862d,0x11dc,0xa9,0x4d,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
/*
* Boot partition used by GRUB 2.
*/
#define GPT_ENT_TYPE_BIOS_BOOT \
{0x21686148,0x6449,0x6e6f,0x74,0x4e,{0x65,0x65,0x64,0x45,0x46,0x49}}
#endif /* _SYS_GPT_H_ */
......@@ -89,8 +89,10 @@ static long outputmaxsec = 0;
} \
}
#define sectobytes(s) ((off_t)(s) * SECSIZE)
#define bytestosec(b) (uint32_t)((b) / SECSIZE)
/* XXX keep macros in sync with global.h */
int secsize = 512;
#define sectobytes(s) ((off_t)(s) * secsize)
#define bytestosec(b) (uint32_t)((b) / secsize)
/*
* Sector alignment is required for buffers used with read/write on
......@@ -127,8 +129,8 @@ static int readretries = 0;
static int nodecompress = 0;
static char chunkbuf[CHUNKSIZE];
#endif
int readmbr(int slice);
int fixmbr(int slice, int dtype);
int getslicebounds(int slice);
void setslicetype(int slice, int dostype);
static int write_subblock(int, const char *, int);
static int inflate_subblock(const char *);
void writezeros(off_t offset, off_t zcount);
......@@ -785,8 +787,8 @@ main(int argc, char *argv[])
"cannot specify a slice\n");
exit(1);
}
if (readmbr(slice)) {
fprintf(stderr, "Failed to read MBR\n");
if (getslicebounds(slice)) {
fprintf(stderr, "Failed to read slice bounds\n");
exit(1);
}
close(outfd);
......@@ -835,8 +837,8 @@ main(int argc, char *argv[])
if (slice) {
off_t minseek;
if (readmbr(slice)) {
fprintf(stderr, "Failed to read MBR\n");
if (getslicebounds(slice)) {
fprintf(stderr, "Failed to read slice bounds\n");
exit(1);
}
minseek = sectobytes(outputminsec);
......@@ -954,7 +956,7 @@ main(int argc, char *argv[])
/* Set the MBR type if necesary */
if (slice && dostype >= 0)
fixmbr(slice, dostype);
setslicetype(slice, dostype);
/* Flush any cached data and close the output device */
if (outfd >= 0) {
......@@ -1082,8 +1084,8 @@ ImageUnzipInit(char *filename, int _slice, int _debug, int _fill,
if (slice) {
off_t minseek;
if (readmbr(slice)) {
fprintf(stderr, "Failed to read MBR\n");
if (getslicebounds(slice)) {
fprintf(stderr, "Failed to read slice bounds\n");
exit(1);
}
minseek = sectobytes(outputminsec);
......@@ -1162,7 +1164,7 @@ ImageUnzipQuit(void)
/* Set the MBR type if necesary */
if (slice && dostype >= 0)
fixmbr(slice, dostype);
setslicetype(slice, dostype);
/* Now we can close it */
if (outfd >= 0)
......@@ -1904,72 +1906,28 @@ zero_remainder()
}
#include "sliceinfo.h"
#include "mbr/mbr.h"
static long long outputmaxsize = 0;
/*
* XXX Argh! We have a problem.
*
* The definition of the DOS boot block (doslabel struct) has an embedded
* struct (parts) that is at a non-word boundary according to the on-disk
* layout of the boot block. Left to its own devices, the compiler will
* offset the parts struct inserting an implicit 2 bytes of padding before
* it, so that word accesses within the struct (in particular, dp_start
* and dp_size) are aligned. (Once upon a time, such unaligned accesses
* were fatal. Now they are not on most x86-en, but we try to avoid it
* anyway.) The problem is that the implicit padding means the struct
* doesn't line up with the on-disk structure. So, struct doslabel inserts
* 2 bytes of padding at the beginning of the struct ("align") so that the
* "parts" struct does fall on a word boundary without padding. The price
* we pay is that now whenever we read or write such a struct, we do so at
* an offset 2 bytes in (the "pad2" field).
*
* That was all fine until we started using the O_DIRECT flag on open of
* a device. O_DIRECT requires that the data buffer we pass be 512-byte
* aligned, at least on Linux. But there is no way we can have both the
* read-buffer aligned and the "parts" struct within the doslabel aligned.
* One solution is to align the read buffer and just use the "packed"
* attribute for the struct so that the compiler won't try to align it
* and we would wind up doing unaligned word accesses. However, this would
* be way too simple. Instead, we retain the obscure structure definition
* and COPY the data from the read/write buffer into a properly (mis)aligned
* doslabel struct for access!
*/
static char mbrbuf[DOSPARTSIZE+SECSIZE];
/*
* Parse the DOS partition table to set the bounds of the slice we
* are writing to.
*/
int
readmbr(int slice)
getslicebounds(int slice)
{
struct doslabel doslabel;
int cc;
char *mbr = SECALIGN(mbrbuf);
struct iz_slice parttab[MAXSLICES+1];
if (slice < 1 || slice > 4) {
fprintf(stderr, "Slice must be 1, 2, 3, or 4\n");
if (slice < 1 || slice > MAXSLICES) {
fprintf(stderr, "Slice must be 1-%d\n", MAXSLICES);
return 1;
}
if ((cc = devread(outfd, mbr, DOSPARTSIZE)) < 0) {
perror("Could not read DOS label");
return 1;
}
if (cc != DOSPARTSIZE) {
fprintf(stderr, "Could not get the entire DOS label\n");
if (parse_mbr(outfd, parttab))
return 1;
}
memcpy(&doslabel.pad2, mbr, DOSPARTSIZE);
if (doslabel.magic != BOOT_MAGIC) {
fprintf(stderr, "Wrong magic number in DOS partition table\n");
if (parttab[slice-1].type == IZTYPE_INVALID)
return 1;
}
outputminsec = doslabel.parts[slice-1].dp_start;
outputmaxsec = doslabel.parts[slice-1].dp_start +
doslabel.parts[slice-1].dp_size;
outputminsec = parttab[slice-1].offset;
outputmaxsec = parttab[slice-1].offset + parttab[slice-1].size;
outputmaxsize = (long long)sectobytes(outputmaxsec - outputminsec);
if (debug) {
......@@ -1977,49 +1935,17 @@ readmbr(int slice)
slice, outputminsec, outputmaxsec, outputmaxsize);
}
return 0;
}
int
fixmbr(int slice, int dtype)
void
setslicetype(int slice, int dostype)
{
struct doslabel doslabel;
int cc;
char *mbr = SECALIGN(mbrbuf);
if (lseek(outfd, (off_t)0, SEEK_SET) < 0) {
perror("Could not seek to DOS label");
return 1;
}
if ((cc = devread(outfd, mbr, DOSPARTSIZE)) < 0) {
perror("Could not read DOS label");
return 1;
}
if (cc != DOSPARTSIZE) {
fprintf(stderr, "Could not get the entire DOS label\n");
return 1;
}
memcpy(&doslabel.pad2, mbr, DOSPARTSIZE);
if (doslabel.magic != BOOT_MAGIC) {
fprintf(stderr, "Wrong magic number in DOS partition table\n");
return 1;
}
if (doslabel.parts[slice-1].dp_typ != dostype) {
doslabel.parts[slice-1].dp_typ = dostype;
if (lseek(outfd, (off_t)0, SEEK_SET) < 0) {
perror("Could not seek to DOS label");
return 1;
}
memcpy(mbr, &doslabel.pad2, DOSPARTSIZE);
cc = write(outfd, mbr, DOSPARTSIZE);
if (cc != DOSPARTSIZE) {
perror("Could not write DOS label");
return 1;
}
if (set_mbr_type(outfd, slice, (iz_type)dostype))
fprintf(stderr, "WARNING: could not set MBR type!\n");
else
fprintf(stderr, "Set type of DOS partition %d to %d\n",
slice, dostype);
}
return 0;
}
static struct blockreloc *reloctable;
......
This diff is collapsed.
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = @top_builddir@
SUBDIR = $(subst $(TESTBED_SRCDIR)/,,$(SRCDIR))
MAINDIR = $(SRCDIR)/..
include $(OBJDIR)/Makeconf
CFLAGS += $(SUBDIRCFLAGS) -I$(MAINDIR) -I$(SRCDIR)
all: libmbr.a
include $(TESTBED_SRCDIR)/GNUmakerules
OBJS = mbr.o