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 /* afsdump_dirlist.c - List an AFS directory file */
31 #include <afsconfig.h>
33 #include <sys/fcntl.h>
39 #include <afs/com_err.h>
40 #include <afs/cellconfig.h>
41 #include <afs/vlserver.h>
42 #include <afs/volser.h>
46 #include "dumpscan_errs.h"
53 static char *input_path;
54 static int quiet, verbose, error_count;
56 static dump_parser dp;
59 /* Print a usage message and exit */
61 usage(int status, char *msg)
64 fprintf(stderr, "%s: %s\n", argv0, msg);
65 fprintf(stderr, "Usage: %s [options] [file]\n", argv0);
66 fprintf(stderr, " -h Print this help message\n");
67 fprintf(stderr, " -q Quiet mode (don't print errors)\n");
68 fprintf(stderr, " -v Verbose mode\n");
73 /* Parse the command-line options */
75 parse_options(int argc, char **argv)
79 /* Set the program name */
80 if ((argv0 = strrchr(argv[0], '/')) != NULL)
85 /* Initialize options */
89 /* Initialize other stuff */
92 /* Parse the options */
93 while ((c = getopt(argc, argv, "hqv")) != EOF) {
104 usage(1, "Invalid option!");
108 if (quiet && verbose)
109 usage(1, "Can't specify both -q and -v");
111 /* Parse non-option arguments */
112 if (argc - optind > 1)
113 usage(1, "Too many arguments!");
114 input_path = (argc == optind) ? "-" : argv[optind];
118 /* A callback to count and print errors */
120 my_error_cb(afs_uint32 code, int fatal, void *ref, char *msg, ...)
126 va_start(alist, msg);
127 afs_com_err_va(argv0, code, msg, alist);
136 main(int argc, char **argv)
141 parse_options(argc, argv);
142 initialize_acfg_error_table();
143 initialize_AVds_error_table();
144 initialize_rxk_error_table();
145 initialize_u_error_table();
146 initialize_vl_error_table();
147 initialize_vols_error_table();
148 initialize_xFil_error_table();
149 r = xfopen(&input_file, O_RDONLY, input_path);
151 afs_com_err(argv0, r, "opening %s", input_path);
155 memset(&dp, 0, sizeof(dp));
156 dp.cb_error = my_error_cb;
157 dp.print_flags = DSPRINT_DIR;
158 if (input_file.is_seekable)
159 dp.flags |= DSFLAG_SEEK;
161 r = ParseDirectory(&input_file, &dp, 0, 1);
162 xfclose(&input_file);
164 if (verbose && error_count)
165 fprintf(stderr, "*** %d errors\n", error_count);
167 fprintf(stderr, "*** FAILED: %s\n", afs_error_message(r));