2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/jscan/dump_debug.c,v 1.7 2005/09/07 19:10:09 dillon Exp $
39 static void dump_debug_stream(struct jstream *js);
40 static int dump_debug_subrecord(struct jstream *js, off_t *off,
41 off_t recsize, int level);
42 static int dump_debug_payload(int16_t rectype, struct jstream *js, off_t off,
43 int recsize, int level);
46 dump_debug(struct jsession *ss, struct jdata *jd)
50 if ((js = jaddrecord(ss, jd)) != NULL) {
51 dump_debug_stream(js);
54 jsession_update_transid(ss, jd->jd_transid);
58 dump_debug_stream(struct jstream *js)
60 struct journal_rawrecbeg head;
63 jsread(js, 0, &head, sizeof(head));
65 sid = head.streamid & JREC_STREAMID_MASK;
66 printf("STREAM %04x %016llx {\n", (int)(u_int16_t)head.streamid,
68 if (sid >= JREC_STREAMID_JMIN && sid < JREC_STREAMID_JMAX) {
69 off_t off = sizeof(head);
71 dump_debug_subrecord(js, &off,
72 js->js_normalized_total - sizeof(head),
75 switch(head.streamid & JREC_STREAMID_MASK) {
76 case JREC_STREAMID_SYNCPT & JREC_STREAMID_MASK:
79 case JREC_STREAMID_PAD & JREC_STREAMID_MASK:
82 case JREC_STREAMID_DISCONT & JREC_STREAMID_MASK:
85 case JREC_STREAMID_ANNOTATE & JREC_STREAMID_MASK:
86 printf(" ANNOTATION\n");
97 dump_debug_subrecord(struct jstream *js, off_t *off, off_t recsize, int level)
99 struct journal_subrecord sub;
106 while (recsize > 0) {
107 if ((error = jsread(js, base, &sub, sizeof(sub))) != 0) {
110 printf("%*.*s", level * 4, level * 4, "");
111 printf("@%lld ", base);
112 printf("RECORD %s [%04x/%d]", type_to_name(sub.rectype),
113 (int)(u_int16_t)sub.rectype, sub.recsize);
114 if (sub.recsize == -1) {
115 if ((sub.rectype & JMASK_NESTED) == 0) {
116 printf("Record size of -1 only works for nested records\n");
120 payload = 0x7FFFFFFF;
121 subsize = 0x7FFFFFFF;
123 payload = sub.recsize - sizeof(sub);
124 subsize = (sub.recsize + 7) & ~7;
126 if (sub.rectype & JMASK_NESTED) {
129 *off = base + sizeof(sub);
130 error = dump_debug_subrecord(js, off, payload, level + 1);
132 printf("%*.*s}\n", level * 4, level * 4, "");
133 } else if (sub.rectype & JMASK_SUBRECORD) {
134 printf(" DATA (%d)", payload);
135 error = dump_debug_payload(sub.rectype, js, base + sizeof(sub), payload, level);
136 *off = base + sizeof(sub) + payload;
139 printf("[%d bytes of unknown content]\n", sub.recsize);
143 if (sub.recsize == -1) {
144 recsize -= ((*off + 7) & ~7) - base;
145 base = (*off + 7) & ~7;
148 subsize = sizeof(sub);
152 if (sub.rectype & JMASK_LAST)
160 dump_debug_payload(int16_t rectype, struct jstream *js, off_t off,
161 int recsize, int level)
163 enum { DT_NONE, DT_STRING, DT_DEC, DT_HEX, DT_OCT,
164 DT_DATA, DT_TIMESTAMP } dt = DT_DATA;
170 error = jsreadp(js, off, (const void **)&buf, recsize);
174 switch(rectype & ~JMASK_LAST) {
210 case JLEAF_RESERVED_0F:
212 case JLEAF_SYMLINKDATA:
255 for (i = 0; i < recsize; ++i)
256 stringout(stdout, buf[i], 1);
262 printf(" %d", (int)*(const u_int8_t *)buf);
265 printf(" %d", (int)*(const u_int16_t *)buf);
268 printf(" %d", (int)*(const u_int32_t *)buf);
271 printf(" %lld", (int64_t)*(const u_int64_t *)buf);
281 printf(" 0x%02x", (int)*(const u_int8_t *)buf);
284 printf(" 0x%04x", (int)*(const u_int16_t *)buf);
287 printf(" 0x%08x", (int)*(const u_int32_t *)buf);
290 printf(" 0x%016llx", (int64_t)*(const u_int64_t *)buf);
300 printf(" %03o", (int)*(const u_int8_t *)buf);
303 printf(" %06o", (int)*(const u_int16_t *)buf);
306 printf(" %011o", (int)*(const u_int32_t *)buf);
309 printf(" %022llo", (int64_t)*(const u_int64_t *)buf);
319 time_t t = ((const struct timespec *)buf)->tv_sec;
323 strftime(outbuf, sizeof(outbuf), " <%d-%b-%Y %H:%M:%S>", tp);
324 printf("%s", outbuf);
330 for (i = 0; i < recsize; ++i)
331 printf(" %02x", (int)(unsigned char)buf[i]);
333 for (i = 0; i < recsize; ++i)
334 stringout(stdout, buf[i], 0);
338 for (i = 0; i < recsize; i += 16) {
339 printf("%*.*s", level * 4 + 4, level * 4 + 4, "");
340 for (j = i; j < i + 16 && j < recsize; ++j)
341 printf(" %02x", (int)(unsigned char)buf[j]);
342 for (; j < i + 16; ++j)
345 for (j = i; j < i + 16 && j < recsize; ++j)
346 stringout(stdout, buf[j], 0);
349 printf("%*.*s}", level * 4, level * 4, "");