Add a subroutine for comparing kerneldump identifiers.

MFC after:	2 weeks
This commit is contained in:
Mark Johnston 2017-07-11 18:24:05 +00:00
parent 7f48d6a486
commit 4e287bd860

View file

@ -334,6 +334,13 @@ check_space(const char *savedir, off_t dumpsize, int bounds)
return (1);
}
static bool
compare_magic(const struct kerneldumpheader *kdh, const char *magic)
{
return (strncmp(kdh->magic, magic, sizeof(kdh->magic)) == 0);
}
#define BLOCKSIZE (1<<12)
#define BLOCKMASK (~(BLOCKSIZE-1))
@ -564,7 +571,7 @@ DoFile(const char *savedir, const char *device)
}
memcpy(&kdhl, temp, sizeof(kdhl));
istextdump = 0;
if (strncmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl) == 0) {
if (compare_magic(&kdhl, TEXTDUMPMAGIC)) {
if (verbose)
printf("textdump magic on last dump header on %s\n",
device);
@ -578,8 +585,7 @@ DoFile(const char *savedir, const char *device)
if (force == 0)
goto closefd;
}
} else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) ==
0) {
} else if (compare_magic(&kdhl, KERNELDUMPMAGIC)) {
if (dtoh32(kdhl.version) != KERNELDUMPVERSION) {
syslog(LOG_ERR,
"unknown version (%d) in last dump header on %s",
@ -598,8 +604,7 @@ DoFile(const char *savedir, const char *device)
if (force == 0)
goto closefd;
if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED,
sizeof kdhl.magic) == 0) {
if (compare_magic(&kdhl, KERNELDUMPMAGIC_CLEARED)) {
if (verbose)
printf("forcing magic on %s\n", device);
memcpy(kdhl.magic, KERNELDUMPMAGIC,