Deleted Added
full compact
db_textdump.c (174921) db_textdump.c (175199)
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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27/*-
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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27/*-
28 * Kernel text-dump support: allow a series of text files to be written to
29 * the dump partition for later recovery, including captured DDB output, the
30 * kernel configuration, message buffer, panic message, etc. This allows for
31 * a more compact representation of critical debugging information than
32 * traditional binary dumps, as well as allowing dump information to be used
33 * without access to kernel symbols, source code, etc.
28 * Kernel text-dump support: write a series of text files to the dump
29 * partition for later recovery, including captured DDB output, kernel
30 * configuration, message buffer, and panic message. This allows for a more
31 * compact representation of critical debugging information than traditional
32 * binary dumps, as well as allowing dump information to be used without
33 * access to kernel symbols, source code, etc.
34 *
35 * Storage Layout
36 * --------------
37 *
38 * Crash dumps are aligned to the end of the dump or swap partition in order
39 * to minimize the chances of swap duing fsck eating into the dump. However,
40 * unlike a memory dump, we don't know the size of the textdump a priori, so
41 * can't just write it out sequentially in order from a known starting point
42 * calculated with respect to the end of the partition. In order to address
43 * this, we actually write out the textdump in reverse block order, allowing
44 * us to directly align it to the end of the partition and then write out the
45 * dump header and trailer before and after it once done. savecore(8) must
46 * know to reverse the order of the blocks in order to produce a readable
47 * file.
48 *
34 *
35 * Storage Layout
36 * --------------
37 *
38 * Crash dumps are aligned to the end of the dump or swap partition in order
39 * to minimize the chances of swap duing fsck eating into the dump. However,
40 * unlike a memory dump, we don't know the size of the textdump a priori, so
41 * can't just write it out sequentially in order from a known starting point
42 * calculated with respect to the end of the partition. In order to address
43 * this, we actually write out the textdump in reverse block order, allowing
44 * us to directly align it to the end of the partition and then write out the
45 * dump header and trailer before and after it once done. savecore(8) must
46 * know to reverse the order of the blocks in order to produce a readable
47 * file.
48 *
49 * Data is written out in the 'tar' file format, as it provides the facility
50 * to write data incrementally as a stream without reference to previous
51 * files.
49 * Data is written out in the ustar file format so that we can write data
50 * incrementally as a stream without reference to previous files.
52 *
53 * TODO
54 * ----
55 *
56 * - Allow subsytems to register to submit files for inclusion in the text
57 * dump in a generic way.
58 */
59
60#include <sys/cdefs.h>
51 *
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>
61__FBSDID("$FreeBSD: head/sys/ddb/db_textdump.c 174921 2007-12-26 11:32:33Z rwatson $");
60__FBSDID("$FreeBSD: head/sys/ddb/db_textdump.c 175199 2008-01-10 00:26:47Z rwatson $");
62
63#include "opt_config.h"
64
65#include <sys/param.h>
66#include <sys/conf.h>
67#include <sys/kernel.h>
68#include <sys/kerneldump.h>
69#include <sys/msgbuf.h>

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

196 strncpy(kdh->hostname, 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/*
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>

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

195 strncpy(kdh->hostname, hostname, sizeof(kdh->hostname));
196 strncpy(kdh->versionstring, version, sizeof(kdh->versionstring));
197 if (panicstr != NULL)
198 strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
199 kdh->parity = kerneldump_parity(kdh);
200}
201
202/*
204 * Calculate and fill in the checksum for a tar header.
203 * 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
212 for (i = 0; i < sizeof(uhp->uh_sum); i++)

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

264 di->mediaoffset, TEXTDUMP_BLOCKSIZE);
265 return (textdump_error);
266}
267
268/*
269 * Interfaces to save and restore the dump offset, so that printers can go
270 * back to rewrite a header if required, while avoiding their knowing about
271 * the global layout of the blocks.
204 */
205static void
206ustar_checksum(struct ustar_header *uhp)
207{
208 u_int sum;
209 int i;
210
211 for (i = 0; i < sizeof(uhp->uh_sum); i++)

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

263 di->mediaoffset, TEXTDUMP_BLOCKSIZE);
264 return (textdump_error);
265}
266
267/*
268 * Interfaces to save and restore the dump offset, so that printers can go
269 * back to rewrite a header if required, while avoiding their knowing about
270 * the global layout of the blocks.
271 *
272 * If we ever want to support writing textdumps to tape or other
273 * stream-oriented target, we'll need to remove this.
272 */
273void
274textdump_saveoff(off_t *offsetp)
275{
276
277 *offsetp = textdump_offset;
278}
279

--- 276 unchanged lines hidden ---
274 */
275void
276textdump_saveoff(off_t *offsetp)
277{
278
279 *offsetp = textdump_offset;
280}
281

--- 276 unchanged lines hidden ---