-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathafsdump_dirlist.c
156 lines (129 loc) · 4.05 KB
/
afsdump_dirlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* CMUCS AFStools
* dumpscan - routines for scanning and manipulating AFS volume dumps
*
* Copyright (c) 1998, 2001, 2003 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or [email protected]
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/* afsdump_dirlist.c - List an AFS directory file */
#include <sys/fcntl.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <afs/stds.h>
#include <afs/com_err.h>
#include <rx/rxkad.h>
#include <ubik.h>
#include <afs/cellconfig.h>
#include <afs/afsint.h>
#include <afs/volser.h>
#include <afs/vlserver.h>
#include "dumpscan.h"
extern int optind;
extern char *optarg;
char *argv0;
static char *input_path;
static int quiet, verbose, error_count;
static dump_parser dp;
/* Print a usage message and exit */
static void usage(int status, char *msg)
{
if (msg) fprintf(stderr, "%s: %s\n", argv0, msg);
fprintf(stderr, "Usage: %s [options] [file]\n", argv0);
fprintf(stderr, " -h Print this help message\n");
fprintf(stderr, " -q Quiet mode (don't print errors)\n");
fprintf(stderr, " -v Verbose mode\n");
exit(status);
}
/* Parse the command-line options */
static void parse_options(int argc, char **argv)
{
int c;
/* Set the program name */
if (argv0 = strrchr(argv[0], '/')) argv0++;
else argv0 = argv[0];
/* Initialize options */
input_path = 0;
quiet = verbose = 0;
/* Initialize other stuff */
error_count = 0;
/* Parse the options */
while ((c = getopt(argc, argv, "hqv")) != EOF) {
switch (c) {
case 'q': quiet = 1; continue;
case 'v': verbose = 1; continue;
case 'h': usage(0, 0); exit(0);
default: usage(1, "Invalid option!");
}
}
if (quiet && verbose) usage(1, "Can't specify both -q and -v");
/* Parse non-option arguments */
if (argc - optind > 1) usage(1, "Too many arguments!");
input_path = (argc == optind) ? "-" : argv[optind];
}
/* A callback to count and print errors */
static afs_uint32 my_error_cb(afs_uint32 code, int fatal, void *ref, char *msg, ...)
{
va_list alist;
error_count++;
if (!quiet) {
va_start(alist, msg);
afs_com_err_va(argv0, code, msg, alist);
va_end(alist);
}
return 0;
}
/* Main program */
int main(int argc, char **argv)
{
XFILE input_file;
afs_uint32 r;
int code;
parse_options(argc, argv);
initialize_acfg_error_table();
initialize_AVds_error_table();
initialize_rxk_error_table();
initialize_u_error_table();
initialize_vl_error_table();
initialize_vols_error_table();
initialize_xFil_error_table();
r = xfopen(&input_file, O_RDONLY, input_path);
if (r) {
afs_com_err(argv0, r, "opening %s", input_path);
exit(2);
}
memset(&dp, 0, sizeof(dp));
dp.cb_error = my_error_cb;
dp.print_flags = DSPRINT_DIR;
if (input_file.is_seekable) dp.flags |= DSFLAG_SEEK;
r = ParseDirectory(&input_file, &dp, 0, 1);
xfclose(&input_file);
if (verbose && error_count) fprintf(stderr, "*** %d errors\n", error_count);
if (r && !quiet) fprintf(stderr, "*** FAILED: %s\n", afs_error_message(r));
if (r) {
code = 3; /* failed */
} else if (error_count) {
code = 4; /* errors */
}
return code;
}