3 * dumpscan - routines for scanning and manipulating AFS volume dumps
5 * Copyright (c) 1998 Carnegie Mellon University
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.
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.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software_Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
29 /* parsevol.c - Parse a volume header */
32 #include "dumpscan_errs.h"
35 static afs_uint32 store_volhdr(XFILE *, unsigned char *, tagged_field *,
36 afs_uint32, tag_parse_info *, void *, void *);
37 static afs_uint32 parse_weekuse(XFILE *, unsigned char *, tagged_field *,
38 afs_uint32, tag_parse_info *, void *, void *);
40 /** Field list for volume headers **/
41 static tagged_field volhdr_fields[] = {
42 {VHTAG_VOLID, DKIND_INT32, " Volume ID: ", store_volhdr, 0, 0},
43 {VHTAG_VERS, DKIND_INT32, " Version: ", store_volhdr, 0, 0},
44 {VHTAG_VOLNAME, DKIND_STRING, " Volume name: ", store_volhdr, 0, 0},
45 {VHTAG_INSERV, DKIND_FLAG, " In service? ", store_volhdr, 0, 0},
46 {VHTAG_BLESSED, DKIND_FLAG, " Blessed? ", store_volhdr, 0, 0},
47 {VHTAG_VUNIQ, DKIND_INT32, " Uniquifier: ", store_volhdr, 0, 0},
48 {VHTAG_TYPE, DKIND_BYTE, " Type: ", store_volhdr, 0, 0},
49 {VHTAG_PARENT, DKIND_INT32, " Parent ID: ", store_volhdr, 0, 0},
50 {VHTAG_CLONE, DKIND_INT32, " Clone ID: ", store_volhdr, 0, 0},
51 {VHTAG_MAXQUOTA, DKIND_INT32, " Max quota: ", store_volhdr, 0, 0},
52 {VHTAG_MINQUOTA, DKIND_INT32, " Min quota: ", store_volhdr, 0, 0},
53 {VHTAG_DISKUSED, DKIND_INT32, " Disk used: ", store_volhdr, 0, 0},
54 {VHTAG_FILECNT, DKIND_INT32, " File count: ", store_volhdr, 0, 0},
55 {VHTAG_ACCOUNT, DKIND_INT32, " Account: ", store_volhdr, 0, 0},
56 {VHTAG_OWNER, DKIND_INT32, " Owner: ", store_volhdr, 0, 0},
57 {VHTAG_CREAT, DKIND_TIME, " Created: ", store_volhdr, 0, 0},
58 {VHTAG_ACCESS, DKIND_TIME, " Accessed: ", store_volhdr, 0, 0},
59 {VHTAG_UPDATE, DKIND_TIME, " Updated: ", store_volhdr, 0, 0},
60 {VHTAG_EXPIRE, DKIND_TIME, " Expires: ", store_volhdr, 0, 0},
61 {VHTAG_BACKUP, DKIND_TIME, " Backed up: ", store_volhdr, 0, 0},
62 {VHTAG_OFFLINE, DKIND_STRING, " Offine Msg: ", store_volhdr, 0, 0},
63 {VHTAG_MOTD, DKIND_STRING, " MOTD: ", store_volhdr, 0, 0},
64 {VHTAG_WEEKUSE, DKIND_SPECIAL, " Weekuse: ", parse_weekuse, 0, 0},
65 {VHTAG_DUDATE, DKIND_TIME, " Dayuse Date: ", store_volhdr, 0, 0},
66 {VHTAG_DAYUSE, DKIND_INT32, " Daily usage: ", store_volhdr, 0, 0},
71 /* Parse a volume header, including any tagged attributes, and call the
72 * volume-header callback, if one is defined.
75 parse_volhdr(XFILE * X, unsigned char *tag, tagged_field * field,
76 afs_uint32 value, tag_parse_info * pi, void *g_refcon,
79 dump_parser *p = (dump_parser *) g_refcon;
84 memset(&hdr, 0, sizeof(hdr));
85 if ((r = xftell(X, &where)))
87 sub64_32(hdr.offset, where, 1);
88 if (p->print_flags & DSPRINT_VOLHDR)
89 printf("%s [%s = 0x%s]\n", field->label,
90 decimate_int64(&hdr.offset, 0), hexify_int64(&hdr.offset, 0));
92 r = ParseTaggedData(X, volhdr_fields, tag, pi, g_refcon, (void *)&hdr);
94 if (!r && p->cb_volhdr) {
95 if ((r = xftell(X, &where)))
97 r = (p->cb_volhdr) (&hdr, X, p->refcon);
98 if (p->flags & DSFLAG_SEEK) {
100 r = xfseek(X, &where);
105 if (hdr.field_mask & F_VOLHDR_VOLUNIQ)
106 p->vol_uniquifier = hdr.voluniq;
107 if (hdr.field_mask & F_VOLHDR_VOLNAME)
109 if (hdr.field_mask & F_VOLHDR_OFFLINE_MSG)
110 free(hdr.offline_msg);
111 if (hdr.field_mask & F_VOLHDR_MOTD)
117 /* Store data in a volume header */
119 store_volhdr(XFILE * X, unsigned char *tag, tagged_field * field,
120 afs_uint32 value, tag_parse_info * pi, void *g_refcon,
123 dump_parser *p = (dump_parser *) g_refcon;
124 afs_vol_header *hdr = (afs_vol_header *) l_refcon;
128 switch (field->tag) {
130 hdr->field_mask |= F_VOLHDR_VOLID;
135 hdr->field_mask |= F_VOLHDR_VOLVERS;
136 hdr->volvers = value;
141 hdr->field_mask |= F_VOLHDR_VOLNAME;
148 hdr->field_mask |= F_VOLHDR_INSERV;
149 hdr->flag_inservice = value;
153 hdr->field_mask |= F_VOLHDR_BLESSED;
154 hdr->flag_blessed = value;
158 hdr->field_mask |= F_VOLHDR_VOLUNIQ;
159 hdr->voluniq = value;
163 hdr->field_mask |= F_VOLHDR_VOLTYPE;
164 hdr->voltype = value;
168 hdr->field_mask |= F_VOLHDR_PARENT;
169 hdr->parent_volid = value;
173 hdr->field_mask |= F_VOLHDR_CLONE;
174 hdr->clone_volid = value;
178 hdr->field_mask |= F_VOLHDR_MAXQ;
179 hdr->maxquota = value;
183 hdr->field_mask |= F_VOLHDR_MINQ;
184 hdr->minquota = value;
188 hdr->field_mask |= F_VOLHDR_DISKUSED;
189 hdr->diskused = value;
193 hdr->field_mask |= F_VOLHDR_NFILES;
198 hdr->field_mask |= F_VOLHDR_ACCOUNT;
199 hdr->account_no = value;
203 hdr->field_mask |= F_VOLHDR_OWNER;
208 hdr->field_mask |= F_VOLHDR_CREATE_DATE;
209 hdr->create_date = value;
213 hdr->field_mask |= F_VOLHDR_ACCESS_DATE;
214 hdr->access_date = value;
218 hdr->field_mask |= F_VOLHDR_UPDATE_DATE;
219 hdr->update_date = value;
223 hdr->field_mask |= F_VOLHDR_EXPIRE_DATE;
224 hdr->expire_date = value;
228 hdr->field_mask |= F_VOLHDR_BACKUP_DATE;
229 hdr->backup_date = value;
234 hdr->field_mask |= F_VOLHDR_OFFLINE_MSG;
235 hdr->offline_msg = tag;
242 hdr->field_mask |= F_VOLHDR_MOTD;
249 hdr->field_mask |= F_VOLHDR_DAYUSE_DATE;
250 hdr->dayuse_date = value;
254 hdr->field_mask |= F_VOLHDR_DAYUSE;
259 if (p->print_flags & DSPRINT_VOLHDR)
260 switch (field->kind) {
264 printf("%s%d\n", field->label, value);
267 printf("%s0x%02x\n", field->label, value);
270 printf("%s0x%04x\n", field->label, value);
273 printf("%s0x%08x\n", field->label, value);
276 printf("%s%c\n", field->label, value);
279 printf("%s%s\n", field->label, tag);
282 printf("%s%s\n", field->label, value ? "true" : "false");
286 printf("%s%s", field->label, ctime(&when));
293 /* Parse and store the week use data from a volume header */
295 parse_weekuse(XFILE * X, unsigned char *tag, tagged_field * field,
296 afs_uint32 value, tag_parse_info * pi, void *g_refcon,
299 dump_parser *p = (dump_parser *) g_refcon;
300 afs_vol_header *hdr = (afs_vol_header *) l_refcon;
305 if ((r = ReadInt16(X, &count)))
309 (p->cb_error) (DSERR_FMT, 1, p->err_refcon,
310 "Incorrect array count (%d) in weekuse data",
314 for (i = 0; i < count; i++)
315 if ((r = ReadInt32(X, hdr->weekuse + i)))
317 hdr->field_mask |= F_VOLHDR_WEEKUSE;
318 if (p->print_flags & DSPRINT_VOLHDR) {
319 printf("%s%10d %10d %10d %10d\n", field->label, hdr->weekuse[0],
320 hdr->weekuse[1], hdr->weekuse[2], hdr->weekuse[3]);
321 printf("%s%10d %10d %10d\n", field->label, hdr->weekuse[4],
322 hdr->weekuse[5], hdr->weekuse[6]);
324 return ReadByte(X, tag);