Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / tools / dumpscan / backuphdr.c
1 /*
2 * CMUCS AFStools
3 * dumpscan - routines for scanning and manipulating AFS volume dumps
4 *
5 * Copyright (c) 1998 Carnegie Mellon University
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software_Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
27 */
28
29 /* backuphdr.c - Parse and print backup system headers */
30
31 #include <stdlib.h>
32
33 #include "dumpscan.h"
34 #include "dumpscan_errs.h"
35 #include "stagehdr.h"
36
37 afs_uint32
38 try_backuphdr(XFILE * X, char *tag, tagged_field * field, afs_uint32 value,
39 tag_parse_info * pi, void *g_refcon, void *l_refcon)
40 {
41 dump_parser *p = (dump_parser *) g_refcon;
42 backup_system_header bh;
43 dt_uint64 where;
44 afs_uint32 r;
45
46 /* Which header should we try (if any)? */
47 switch (*tag) {
48 case STAGE_VERSMIN:
49 r = ParseStageHdr(X, (unsigned char *)tag, &bh);
50 break;
51 default:
52 return DSERR_MAGIC;
53 }
54 if (r)
55 return r;
56
57 /* Do something with it... */
58 if (p->print_flags & DSPRINT_BCKHDR)
59 PrintBackupHdr(&bh);
60 if (p->cb_bckhdr) {
61 r = xftell(X, &where);
62 if (!r && p->cb_bckhdr)
63 r = (p->cb_bckhdr) (&bh, X, p->refcon);
64 if (p->flags & DSFLAG_SEEK) {
65 if (!r)
66 r = xfseek(X, &where);
67 else
68 xfseek(X, &where);
69 }
70 }
71 if (bh.server)
72 free(bh.server);
73 if (bh.part)
74 free(bh.part);
75 if (bh.volname)
76 free(bh.volname);
77 return r;
78 }
79
80
81 void
82 PrintBackupHdr(backup_system_header * hdr)
83 {
84 time_t from = hdr->from_date, to = hdr->to_date, dd = hdr->dump_date;
85
86 printf("* BACKUP SYSTEM HEADER\n");
87 printf(" Version: %d\n", hdr->version);
88 printf(" Volume: %s (%d)\n", hdr->volname, hdr->volid);
89 printf(" Location: %s %s\n", hdr->server, hdr->part);
90 printf(" Level: %d\n", hdr->level);
91 printf(" Range: %d => %d\n", hdr->from_date, hdr->to_date);
92 printf(" == %s", ctime(&from));
93 printf(" => %s", ctime(&to));
94 printf(" Dump Time: %d == %s", hdr->dump_date, ctime(&dd));
95 printf(" Dump Flags: 0x%08x\n", hdr->flags);
96 #ifdef NATIVE_UINT64
97 printf(" Length: %llu\n", hdr->dumplen);
98 #else
99 printf(" Length: %u,%u\n", hdr->dumplen.hi, hdr->dumplen.lo);
100 #endif
101 printf(" File Num: %d\n", hdr->filenum);
102 }