9 static char *input_path
= 0;
10 static int quiet
= 0, showpaths
= 0, searchcount
= 1;
11 static int error_count
= 0, bad_count
= 0;
12 static path_hashinfo phi
;
13 static dump_parser dp
;
15 /* Print a usage message and exit */
17 usage(int status
, char *msg
)
20 fprintf(stderr
, "%s: %s\n", argv0
, msg
);
21 fprintf(stderr
, "Usage: %s [options] [file]\n", argv0
);
22 fprintf(stderr
, " -h Print this help message\n");
23 fprintf(stderr
, " -p Print paths of bad vnodes\n");
24 fprintf(stderr
, " -q Quiet mode (don't print errors)\n");
29 /* Parse the command-line options */
31 parse_options(int argc
, char **argv
)
35 if (argv0
= strrchr(argv
[0], '/'))
40 /* Parse the options */
41 while ((c
= getopt(argc
, argv
, "n:hpq")) != EOF
) {
44 searchcount
= atoi(optarg
);
55 usage(1, "Invalid option!");
59 if (argc
- optind
> 1)
60 usage(1, "Too many arguments!");
61 input_path
= (argc
== optind
) ? "-" : argv
[optind
];
65 /* A callback to count and print errors */
67 my_error_cb(afs_uint32 code
, int fatal
, void *ref
, char *msg
, ...)
74 afs_com_err_va(argv0
, code
, msg
, alist
);
80 /* A callback to process file vnodes */
82 my_file_cb(afs_vnode
* v
, XFILE
* X
, void *refcon
)
84 static char buf
[1024];
85 afs_uint32 size
, nulls
, cnulls
, maxcnulls
, n
, r
;
89 nulls
= cnulls
= maxcnulls
= 0;
91 if ((r
= xfseek(X
, &v
->d_offset
)))
94 n
= (size
> 1024) ? 1024 : size
;
95 if (r
= xfread(X
, buf
, n
))
97 for (i
= 0; i
< n
; i
++) {
99 if (cnulls
> maxcnulls
)
109 if (maxcnulls
>= searchcount
) {
112 Path_Build(X
, &phi
, v
->vnode
, &name
, 0);
114 printf("*** BAD %d (%s) - %d nulls, %d consecutive\n", v
->vnode
,
115 name
, nulls
, maxcnulls
);
118 printf("*** BAD %d - %d nulls, %d consecutive\n", v
->vnode
, nulls
,
127 main(int argc
, char **argv
)
132 parse_options(argc
, argv
);
133 initialize_acfg_error_table();
134 initialize_AVds_error_table();
135 initialize_rxk_error_table();
136 initialize_u_error_table();
137 initialize_vl_error_table();
138 initialize_vols_error_table();
139 initialize_xFil_error_table();
140 r
= xfopen(&input_file
, O_RDONLY
, input_path
);
142 afs_com_err(argv0
, r
, "opening %s", input_path
);
146 memset(&dp
, 0, sizeof(dp
));
147 dp
.cb_error
= my_error_cb
;
148 if (input_file
.is_seekable
)
149 dp
.flags
|= DSFLAG_SEEK
;
153 memset(&phi
, 0, sizeof(phi
));
156 if ((r
= xftell(&input_file
, &where
))
157 || (r
= Path_PreScan(&input_file
, &phi
, 0))
158 || (r
= xfseek(&input_file
, &where
))) {
159 afs_com_err(argv0
, r
, "- path initialization failed");
160 xfclose(&input_file
);
165 dp
.cb_vnode_file
= my_file_cb
;
166 r
= ParseDumpFile(&input_file
, &dp
);
167 xfclose(&input_file
);
170 printf("*** %d errors\n", error_count
);
172 printf("*** %d bad files\n", bad_count
);
174 printf("*** FAILED: %s\n", afs_error_message(r
));