Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
f1f88348
Commit
f1f88348
authored
Jan 20, 2015
by
Mike Hibler
Browse files
Merge branch 'imagezip-gpt'
parents
a40fb744
e3209e0f
Changes
29
Hide whitespace changes
Inline
Side-by-side
Makeconf.in
View file @
f1f88348
#
# Copyright (c) 2000-201
2
University of Utah and the Flux Group.
# Copyright (c) 2000-201
4
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 = ${
OBJ
DIR}/clientside/os/imagezip
TESTBED_IMAGEZIPSRCDIR = ${
TESTBED_SRC
DIR}/clientside/os/imagezip
clientside/Makeconf.in
View file @
f1f88348
#
# Copyright (c) 2000-201
2
University of Utah and the Flux Group.
# Copyright (c) 2000-201
4
University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
...
...
@@ -72,4 +72,4 @@ ELVIN_COMPAT = @ELVIN_COMPAT@
WITH_EMULAB = @WITH_EMULAB@
TESTBED_LIBSRCDIR = ${TESTBED_SRCDIR}/lib
TESTBED_LIBOBJDIR = ${OBJDIR}/lib
TESTBED_IMAGEZIPSRCDIR = ${
OBJ
DIR}/os/imagezip
TESTBED_IMAGEZIPSRCDIR = ${
TESTBED_SRC
DIR}/os/imagezip
clientside/configure
View file @
f1f88348
...
...
@@ -4553,6 +4553,8 @@ outfiles="Makeconf GNUmakefile setversion \
os/growdisk/GNUmakefile
\
os/zapdisk/GNUmakefile
\
os/imagezip/GNUmakefile
\
os/imagezip/mbr/GNUmakefile
\
os/imagezip/gpt/GNUmakefile
\
os/imagezip/ffs/GNUmakefile
\
os/imagezip/extfs/GNUmakefile
\
$winfiles
\
...
...
clientside/configure.ac
View file @
f1f88348
...
...
@@ -290,6 +290,8 @@ outfiles="Makeconf GNUmakefile setversion \
os/growdisk/GNUmakefile \
os/zapdisk/GNUmakefile \
os/imagezip/GNUmakefile \
os/imagezip/mbr/GNUmakefile \
os/imagezip/gpt/GNUmakefile \
os/imagezip/ffs/GNUmakefile \
os/imagezip/extfs/GNUmakefile \
$winfiles \
...
...
clientside/os/frisbee.redux/GNUmakefile.in
View file @
f1f88348
...
...
@@ -84,7 +84,7 @@ subboss:
include $(TESTBED_SRCDIR)/GNUmakerules
FRISBEE
DIR = $(TESTBED_IMAGEZIPSRCDIR)
IZSRC
DIR = $(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: $(
FRISBEE
DIR)/disksize.c
$(CC) -c $(CFLAGS) $(IUZFLAGS)
-I$(FRISBEEDIR)
-o disksize.o $<
disksize.o: $(
IZSRC
DIR)/disksize.c
$(CC) -c $(CFLAGS) $(IUZFLAGS) -o disksize.o $<
checksum.o: $(
FRISBEE
DIR)/checksum.c
$(CC) -c $(CFLAGS) $(IUZFLAGS)
-I$(FRISBEEDIR)
-o checksum.o $<
checksum.o: $(
IZSRC
DIR)/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
...
...
clientside/os/imagezip/GNUmakefile.in
View file @
f1f88348
...
...
@@ -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 = 1
#
# 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
...
...
@@ -229,6 +251,9 @@ imagehash: imagehash.o version.o
imagehash.o: imagehash.c
$(CC) -c $(HASHCFLAGS) -o imagehash.o $<
sizetest: disksize.c
$(CC) -DTEST $< -o sizetest
$(SUBDIRS):
@$(MAKE) SUBDIRCFLAGS="$(SUBDIRCFLAGS)" -C $@ all
...
...
clientside/os/imagezip/disksize.c
View file @
f1f88348
/*
* Copyright (c) 2000-20
06
University of Utah and the Flux Group.
* Copyright (c) 2000-20
14
University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
...
...
@@ -25,6 +25,7 @@
* Determine the size of the target disk in sectors.
*/
#include
<inttypes.h>
#include
<unistd.h>
#include
<stdio.h>
...
...
@@ -41,7 +42,7 @@
#endif
#endif
u
nsigned
long
u
int64_t
getdisksize
(
int
fd
)
{
unsigned
long
disksize
=
0
;
...
...
@@ -54,6 +55,9 @@ getdisksize(int fd)
rv
=
ioctl
(
fd
,
BLKGETSIZE
,
&
disksize
);
if
(
rv
<
0
)
disksize
=
0
;
#ifdef TEST
fprintf
(
stderr
,
"Linux BLKGETSIZE returned %lu
\n
"
,
disksize
);
#endif
}
#else
#ifdef DIOCGMEDIASIZE
...
...
@@ -66,6 +70,9 @@ getdisksize(int fd)
rv
=
ioctl
(
fd
,
DIOCGMEDIASIZE
,
&
dsize
);
if
(
rv
>=
0
)
disksize
=
(
unsigned
long
)(
dsize
/
ssize
);
#ifdef TEST
fprintf
(
stderr
,
"BSD BIOCGMEDIASIZE returned %lu
\n
"
,
disksize
);
#endif
}
#else
#ifdef DIOCGDINFO
...
...
@@ -76,6 +83,9 @@ getdisksize(int fd)
rv
=
ioctl
(
fd
,
DIOCGDINFO
,
&
label
);
if
(
rv
>=
0
)
disksize
=
label
.
d_secperunit
;
#ifdef TEST
fprintf
(
stderr
,
"BSD DIOCGDINFO returned %lu
\n
"
,
disksize
);
#endif
}
#endif
#endif
...
...
@@ -93,6 +103,10 @@ getdisksize(int fd)
lastoff
=
lseek
(
fd
,
(
off_t
)
0
,
SEEK_END
);
if
(
lastoff
>
0
)
disksize
=
(
unsigned
long
)(
lastoff
/
ssize
);
#ifdef TEST
fprintf
(
stderr
,
"lseek SEEK_END returned %lu
\n
"
,
disksize
);
#endif
}
/*
...
...
@@ -111,3 +125,33 @@ getdisksize(int fd)
return
disksize
;
}
#ifdef TEST
#include
<fcntl.h>
int
main
(
int
argc
,
char
**
argv
)
{
uint64_t
dsize
;
int
fd
;
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"Usage: %s disk
\n
"
,
argv
[
0
]);
return
1
;
}
fd
=
open
(
argv
[
1
],
O_RDONLY
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Could not open '%s'
\n
"
,
argv
[
1
]);
return
1
;
}
dsize
=
getdisksize
(
fd
);
close
(
fd
);
fprintf
(
stderr
,
"%s: size is %llu sectors
\n
"
,
argv
[
1
],
(
unsigned
long
long
)
dsize
);
return
0
;
}
#endif
clientside/os/imagezip/extfs/extfs.c
View file @
f1f88348
/*
* Copyright (c) 2000-201
2
University of Utah and the Flux Group.
* Copyright (c) 2000-201
4
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
,
i
nt
stype
,
u_int32_t
start
,
u_int32_t
size
,
read_linuxslice
(
int
slice
,
i
z_type
stype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
)
{
#define LINUX_SUPERBLOCK_OFFSET 1024
...
...
@@ -73,8 +73,8 @@ read_linuxslice(int slice, int stype, u_int32_t start, u_int32_t size,
assert
((
sizeof
(
fs
)
&
~
LINUX_SUPERBLOCK_SIZE
)
==
0
);
if
(
debug
)
fprintf
(
stderr
,
" P%d %s
Linux Slice)
\n
"
,
dosslice
,
rval
?
"(Bootable"
:
"("
);
fprintf
(
stderr
,
" P%d %sLinux Slice)
\n
"
,
dosslice
,
rval
?
"(Bootable
"
:
"("
);
/*
* Skip ahead to the superblock.
...
...
@@ -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
,
i
nt
stype
,
u_int32_t
start
,
u_int32_t
size
,
read_linuxswap
(
int
slice
,
i
z_type
stype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
)
{
if
(
debug
)
{
...
...
clientside/os/imagezip/fat/fat_glue.c
View file @
f1f88348
/*
* Copyright (c) 2003-20
05
University of Utah and the Flux Group.
* Copyright (c) 2003-20
14
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
,
i
nt
stype
,
u_int32_t
start
,
u_int32_t
size
,
read_fatslice
(
int
slice
,
i
z_type
stype
,
iz_lba
start
,
iz_size
size
,
char
*
sfilename
,
int
infd
)
{
struct
bootblock
boot
;
...
...
clientside/os/imagezip/ffs/ffs.c
View file @
f1f88348
...
...
@@ -50,6 +50,9 @@
#undef CLEAR_FREE_INODES
#endif
static
int
_read_bsdslice
(
int
slice
,
iz_type
bsdtype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
,
int
musthavelabel
);
static
int
read_bsdpartition
(
int
infd
,
struct
disklabel
*
dlabel
,
int
part
);
static
int
read_bsdsblock
(
int
infd
,
u_int32_t
off
,
int
part
,
struct
fs
*
fsp
);
static
int
read_bsdcg
(
struct
fs
*
fsp
,
struct
cg
*
cgp
,
int
cg
,
u_int32_t
off
);
...
...
@@ -66,8 +69,35 @@ static int32_t freecount;
* Operate on a BSD slice
*/
int
read_bsdslice
(
int
slice
,
i
nt
bsdtype
,
u_int32_t
start
,
u_int32_t
size
,
read_bsdslice
(
int
slice
,
i
z_type
bsdtype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
)
{
return
_read_bsdslice
(
slice
,
bsdtype
,
start
,
size
,
sname
,
infd
,
1
);
}
int
read_bsdslicenl
(
int
slice
,
iz_type
bsdtype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
)
{
return
_read_bsdslice
(
slice
,
bsdtype
,
start
,
size
,
sname
,
infd
,
0
);
}
int
read_bsdswapslice
(
int
slice
,
iz_type
bsdtype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
)
{
if
(
debug
)
fprintf
(
stderr
,
" P%d (FreeBSD Swap Slice)
\n
"
,
slice
+
1
);
/* skip the whole thing */
addskip
(
start
,
size
);
return
0
;
}
static
int
_read_bsdslice
(
int
slice
,
iz_type
bsdtype
,
iz_lba
start
,
iz_size
size
,
char
*
sname
,
int
infd
,
int
musthavelabel
)
{
int
cc
,
i
,
rval
=
0
,
npart
,
absoffset
;
union
{
...
...
@@ -77,7 +107,9 @@ 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_OPENBSD
?
"Open"
:
(
bsdtype
==
IZTYPE_386BSD
?
"Free"
:
"Unlabeled Free"
));
if
(
devlseek
(
infd
,
sectobytes
(
start
),
SEEK_SET
)
<
0
)
{
warn
(
"Could not seek to beginning of BSD slice"
);
...
...
@@ -106,24 +138,23 @@ read_bsdslice(int slice, int bsdtype, u_int32_t start, u_int32_t size,
*/
if
(
dlabel
.
label
.
d_magic
!=
DISKMAGIC
||
dlabel
.
label
.
d_magic2
!=
DISKMAGIC
)
{
#ifdef linux
/* not needed in BSD, a fake disklabel is created by the kernel */
/*
*
If we were forced with the bsdfs option,
*
assume this is
a single partition disk like a
*
memory or
vnode disk. We cons up a disklabel
*
This may be a situation in which there is no label
*
(e.g.,
a single partition disk like a
memory or
* vnode disk
or a GPT partition)
. We cons up a disklabel
* and let it rip.
*/
if
(
slice
==
-
1
)
{
if
(
!
musthavelabel
)
{
fprintf
(
stderr
,
"P%d: WARNING: No disklabel, "
"assuming single partition
\n
"
,
slice
+
1
);
dlabel
.
label
.
d_partitions
[
0
].
p_offset
=
0
;
dlabel
.
label
.
d_partitions
[
0
].
p_offset
=
start
;
dlabel
.
label
.
d_partitions
[
0
].
p_size
=
size
;
dlabel
.
label
.
d_partitions
[
0
].
p_fstype
=
FS_BSDFFS
;
return
read_bsdpartition
(
infd
,
&
dlabel
.
label
,
0
);
}
else
{
warnx
(
"Wrong magic number in BSD disklabel"
);
return
1
;
}
#endif
warnx
(
"Wrong magic number in BSD disklabel"
);
return
1
;
}
/*
...
...
@@ -148,7 +179,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
==
DOSP
TYP_OPENBSD
&&
i
>=
8
&&
i
<
16
)
if
(
bsdtype
==
IZ
TYP
E
_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 +202,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
==
DOSP
TYP_OPENBSD
&&
i
>=
8
&&
i
<
16
)
{
if
(
bsdtype
==
IZ
TYP
E
_OPENBSD
&&
i
>=
8
&&
i
<
16
)
{
if
(
debug
)
fprintf
(
stderr
,
" '%c' skipping, "
"OpenBSD mapping of DOS partition %d
\n
"
,
...
...
@@ -234,7 +265,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
==
DOSP
TYP_OPENBSD
&&
if
(
bsdtype
==
IZ
TYP
E
_OPENBSD
&&
(
i
==
2
||
(
i
>=
8
&&
i
<
16
)))
continue
;
...
...
@@ -247,7 +278,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
==
DOSP
TYP_OPENBSD
?
bsdtype
==
IZ
TYP
E
_OPENBSD
?
RELOC_OBSDDISKLABEL
:
RELOC_FBSDDISKLABEL
);
}
...
...
clientside/os/imagezip/global.h
View file @
f1f88348
...
...
@@ -45,8 +45,21 @@ extern int hasfixup(uint32_t soffset, uint32_t ssize);
extern
void
savefixups
(
void
);
extern
void
restorefixups
(
int
isempty
);
extern
void
dumpfixups
(
int
verbose
,
int
count
);
extern
uint64_t
getdisksize
(
int
fd
);
#ifdef WITH_MBR
extern
int
parse_mbr
(
int
fd
,
struct
iz_slice
*
parttab
,
iz_lba
*
startp
,
iz_size
*
sizep
,
int
dowarn
);
#endif
#ifdef WITH_GPT
extern
int
parse_gpt
(
int
fd
,
struct
iz_slice
*
parttab
,
iz_lba
*
startp
,
iz_size
*
sizep
,
int
dowarn
);
#endif
extern
SLICEMAP_PROCESS_PROTO
(
read_rawslice
);
extern
SLICEMAP_PROCESS_PROTO
(
read_bsdslice
);
extern
SLICEMAP_PROCESS_PROTO
(
read_bsdslicenl
);
extern
SLICEMAP_PROCESS_PROTO
(
read_bsdswapslice
);
extern
SLICEMAP_PROCESS_PROTO
(
read_linuxslice
);
extern
SLICEMAP_PROCESS_PROTO
(
read_linuxswap
);
extern
SLICEMAP_PROCESS_PROTO
(
read_ntfsslice
);
...
...
clientside/os/imagezip/gpt/GNUmakefile.in
0 → 100644
View file @
f1f88348
#
# 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 += -DIMAGEZIP $(SUBDIRCFLAGS) -I$(MAINDIR) -I$(SRCDIR)
all: libgpt.a
include $(TESTBED_SRCDIR)/GNUmakerules
OBJS = gpt.o crc32.o gpt_glue.o
gpt.o: gpt_glue.h gpt.h
crc32.o: crc32.h
gpt_glue.o: gpt_glue.h gpt.h
gpt_glue.o: $(MAINDIR)/global.h $(MAINDIR)/sliceinfo.h $(MAINDIR)/imagehdr.h
libgpt.a: $(OBJS)
$(AR) $(ARFLAGS) $@ $?
$(RANLIB) $@
install:
clean:
rm -f libgpt.a $(OBJS)
clientside/os/imagezip/gpt/crc32.c
0 → 100644
View file @
f1f88348
/*-
* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
* code or tables extracted from it, as desired without restriction.
*/
/*
* First, the polynomial itself and its table of feedback terms. The
* polynomial is
* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
*
* Note that we take it "backwards" and put the highest-order term in
* the lowest-order bit. The X^32 term is "implied"; the LSB is the
* X^31 term, etc. The X^0 term (usually shown as "+1") results in
* the MSB being 1
*
* Note that the usual hardware shift register implementation, which
* is what we're using (we're merely optimizing it by doing eight-bit
* chunks at a time) shifts bits into the lowest-order term. In our
* implementation, that means shifting towards the right. Why do we
* do it this way? Because the calculated CRC must be transmitted in
* order from highest-order term to lowest-order term. UARTs transmit
* characters in order from LSB to MSB. By storing the CRC this way
* we hand it to the UART in the order low-byte to high-byte; the UART
* sends each low-bit to hight-bit; and the result is transmission bit
* by bit from highest- to lowest-order term without requiring any bit
* shuffling on our part. Reception works similarly
*
* The feedback terms table consists of 256, 32-bit entries. Notes
*
* The table can be generated at runtime if desired; code to do so
* is shown later. It might not be obvious, but the feedback
* terms simply represent the results of eight shift/xor opera
* tions for all combinations of data and CRC register values
*
* The values must be right-shifted by eight bits by the "updcrc
* logic; the shift must be unsigned (bring in zeroes). On some
* hardware you could probably optimize the shift in assembler by
* using byte-swap instructions
* polynomial $edb88320
*
*
* CRC32 code derived from work by Gary S. Brown.
*/
#include
<sys/cdefs.h>
//__FBSDID("$FreeBSD: releng/10.1/sys/boot/common/crc32.c 233517 2012-03-26 18:22:04Z marius $");
#include
<sys/types.h>
#include
<inttypes.h>
#include
"crc32.h"
static
const
uint32_t
crc32_tab
[]
=
{
0x00000000
,
0x77073096
,
0xee0e612c
,
0x990951ba
,
0x076dc419
,
0x706af48f
,
0xe963a535
,
0x9e6495a3
,
0x0edb8832
,
0x79dcb8a4
,
0xe0d5e91e
,
0x97d2d988
,
0x09b64c2b
,
0x7eb17cbd
,
0xe7b82d07
,
0x90bf1d91
,
0x1db71064
,
0x6ab020f2
,
0xf3b97148
,
0x84be41de
,
0x1adad47d
,
0x6ddde4eb
,
0xf4d4b551
,
0x83d385c7
,
0x136c9856
,
0x646ba8c0
,
0xfd62f97a
,
0x8a65c9ec
,
0x14015c4f
,
0x63066cd9
,
0xfa0f3d63
,
0x8d080df5
,
0x3b6e20c8
,
0x4c69105e
,
0xd56041e4
,
0xa2677172
,
0x3c03e4d1
,
0x4b04d447
,
0xd20d85fd
,
0xa50ab56b
,
0x35b5a8fa
,
0x42b2986c
,
0xdbbbc9d6
,
0xacbcf940
,
0x32d86ce3
,
0x45df5c75
,
0xdcd60dcf
,
0xabd13d59
,
0x26d930ac
,
0x51de003a
,
0xc8d75180
,
0xbfd06116
,
0x21b4f4b5
,
0x56b3c423
,
0xcfba9599
,
0xb8bda50f
,
0x2802b89e
,
0x5f058808
,
0xc60cd9b2
,
0xb10be924
,
0x2f6f7c87
,
0x58684c11
,
0xc1611dab
,
0xb6662d3d
,
0x76dc4190
,
0x01db7106
,
0x98d220bc
,
0xefd5102a
,
0x71b18589
,
0x06b6b51f
,
0x9fbfe4a5
,
0xe8b8d433
,
0x7807c9a2
,
0x0f00f934
,
0x9609a88e
,
0xe10e9818
,
0x7f6a0dbb
,
0x086d3d2d
,
0x91646c97
,
0xe6635c01
,
0x6b6b51f4
,
0x1c6c6162
,
0x856530d8
,
0xf262004e
,
0x6c0695ed
,
0x1b01a57b
,
0x8208f4c1
,
0xf50fc457
,
0x65b0d9c6
,
0x12b7e950
,
0x8bbeb8ea
,
0xfcb9887c
,
0x62dd1ddf
,
0x15da2d49
,
0x8cd37cf3
,
0xfbd44c65
,
0x4db26158
,
0x3ab551ce
,
0xa3bc0074
,
0xd4bb30e2
,
0x4adfa541
,
0x3dd895d7
,
0xa4d1c46d
,
0xd3d6f4fb
,
0x4369e96a
,
0x346ed9fc
,
0xad678846
,
0xda60b8d0
,
0x44042d73
,
0x33031de5
,
0xaa0a4c5f
,
0xdd0d7cc9
,
0x5005713c
,
0x270241aa
,
0xbe0b1010
,
0xc90c2086
,
0x5768b525
,
0x206f85b3
,
0xb966d409
,
0xce61e49f
,
0x5edef90e
,
0x29d9c998
,
0xb0d09822
,
0xc7d7a8b4
,
0x59b33d17
,
0x2eb40d81
,
0xb7bd5c3b
,
0xc0ba6cad
,
0xedb88320
,
0x9abfb3b6
,
0x03b6e20c
,
0x74b1d29a
,
0xead54739
,
0x9dd277af
,
0x04db2615
,
0x73dc1683
,
0xe3630b12
,
0x94643b84
,
0x0d6d6a3e
,
0x7a6a5aa8
,
0xe40ecf0b
,
0x9309ff9d
,
0x0a00ae27
,
0x7d079eb1
,
0xf00f9344
,
0x8708a3d2
,
0x1e01f268
,
0x6906c2fe
,
0xf762575d
,
0x806567cb
,
0x196c3671
,
0x6e6b06e7
,
0xfed41b76
,
0x89d32be0
,
0x10da7a5a
,
0x67dd4acc
,
0xf9b9df6f
,
0x8ebeeff9
,
0x17b7be43
,
0x60b08ed5
,
0xd6d6a3e8
,
0xa1d1937e
,
0x38d8c2c4
,
0x4fdff252
,
0xd1bb67f1
,
0xa6bc5767
,
0x3fb506dd
,
0x48b2364b
,
0xd80d2bda
,
0xaf0a1b4c
,
0x36034af6
,
0x41047a60
,
0xdf60efc3
,
0xa867df55
,
0x316e8eef
,
0x4669be79
,
0xcb61b38c
,
0xbc66831a
,
0x256fd2a0
,
0x5268e236
,
0xcc0c7795
,
0xbb0b4703
,
0x220216b9
,
0x5505262f
,
0xc5ba3bbe
,
0xb2bd0b28
,
0x2bb45a92
,
0x5cb36a04
,
0xc2d7ffa7
,
0xb5d0cf31
,
0x2cd99e8b
,
0x5bdeae1d
,
0x9b64c2b0
,
0xec63f226
,
0x756aa39c
,
0x026d930a
,
0x9c0906a9
,
0xeb0e363f
,
0x72076785
,
0x05005713
,
0x95bf4a82
,
0xe2b87a14
,
0x7bb12bae
,
0x0cb61b38
,
0x92d28e9b
,
0xe5d5be0d
,
0x7cdcefb7
,
0x0bdbdf21
,
0x86d3d2d4
,
0xf1d4e242
,
0x68ddb3f8
,
0x1fda836e
,
0x81be16cd
,
0xf6b9265b
,
0x6fb077e1
,
0x18b74777
,
0x88085ae6
,
0xff0f6a70
,
0x66063bca
,
0x11010b5c
,
0x8f659eff
,
0xf862ae69
,
0x616bffd3
,
0x166ccf45
,
0xa00ae278
,
0xd70dd2ee
,
0x4e048354
,
0x3903b3c2
,
0xa7672661
,
0xd06016f7
,
0x4969474d
,
0x3e6e77db
,
0xaed16a4a
,
0xd9d65adc
,
0x40df0b66
,
0x37d83bf0
,
0xa9bcae53
,
0xdebb9ec5
,
0x47b2cf7f
,
0x30b5ffe9
,
0xbdbdf21c
,
0xcabac28a
,
0x53b39330
,
0x24b4a3a6
,
0xbad03605
,
0xcdd70693
,
0x54de5729
,
0x23d967bf
,
0xb3667a2e
,
0xc4614ab8
,
0x5d681b02
,
0x2a6f2b94
,
0xb40bbe37
,
0xc30c8ea1
,
0x5a05df1b
,
0x2d02ef8d
};
uint32_t
crc32
(
const
void
*
buf
,
size_t
size
)
{
const
uint8_t
*
p
=
buf
;
uint32_t
crc
;
crc