test-suite-pull-tools-directly-in-20020114
[openafs.git] / src / tests / 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 try_backuphdr(XFILE *X, char *tag, tagged_field *field,
38                       afs_uint32 value, tag_parse_info *pi,
39                       void *g_refcon, void *l_refcon)
40 {
41   dump_parser *p = (dump_parser *)g_refcon;
42   backup_system_header bh;
43   u_int64 where;
44   afs_uint32 r;
45
46   /* Which header should we try (if any)? */
47   switch (*tag) {
48     case STAGE_VERSMIN: r = ParseStageHdr(X, tag, &bh); break;
49     default: return DSERR_MAGIC;
50   }
51   if (r) return r;
52
53   /* Do something with it... */
54   if (p->print_flags & DSPRINT_BCKHDR) PrintBackupHdr(&bh);
55   if (p->cb_bckhdr) {
56     r = xftell(X, &where);
57     if (!r && p->cb_bckhdr)
58       r = (p->cb_bckhdr)(&bh, X, p->refcon);
59     if (p->flags & DSFLAG_SEEK) {
60       if (!r) r = xfseek(X, &where);
61       else xfseek(X, &where);
62     }
63   }
64   if (bh.server)  free(bh.server);
65   if (bh.part)    free(bh.part);
66   if (bh.volname) free(bh.volname);
67   return r;
68 }
69
70
71 void PrintBackupHdr(backup_system_header *hdr)
72 {
73   time_t from = hdr->from_date, to = hdr->to_date, dd = hdr->dump_date;
74
75   printf("* BACKUP SYSTEM HEADER\n");
76   printf(" Version:    %d\n", hdr->version);
77   printf(" Volume:     %s (%d)\n", hdr->volname, hdr->volid);
78   printf(" Location:   %s %s\n", hdr->server, hdr->part);
79   printf(" Level:      %d\n", hdr->level);
80   printf(" Range:      %d => %d\n", hdr->from_date, hdr->to_date);
81   printf("          == %s", ctime(&from));
82   printf("          => %s", ctime(&to));
83   printf(" Dump Time:  %d == %s", hdr->dump_date, ctime(&dd));
84   printf(" Dump Flags: 0x%08x\n", hdr->flags);
85   printf(" Length:     %d\n", hdr->dumplen);
86   printf(" File Num:   %d\n", hdr->filenum);
87 }