~ubuntu-branches/ubuntu/warty/openafs/warty

« back to all changes in this revision

Viewing changes to src/tests/dumpscan.h

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-01-10 16:37:33 UTC
  • Revision ID: james.westby@ubuntu.com-20040110163733-jvr0n1uahshlb1uu
Tags: upstream-1.2.11
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* dumpscan.h - Public interface */
 
30
 
 
31
#ifndef _DUMPSCAN_H_
 
32
#define _DUMPSCAN_H_
 
33
 
 
34
#include "intNN.h"
 
35
#include "xfiles.h"
 
36
 
 
37
#include <lock.h>
 
38
#include <afs/afsint.h>
 
39
#include <afs/nfs.h>
 
40
#include <afs/ihandle.h>
 
41
#include <afs/vnode.h>
 
42
#include <afs/cmd.h>
 
43
#include <afs/auth.h>
 
44
#include <afs/bnode.h>
 
45
#include <afs/cellconfig.h>
 
46
#include <afs/kautils.h>
 
47
#include <afs/pterror.h>
 
48
#include <afs/vlserver.h>
 
49
#include <afs/volser.h>
 
50
#include <ubik.h>
 
51
 
 
52
/* Random useful types */
 
53
typedef struct tagged_field tagged_field;
 
54
typedef struct tag_parse_info tag_parse_info;
 
55
typedef afs_uint32 (*tag_parser)(XFILE *, unsigned char *, tagged_field *,
 
56
                              afs_uint32, tag_parse_info *, void *, void *);
 
57
 
 
58
/* Error codes used within dumpscan.
 
59
 * Any of the routines declared below, or callbacks used by them,
 
60
 * may signal a system error by returning the error number, or
 
61
 * some other error by returning a com_err code.  Note that
 
62
 * ParseTaggedData does _not_ return DSERR_TAG; instead, it returns
 
63
 * 0, assuming the tag will be handled at a higher level.
 
64
 *
 
65
 * In addition, these errors may be reported to the caller of
 
66
 * ParseDumpFile using the error callback.  Such reports will be
 
67
 * issued whether or not error recovery is possible or attempted.
 
68
 *
 
69
 * NB: These errors are now in dumpscan_errs.h
 
70
 */
 
71
 
 
72
 
 
73
/* Backup system dump header */
 
74
/* Right now, this looks a lot like an old stage header.  Eventually, it
 
75
 * should contain enough fields to fully represent headers from old or
 
76
 * new stage, Transarc, or other backup systems, and the appropriate read
 
77
 * functions should extract as much data as possible from the actual file
 
78
 * to fill this in. */
 
79
typedef struct {
 
80
  afs_uint32 version;
 
81
  afs_uint32 from_date;
 
82
  afs_uint32 to_date;
 
83
  afs_uint32 dump_date;
 
84
  afs_uint32 filenum;
 
85
  unsigned char *server;
 
86
  unsigned char *part;
 
87
  unsigned char *volname;
 
88
  afs_uint32 volid;
 
89
  afs_uint32 dumplen;
 
90
  afs_uint32 level;
 
91
  afs_uint32 magic;
 
92
  afs_uint32 cksum;
 
93
  afs_uint32 flags;
 
94
} backup_system_header;
 
95
 
 
96
 
 
97
/** AFS dump header **/
 
98
#define F_DUMPHDR_VOLID       0x00000001
 
99
#define F_DUMPHDR_VOLNAME     0x00000002
 
100
#define F_DUMPHDR_FROM        0x00000004
 
101
#define F_DUMPHDR_TO          0x00000008
 
102
typedef struct {
 
103
  u_int64 offset;           /* Where in the file is it? */
 
104
  afs_uint32 field_mask;       /* What fields are present? */
 
105
  afs_uint32 magic;            /* Magic number */
 
106
  afs_uint32 version;          /* Dump format version */
 
107
  afs_uint32 volid;            /* VolID of volume in dump */
 
108
  unsigned char *volname;   /* Name of volume in dump */
 
109
  afs_uint32 from_date;        /* Reference date */
 
110
  afs_uint32 to_date;          /* Date of dump */
 
111
} afs_dump_header;
 
112
 
 
113
 
 
114
/** AFS volume header **/
 
115
#define F_VOLHDR_VOLID        0x00000001
 
116
#define F_VOLHDR_VOLVERS      0x00000002
 
117
#define F_VOLHDR_VOLNAME      0x00000004
 
118
#define F_VOLHDR_INSERV       0x00000008
 
119
#define F_VOLHDR_BLESSED      0x00000010
 
120
#define F_VOLHDR_VOLUNIQ      0x00000020
 
121
#define F_VOLHDR_VOLTYPE      0x00000040
 
122
#define F_VOLHDR_PARENT       0x00000080
 
123
#define F_VOLHDR_CLONE        0x00000100
 
124
#define F_VOLHDR_MAXQ         0x00000200
 
125
#define F_VOLHDR_MINQ         0x00000400
 
126
#define F_VOLHDR_DISKUSED     0x00000800
 
127
#define F_VOLHDR_NFILES       0x00001000
 
128
#define F_VOLHDR_ACCOUNT      0x00002000
 
129
#define F_VOLHDR_OWNER        0x00004000
 
130
#define F_VOLHDR_CREATE_DATE  0x00008000
 
131
#define F_VOLHDR_ACCESS_DATE  0x00010000
 
132
#define F_VOLHDR_UPDATE_DATE  0x00020000
 
133
#define F_VOLHDR_EXPIRE_DATE  0x00040000
 
134
#define F_VOLHDR_BACKUP_DATE  0x00080000
 
135
#define F_VOLHDR_OFFLINE_MSG  0x00100000
 
136
#define F_VOLHDR_MOTD         0x00200000
 
137
#define F_VOLHDR_WEEKUSE      0x00400000
 
138
#define F_VOLHDR_DAYUSE       0x00800000
 
139
#define F_VOLHDR_DAYUSE_DATE  0x01000000
 
140
typedef struct {
 
141
  u_int64 offset;           /* Where in the file is it? */
 
142
  afs_uint32 field_mask;       /* What fields are present? */
 
143
  afs_uint32 volid;            /* Volume ID */
 
144
  afs_uint32 volvers;          /* ?? */
 
145
  unsigned char *volname;   /* Volume Name */
 
146
  int     flag_inservice;   /* Inservice flag (0 or not) */
 
147
  int     flag_blessed;     /* Blessed to come online (0 or not) */
 
148
  afs_uint32 voluniq;          /* Volume uniquifier */
 
149
  int     voltype;          /* Volume type */
 
150
  afs_uint32 parent_volid;     /* Parent volume ID */
 
151
  afs_uint32 clone_volid;      /* Clone volume ID */
 
152
  afs_uint32 maxquota;         /* Max quota */
 
153
  afs_uint32 minquota;         /* Min quota (obsolete) */
 
154
  afs_uint32 diskused;         /* Disk blocks used */
 
155
  afs_uint32 nfiles;           /* Number of files in volume */
 
156
  afs_uint32 account_no;       /* Account number (unused) */
 
157
  afs_uint32 owner;            /* Volume owner */
 
158
  afs_uint32 create_date;      /* Creation date of this copy */
 
159
  afs_uint32 access_date;      /* Last access */
 
160
  afs_uint32 update_date;      /* Last modification */
 
161
  afs_uint32 expire_date;      /* Expiration (unused) */
 
162
  afs_uint32 backup_date;      /* Last backup clone */
 
163
  unsigned char *offline_msg; /* Offline message */
 
164
  unsigned char *motd_msg;    /* Volume MOTD */
 
165
  afs_uint32 weekuse[7];       /* Weekuse data */
 
166
  afs_uint32 dayuse;           /* # accesses in last day */
 
167
  afs_uint32 dayuse_date;      /* Date for which dayuse is valid */
 
168
} afs_vol_header;
 
169
 
 
170
 
 
171
/** AFS vnode **/
 
172
#define F_VNODE_TYPE          0x00000001
 
173
#define F_VNODE_NLINKS        0x00000002
 
174
#define F_VNODE_PARENT        0x00000004
 
175
#define F_VNODE_DVERS         0x00000008
 
176
#define F_VNODE_AUTHOR        0x00000010
 
177
#define F_VNODE_OWNER         0x00000020
 
178
#define F_VNODE_GROUP         0x00000040
 
179
#define F_VNODE_MODE          0x00000080
 
180
#define F_VNODE_CDATE         0x00000100
 
181
#define F_VNODE_SDATE         0x00000200
 
182
#define F_VNODE_SIZE          0x00000800
 
183
#define F_VNODE_DATA          0x00001000
 
184
#define F_VNODE_ACL           0x00000400
 
185
typedef struct {
 
186
  u_int64 offset;           /* Where in the file is it? */
 
187
  afs_uint32 field_mask;       /* What fields are present? */
 
188
  afs_uint32 vnode;            /* Vnode number */
 
189
  afs_uint32 vuniq;            /* Uniquifier */
 
190
  int     type;             /* Vnode type */
 
191
  afs_uint16 nlinks;           /* Number of links (should be in 1 dir!) */
 
192
  afs_uint32 parent;           /* Parent vnode */
 
193
  afs_uint32 datavers;         /* Data version */
 
194
  afs_uint32 author;           /* Last writer */
 
195
  afs_uint32 owner;            /* Owner UID */
 
196
  afs_uint32 group;            /* Owning group */
 
197
  afs_uint16 mode;             /* UNIX mode bits */
 
198
  afs_uint32 client_date;      /* Last modified date from client */
 
199
  afs_uint32 server_date;      /* Last modified date on server */
 
200
  afs_uint32 size;             /* Size of data */
 
201
  u_int64 d_offset;         /* Where in the file is the data? */
 
202
  unsigned char acl[SIZEOF_LARGEDISKVNODE - SIZEOF_SMALLDISKVNODE];
 
203
} afs_vnode;
 
204
 
 
205
 
 
206
/** AFS directory entry **/
 
207
typedef struct {
 
208
  int  slot;                /* Directory slot # (info only) */
 
209
  char *name;               /* Name of entry */
 
210
  afs_uint32 vnode;            /* Vnode number */
 
211
  afs_uint32 uniq;             /* Uniquifier */
 
212
} afs_dir_entry;
 
213
 
 
214
 
 
215
/** Tagged field definitions **/
 
216
#define DKIND_NOOP      0x00  /* No data */
 
217
#define DKIND_BYTE      0x10  /* 1 byte  - decimal */
 
218
#define DKIND_HEX8      0x11  /* 1 byte  - hex */
 
219
#define DKIND_CHAR      0x12  /* 1 byte  - character */
 
220
#define DKIND_FLAG      0x13  /* 1 byte  - true/false */
 
221
#define DKIND_INT16     0x20  /* 2 bytes - decimal */
 
222
#define DKIND_HEX16     0x21  /* 2 bytes - hex */
 
223
#define DKIND_INT32     0x30  /* 4 bytes - decimal */
 
224
#define DKIND_HEX32     0x31  /* 4 bytes - hex */
 
225
#define DKIND_TIME      0x32  /* 4 bytes - time */
 
226
#define DKIND_STRING    0x40  /* ASCIIZ string */
 
227
#define DKIND_SPECIAL   0x50  /* Custom parser */
 
228
#define DKIND_MASK     (~0x0f)
 
229
struct tag_parse_info {
 
230
  void *err_refcon;
 
231
  afs_uint32 (*cb_error)(afs_uint32, int, void *, char *, ...);
 
232
  afs_uint32 flags;
 
233
#define TPFLAG_SKIP   0x0001
 
234
#define TPFLAG_RSKIP  0x0002
 
235
  int shift_offset;
 
236
  u_int64 shift_start;
 
237
};
 
238
struct tagged_field {
 
239
  char tag;        /* Tag character */
 
240
  int  kind;       /* Kind of object */
 
241
  char *label;     /* Label to use (for debugging) */
 
242
  tag_parser func; /* Parser function (for DKIND_SPECIAL) */
 
243
  void *refptr;    /* Reference pointer (for parser's use) */
 
244
  int  refarg;     /* Reference argument (for parser's use) */
 
245
};
 
246
 
 
247
 
 
248
/** Control structure for parsing volume dumps **/
 
249
typedef struct {
 
250
  /* Callback functions:
 
251
   * Whenever a "complex" object is parsed, we call a callback function.
 
252
   * The callback gets a pointer to the complex object, the file pointer
 
253
   * for the dump we're parsing, and the value of refcon in this structure.
 
254
   * Callbacks should return 0 if all is well, non-0 to abort the dump.
 
255
   * By convention, positive numbers should be errno values, and negative
 
256
   * numbers can be used for other things.  It is OK to _try_ to seek anywhere
 
257
   * in the file.  Beware, though, that the input is not always seekable.
 
258
   * Also, note that the structures passed to these callbacks are going to
 
259
   * go away after the callback returns.  There is no way to prevent this;
 
260
   * make a copy if you want one.
 
261
   */
 
262
  void *refcon;
 
263
  afs_uint32 (*cb_bckhdr)(backup_system_header *, XFILE *, void *); /* Backup   */
 
264
  afs_uint32 (*cb_dumphdr)(afs_dump_header *, XFILE *, void *); /* Dump hdr     */
 
265
  afs_uint32 (*cb_volhdr)(afs_vol_header *, XFILE *, void *);   /* Volume hdr   */
 
266
  afs_uint32 (*cb_vnode_dir)(afs_vnode *, XFILE *, void *);     /* Directory    */
 
267
  afs_uint32 (*cb_vnode_file)(afs_vnode *, XFILE *, void *);    /* File         */
 
268
  afs_uint32 (*cb_vnode_link)(afs_vnode *, XFILE *, void *);    /* Symlink      */
 
269
  afs_uint32 (*cb_vnode_empty)(afs_vnode *, XFILE *, void *);   /* vnode+uniq   */
 
270
  afs_uint32 (*cb_vnode_wierd)(afs_vnode *, XFILE *, void *);   /* Unknown type */
 
271
 
 
272
  /* This function is called when there is an error in the dump. */
 
273
  /* (cb_error)(errno, fatal, refcon, msg_fmt, msg_args...) */
 
274
  void *err_refcon; /* If set, use instead of refcon for dir entries */
 
275
  afs_uint32 (*cb_error)(afs_uint32, int, void *, char *, ...);
 
276
 
 
277
  /* This function is called for each directory entry, if set */
 
278
  afs_uint32 (*cb_dirent)(afs_vnode *, afs_dir_entry *, XFILE *, void *);
 
279
 
 
280
  int flags;            /* Flags and options */
 
281
#define DSFLAG_SEEK     0x0001  /* Input file is seekable */
 
282
 
 
283
  int print_flags;      /* Flags to control what is printed */
 
284
#define DSPRINT_BCKHDR  0x0001  /* Print backup system header */
 
285
#define DSPRINT_DUMPHDR 0x0002  /* Print AFS dump header */
 
286
#define DSPRINT_VOLHDR  0x0004  /* Print AFS volume header */
 
287
#define DSPRINT_ITEM    0x0010  /* Print top-level tags */
 
288
#define DSPRINT_VNODE   0x0020  /* Print vnode attributes */
 
289
#define DSPRINT_ACL     0x0040  /* Print directory ACL's */
 
290
#define DSPRINT_DIR     0x0080  /* Print directory contents */
 
291
#define DSPRINT_DEBUG   0x0100  /* Print debugging info */
 
292
#define DSPRINT_PATH    0x0200  /* Print vnode paths */
 
293
 
 
294
  int repair_flags;     /* Flags to control what is repaired.
 
295
                         * Most of these _require_ DSFLAG_SEEK */
 
296
#define DSFIX_SKIP      0x0001  /* Try to skip null tags */
 
297
#define DSFIX_RSKIP     0x0002  /* Seek back to fing skipped tags */
 
298
#define DSFIX_VDSYNC    0x0004  /* Resync location after vnode data */
 
299
#define DSFIX_VFSYNC    0x0008  /* Try to resync after bad vnode */
 
300
 
 
301
  /** Things below this point for internal use only **/
 
302
  afs_uint32 vol_uniquifier;
 
303
} dump_parser;
 
304
 
 
305
 
 
306
/** Hash table and control info for pathname manipulation **/
 
307
typedef struct vhash_ent {
 
308
  struct vhash_ent *next;    /* Pointer to next entry */
 
309
  afs_uint32 vnode;             /* VNode number */
 
310
  afs_uint32 parent;            /* Parent VNode number */
 
311
  u_int64 v_offset;          /* Offset to start of vnode */
 
312
  u_int64 d_offset;          /* Offset to data (0 if none) */
 
313
  afs_uint32 d_size;            /* Size of data */
 
314
} vhash_ent;
 
315
typedef struct {
 
316
  afs_uint32 n_vnodes;          /* Number of vnodes in volume */
 
317
  afs_uint32 n_dirs;            /* Number of file vnodes */
 
318
  afs_uint32 n_files;           /* Number of directory vnodes */
 
319
  int hash_size;             /* Hash table size (bits) */
 
320
  vhash_ent **hash_table;    /* Hash table */
 
321
  dump_parser *p;            /* Dump parser to use */
 
322
} path_hashinfo;
 
323
 
 
324
 
 
325
/** Function prototypes **/
 
326
/** Only the functions declared below are public interfaces **/
 
327
/** Maybe someday, I'll write man pages for these **/
 
328
 
 
329
/* primitive.c - I/O primitives */
 
330
extern afs_uint32 ReadByte(XFILE *, unsigned char *);
 
331
extern afs_uint32 ReadInt16(XFILE *, afs_uint16 *);
 
332
extern afs_uint32 ReadInt32(XFILE *, afs_uint32 *);
 
333
extern afs_uint32 ReadString(XFILE *, unsigned char **);
 
334
extern afs_uint32 WriteByte(XFILE *, unsigned char);
 
335
extern afs_uint32 WriteInt16(XFILE *, afs_uint16);
 
336
extern afs_uint32 WriteInt32(XFILE *, afs_uint32);
 
337
extern afs_uint32 WriteString(XFILE *, unsigned char *);
 
338
extern afs_uint32 WriteTagByte(XFILE *, unsigned char, unsigned char);
 
339
extern afs_uint32 WriteTagInt16(XFILE *, unsigned char, afs_uint16);
 
340
extern afs_uint32 WriteTagInt32(XFILE *, unsigned char, afs_uint32);
 
341
extern afs_uint32 WriteTagInt32Pair(XFILE *, unsigned char, afs_uint32, afs_uint32);
 
342
 
 
343
/* parsetag.c - Parse tagged data */
 
344
extern afs_uint32 ParseTaggedData(XFILE *, tagged_field *, unsigned char *,
 
345
                           tag_parse_info *, void *, void *);
 
346
 
 
347
/* stagehdr.c - Parse and dump Stage dump headers */
 
348
extern afs_uint32 ParseStageHdr(XFILE *, unsigned char *, backup_system_header *);
 
349
extern afs_uint32 DumpStagehdr(XFILE *, backup_system_header *);
 
350
 
 
351
/* backuphdr.c - Parse and print backup system headers */
 
352
extern void PrintBackupHdr(backup_system_header *);
 
353
 
 
354
/* parsedump.c - Parse all or part of a volume dump */
 
355
extern afs_uint32 ParseDumpFile(XFILE *, dump_parser *);
 
356
extern afs_uint32 ParseDumpHeader(XFILE *, dump_parser *);
 
357
extern afs_uint32 ParseVolumeHeader(XFILE *, dump_parser *);
 
358
extern afs_uint32 ParseVNode(XFILE *, dump_parser *);
 
359
 
 
360
 
 
361
/* directory.c - Directory parsing and lookup */
 
362
extern afs_uint32 ParseDirectory(XFILE *, dump_parser *, afs_uint32, int);
 
363
extern afs_uint32 DirectoryLookup(XFILE *, dump_parser *, afs_uint32,
 
364
                           char **, afs_uint32 *, afs_uint32 *);
 
365
 
 
366
/* dump.c - Dump parts of a volume dump */
 
367
extern afs_uint32 DumpDumpHeader(XFILE *, afs_dump_header *);
 
368
extern afs_uint32 DumpVolumeHeader(XFILE *, afs_vol_header *);
 
369
extern afs_uint32 DumpVNode(XFILE *, afs_vnode *);
 
370
extern afs_uint32 DumpVnodeData(XFILE *, char *, afs_uint32);
 
371
extern afs_uint32 CopyVnodeData(XFILE *, XFILE *, afs_uint32);
 
372
 
 
373
/* pathname.c - Follow and construct pathnames */
 
374
extern afs_uint32 Path_PreScan(XFILE *, path_hashinfo *, int);
 
375
extern void Path_FreeHashTable(path_hashinfo *);
 
376
extern afs_uint32 Path_Follow(XFILE *, path_hashinfo *, char *, vhash_ent *);
 
377
extern afs_uint32 Path_Build(XFILE *, path_hashinfo *, afs_uint32, char **, int);
 
378
 
 
379
#endif