Deleted Added
full compact
db_textdump.c (181803) db_textdump.c (183527)
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 43 unchanged lines hidden (view full) ---

52 * TODO
53 * ----
54 *
55 * - Allow subsytems to register to submit files for inclusion in the text
56 * dump in a generic way.
57 */
58
59#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 43 unchanged lines hidden (view full) ---

52 * TODO
53 * ----
54 *
55 * - Allow subsytems to register to submit files for inclusion in the text
56 * dump in a generic way.
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/ddb/db_textdump.c 181803 2008-08-17 23:27:27Z bz $");
60__FBSDID("$FreeBSD: head/sys/ddb/db_textdump.c 183527 2008-10-01 22:08:53Z peter $");
61
62#include "opt_config.h"
63
64#include <sys/param.h>
65#include <sys/conf.h>
66#include <sys/kernel.h>
67#include <sys/kerneldump.h>
68#include <sys/msgbuf.h>

--- 103 unchanged lines hidden (view full) ---

172
173/*
174 * Statically allocate space to prepare block-sized headers and data.
175 */
176char textdump_block_buffer[TEXTDUMP_BLOCKSIZE];
177static struct kerneldumpheader kdh;
178
179/*
61
62#include "opt_config.h"
63
64#include <sys/param.h>
65#include <sys/conf.h>
66#include <sys/kernel.h>
67#include <sys/kerneldump.h>
68#include <sys/msgbuf.h>

--- 103 unchanged lines hidden (view full) ---

172
173/*
174 * Statically allocate space to prepare block-sized headers and data.
175 */
176char textdump_block_buffer[TEXTDUMP_BLOCKSIZE];
177static struct kerneldumpheader kdh;
178
179/*
180 * Text dumps are prefixed with a normal kernel dump header but with a
181 * different magic number to allow them to be uniquely identified.
182 */
183static void
184mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver,
185 uint64_t dumplen, uint32_t blksz)
186{
187
188 bzero(kdh, sizeof(*kdh));
189 strncpy(kdh->magic, TEXTDUMPMAGIC, sizeof(kdh->magic));
190 strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
191 kdh->version = htod32(KERNELDUMPVERSION);
192 kdh->architectureversion = htod32(archver);
193 kdh->dumplength = htod64(dumplen);
194 kdh->dumptime = htod64(time_second);
195 kdh->blocksize = htod32(blksz);
196 strncpy(kdh->hostname, G_hostname, sizeof(kdh->hostname));
197 strncpy(kdh->versionstring, version, sizeof(kdh->versionstring));
198 if (panicstr != NULL)
199 strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
200 kdh->parity = kerneldump_parity(kdh);
201}
202
203/*
204 * Calculate and fill in the checksum for a ustar header.
205 */
206static void
207ustar_checksum(struct ustar_header *uhp)
208{
209 u_int sum;
210 int i;
211

--- 251 unchanged lines hidden (view full) ---

463 /*
464 * Position the start of the dump so that we'll write the kernel dump
465 * trailer immediately before the end of the partition, and then work
466 * our way back. We will rewrite this header later to reflect the
467 * true size if things go well.
468 */
469 textdump_offset = di->mediasize - sizeof(kdh);
470 textdump_saveoff(&trailer_offset);
180 * Calculate and fill in the checksum for a ustar header.
181 */
182static void
183ustar_checksum(struct ustar_header *uhp)
184{
185 u_int sum;
186 int i;
187

--- 251 unchanged lines hidden (view full) ---

439 /*
440 * Position the start of the dump so that we'll write the kernel dump
441 * trailer immediately before the end of the partition, and then work
442 * our way back. We will rewrite this header later to reflect the
443 * true size if things go well.
444 */
445 textdump_offset = di->mediasize - sizeof(kdh);
446 textdump_saveoff(&trailer_offset);
471 mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE);
447 mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE);
472 (void)textdump_writenextblock(di, (char *)&kdh);
473
474 /*
475 * Write a series of files in ustar format.
476 */
477 if (textdump_do_ddb)
478 db_capture_dump(di);
479#ifdef INCLUDE_CONFIG_FILE

--- 8 unchanged lines hidden (view full) ---

488 textdump_dump_version(di);
489
490 /*
491 * Now that we know the true size, we can write out the header, then
492 * seek back to the end and rewrite the trailer with the correct
493 * size.
494 */
495 dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE);
448 (void)textdump_writenextblock(di, (char *)&kdh);
449
450 /*
451 * Write a series of files in ustar format.
452 */
453 if (textdump_do_ddb)
454 db_capture_dump(di);
455#ifdef INCLUDE_CONFIG_FILE

--- 8 unchanged lines hidden (view full) ---

464 textdump_dump_version(di);
465
466 /*
467 * Now that we know the true size, we can write out the header, then
468 * seek back to the end and rewrite the trailer with the correct
469 * size.
470 */
471 dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE);
496 mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, dumplen,
472 mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, dumplen,
497 TEXTDUMP_BLOCKSIZE);
498 (void)textdump_writenextblock(di, (char *)&kdh);
499 textdump_restoreoff(trailer_offset);
500 (void)textdump_writenextblock(di, (char *)&kdh);
501
502 /*
503 * Terminate the dump, report any errors, and clear the pending flag.
504 */

--- 54 unchanged lines hidden ---
473 TEXTDUMP_BLOCKSIZE);
474 (void)textdump_writenextblock(di, (char *)&kdh);
475 textdump_restoreoff(trailer_offset);
476 (void)textdump_writenextblock(di, (char *)&kdh);
477
478 /*
479 * Terminate the dump, report any errors, and clear the pending flag.
480 */

--- 54 unchanged lines hidden ---