1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1999,2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * fsck_pcfs -- main routines.
31*0Sstevel@tonic-gate */
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include <errno.h>
35*0Sstevel@tonic-gate #include <stdlib.h>
36*0Sstevel@tonic-gate #include <sys/types.h>
37*0Sstevel@tonic-gate #include <sys/stat.h>
38*0Sstevel@tonic-gate #include <fcntl.h>
39*0Sstevel@tonic-gate #include <strings.h>
40*0Sstevel@tonic-gate #include <libintl.h>
41*0Sstevel@tonic-gate #include <locale.h>
42*0Sstevel@tonic-gate #include <sys/fcntl.h>
43*0Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
44*0Sstevel@tonic-gate #include "pcfs_common.h"
45*0Sstevel@tonic-gate #include "fsck_pcfs.h"
46*0Sstevel@tonic-gate #include "pcfs_bpb.h"
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate int32_t BytesPerCluster;
49*0Sstevel@tonic-gate int32_t TotalClusters;
50*0Sstevel@tonic-gate int32_t LastCluster;
51*0Sstevel@tonic-gate off64_t FirstClusterOffset;
52*0Sstevel@tonic-gate off64_t PartitionOffset;
53*0Sstevel@tonic-gate bpb_t TheBIOSParameterBlock;
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate * {Output,Input}Image are the file names where we should write the
57*0Sstevel@tonic-gate * checked fs image and from which we should read the initial fs.
58*0Sstevel@tonic-gate * The image capability is designed for debugging purposes.
59*0Sstevel@tonic-gate */
60*0Sstevel@tonic-gate static char *OutputImage = NULL;
61*0Sstevel@tonic-gate static char *InputImage = NULL;
62*0Sstevel@tonic-gate static int WritableOnly = 0; /* -o w, check writable fs' only */
63*0Sstevel@tonic-gate static int Mflag = 0; /* -m, sanity check if fs is mountable */
64*0Sstevel@tonic-gate static int Preen = 0; /* -o p, preen; non-interactive */
65*0Sstevel@tonic-gate /*
66*0Sstevel@tonic-gate * By default be quick; skip verify reads.
67*0Sstevel@tonic-gate * If the user wants more exhaustive checking,
68*0Sstevel@tonic-gate * they should run with the -o v option.
69*0Sstevel@tonic-gate */
70*0Sstevel@tonic-gate static int Quick = 1;
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate int ReadOnly = 0;
73*0Sstevel@tonic-gate int IsFAT32 = 0;
74*0Sstevel@tonic-gate int Verbose = 0;
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate int AlwaysYes = 0; /* -y or -Y, assume a yes answer to all questions */
77*0Sstevel@tonic-gate int AlwaysNo = 0; /* -n or -N, assume a no answer to all questions */
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate extern ClusterContents TheRootDir;
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate /*
82*0Sstevel@tonic-gate * Function definitions
83*0Sstevel@tonic-gate */
84*0Sstevel@tonic-gate static void
passOne(int fd)85*0Sstevel@tonic-gate passOne(int fd)
86*0Sstevel@tonic-gate {
87*0Sstevel@tonic-gate if (!Quick)
88*0Sstevel@tonic-gate findBadClusters(fd);
89*0Sstevel@tonic-gate scanAndFixMetadata(fd);
90*0Sstevel@tonic-gate }
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate static void
writeBackChanges(int fd)93*0Sstevel@tonic-gate writeBackChanges(int fd)
94*0Sstevel@tonic-gate {
95*0Sstevel@tonic-gate writeFATMods(fd);
96*0Sstevel@tonic-gate if (!IsFAT32)
97*0Sstevel@tonic-gate writeRootDirMods(fd);
98*0Sstevel@tonic-gate writeClusterMods(fd);
99*0Sstevel@tonic-gate }
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate static void
tryOpen(int * fd,char * openMe,int oflag,int exitOnFailure)102*0Sstevel@tonic-gate tryOpen(int *fd, char *openMe, int oflag, int exitOnFailure)
103*0Sstevel@tonic-gate {
104*0Sstevel@tonic-gate int saveError;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate if ((*fd = open(openMe, oflag)) < 0) {
107*0Sstevel@tonic-gate if (exitOnFailure == RETURN_ON_OPEN_FAILURE)
108*0Sstevel@tonic-gate return;
109*0Sstevel@tonic-gate saveError = errno;
110*0Sstevel@tonic-gate mountSanityCheckFails();
111*0Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", openMe);
112*0Sstevel@tonic-gate (void) fprintf(stderr, strerror(saveError));
113*0Sstevel@tonic-gate (void) fprintf(stderr, "\n");
114*0Sstevel@tonic-gate exit(1);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate static void
doOpen(int * inFD,int * outFD,char * name,char * outName)119*0Sstevel@tonic-gate doOpen(int *inFD, int *outFD, char *name, char *outName)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate if (ReadOnly) {
122*0Sstevel@tonic-gate tryOpen(inFD, name, O_RDONLY, EXIT_ON_OPEN_FAILURE);
123*0Sstevel@tonic-gate *outFD = -1;
124*0Sstevel@tonic-gate } else {
125*0Sstevel@tonic-gate tryOpen(inFD, name, O_RDWR, RETURN_ON_OPEN_FAILURE);
126*0Sstevel@tonic-gate if (*inFD < 0) {
127*0Sstevel@tonic-gate if (errno != EACCES || WritableOnly) {
128*0Sstevel@tonic-gate int saveError = errno;
129*0Sstevel@tonic-gate mountSanityCheckFails();
130*0Sstevel@tonic-gate (void) fprintf(stderr,
131*0Sstevel@tonic-gate gettext("%s: "), name);
132*0Sstevel@tonic-gate (void) fprintf(stderr, strerror(saveError));
133*0Sstevel@tonic-gate (void) fprintf(stderr, "\n");
134*0Sstevel@tonic-gate exit(2);
135*0Sstevel@tonic-gate } else {
136*0Sstevel@tonic-gate tryOpen(inFD, name, O_RDONLY,
137*0Sstevel@tonic-gate EXIT_ON_OPEN_FAILURE);
138*0Sstevel@tonic-gate AlwaysYes = 0;
139*0Sstevel@tonic-gate AlwaysNo = 1;
140*0Sstevel@tonic-gate ReadOnly = 1;
141*0Sstevel@tonic-gate *outFD = -1;
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate } else {
144*0Sstevel@tonic-gate *outFD = *inFD;
145*0Sstevel@tonic-gate }
146*0Sstevel@tonic-gate }
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gate if (outName != NULL) {
149*0Sstevel@tonic-gate tryOpen(outFD, outName, (O_RDWR | O_CREAT),
150*0Sstevel@tonic-gate EXIT_ON_OPEN_FAILURE);
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate (void) printf("** %s %s\n", name,
154*0Sstevel@tonic-gate ReadOnly ? gettext("(NO WRITE)") : "");
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate static void
openFS(char * special,int * inFD,int * outFD)158*0Sstevel@tonic-gate openFS(char *special, int *inFD, int *outFD)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate struct stat dinfo;
161*0Sstevel@tonic-gate char *actualDisk = NULL;
162*0Sstevel@tonic-gate char *suffix = NULL;
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gate if (Verbose)
165*0Sstevel@tonic-gate (void) fprintf(stderr, gettext("Opening file system.\n"));
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gate if (InputImage == NULL) {
168*0Sstevel@tonic-gate actualDisk = stat_actual_disk(special, &dinfo, &suffix);
169*0Sstevel@tonic-gate /*
170*0Sstevel@tonic-gate * Destination exists, now find more about it.
171*0Sstevel@tonic-gate */
172*0Sstevel@tonic-gate if (!(S_ISCHR(dinfo.st_mode))) {
173*0Sstevel@tonic-gate mountSanityCheckFails();
174*0Sstevel@tonic-gate (void) fprintf(stderr,
175*0Sstevel@tonic-gate gettext("\n%s: device name must be a "
176*0Sstevel@tonic-gate "character special device.\n"), actualDisk);
177*0Sstevel@tonic-gate exit(2);
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate } else {
180*0Sstevel@tonic-gate actualDisk = InputImage;
181*0Sstevel@tonic-gate }
182*0Sstevel@tonic-gate doOpen(inFD, outFD, actualDisk, OutputImage);
183*0Sstevel@tonic-gate if (suffix) {
184*0Sstevel@tonic-gate if ((PartitionOffset =
185*0Sstevel@tonic-gate findPartitionOffset(*inFD, suffix)) < 0) {
186*0Sstevel@tonic-gate mountSanityCheckFails();
187*0Sstevel@tonic-gate (void) fprintf(stderr,
188*0Sstevel@tonic-gate gettext("Unable to find logical drive %s\n"),
189*0Sstevel@tonic-gate suffix);
190*0Sstevel@tonic-gate exit(2);
191*0Sstevel@tonic-gate } else if (Verbose) {
192*0Sstevel@tonic-gate (void) fprintf(stderr,
193*0Sstevel@tonic-gate gettext("Partition starts at offset %lld\n"),
194*0Sstevel@tonic-gate PartitionOffset);
195*0Sstevel@tonic-gate }
196*0Sstevel@tonic-gate } else {
197*0Sstevel@tonic-gate PartitionOffset = 0;
198*0Sstevel@tonic-gate }
199*0Sstevel@tonic-gate }
200*0Sstevel@tonic-gate
201*0Sstevel@tonic-gate void
usage()202*0Sstevel@tonic-gate usage()
203*0Sstevel@tonic-gate {
204*0Sstevel@tonic-gate (void) fprintf(stderr,
205*0Sstevel@tonic-gate gettext("pcfs Usage: fsck -F pcfs [-o v|p|w] special-file\n"));
206*0Sstevel@tonic-gate exit(1);
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate static
210*0Sstevel@tonic-gate char *LegalOpts[] = {
211*0Sstevel@tonic-gate #define VFLAG 0
212*0Sstevel@tonic-gate "v",
213*0Sstevel@tonic-gate #define PFLAG 1
214*0Sstevel@tonic-gate "p",
215*0Sstevel@tonic-gate #define WFLAG 2
216*0Sstevel@tonic-gate "w",
217*0Sstevel@tonic-gate #define DFLAG 3
218*0Sstevel@tonic-gate "d",
219*0Sstevel@tonic-gate #define IFLAG 4
220*0Sstevel@tonic-gate "i",
221*0Sstevel@tonic-gate #define OFLAG 5
222*0Sstevel@tonic-gate "o",
223*0Sstevel@tonic-gate NULL
224*0Sstevel@tonic-gate };
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate static void
parseSubOptions(char * optsstr)227*0Sstevel@tonic-gate parseSubOptions(char *optsstr)
228*0Sstevel@tonic-gate {
229*0Sstevel@tonic-gate char *value;
230*0Sstevel@tonic-gate int c;
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate while (*optsstr != '\0') {
233*0Sstevel@tonic-gate switch (c = getsubopt(&optsstr, LegalOpts, &value)) {
234*0Sstevel@tonic-gate case VFLAG:
235*0Sstevel@tonic-gate Quick = 0;
236*0Sstevel@tonic-gate break;
237*0Sstevel@tonic-gate case PFLAG:
238*0Sstevel@tonic-gate Preen++;
239*0Sstevel@tonic-gate break;
240*0Sstevel@tonic-gate case WFLAG:
241*0Sstevel@tonic-gate WritableOnly++;
242*0Sstevel@tonic-gate break;
243*0Sstevel@tonic-gate case DFLAG:
244*0Sstevel@tonic-gate Verbose++;
245*0Sstevel@tonic-gate break;
246*0Sstevel@tonic-gate case IFLAG:
247*0Sstevel@tonic-gate if (value == NULL) {
248*0Sstevel@tonic-gate missing_arg(LegalOpts[c]);
249*0Sstevel@tonic-gate } else {
250*0Sstevel@tonic-gate InputImage = value;
251*0Sstevel@tonic-gate }
252*0Sstevel@tonic-gate break;
253*0Sstevel@tonic-gate case OFLAG:
254*0Sstevel@tonic-gate if (value == NULL) {
255*0Sstevel@tonic-gate missing_arg(LegalOpts[c]);
256*0Sstevel@tonic-gate } else {
257*0Sstevel@tonic-gate OutputImage = value;
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate break;
260*0Sstevel@tonic-gate default:
261*0Sstevel@tonic-gate bad_arg(value);
262*0Sstevel@tonic-gate break;
263*0Sstevel@tonic-gate }
264*0Sstevel@tonic-gate }
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate static void
sanityCheckOpts(void)268*0Sstevel@tonic-gate sanityCheckOpts(void)
269*0Sstevel@tonic-gate {
270*0Sstevel@tonic-gate if (WritableOnly && ReadOnly) {
271*0Sstevel@tonic-gate (void) fprintf(stderr,
272*0Sstevel@tonic-gate gettext("-w option may not be used with the -n "
273*0Sstevel@tonic-gate "or -m options\n"));
274*0Sstevel@tonic-gate exit(4);
275*0Sstevel@tonic-gate }
276*0Sstevel@tonic-gate }
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate static void
confirmMountable(char * special,int fd)279*0Sstevel@tonic-gate confirmMountable(char *special, int fd)
280*0Sstevel@tonic-gate {
281*0Sstevel@tonic-gate char *printName;
282*0Sstevel@tonic-gate int okayToMount = 1;
283*0Sstevel@tonic-gate
284*0Sstevel@tonic-gate printName = InputImage ? InputImage : special;
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gate if (!IsFAT32) {
287*0Sstevel@tonic-gate /* make sure we can at least read the root directory */
288*0Sstevel@tonic-gate getRootDirectory(fd);
289*0Sstevel@tonic-gate if (TheRootDir.bytes == NULL)
290*0Sstevel@tonic-gate okayToMount = 0;
291*0Sstevel@tonic-gate } else {
292*0Sstevel@tonic-gate /* check the bit designed into FAT32 for this purpose */
293*0Sstevel@tonic-gate okayToMount = checkFAT32CleanBit(fd);
294*0Sstevel@tonic-gate }
295*0Sstevel@tonic-gate if (okayToMount) {
296*0Sstevel@tonic-gate (void) fprintf(stderr,
297*0Sstevel@tonic-gate gettext("pcfs fsck: sanity check: %s okay\n"), printName);
298*0Sstevel@tonic-gate exit(0);
299*0Sstevel@tonic-gate } else {
300*0Sstevel@tonic-gate (void) fprintf(stderr,
301*0Sstevel@tonic-gate gettext("pcfs fsck: sanity check: %s needs checking\n"),
302*0Sstevel@tonic-gate printName);
303*0Sstevel@tonic-gate exit(32);
304*0Sstevel@tonic-gate }
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate
307*0Sstevel@tonic-gate void
mountSanityCheckFails(void)308*0Sstevel@tonic-gate mountSanityCheckFails(void)
309*0Sstevel@tonic-gate {
310*0Sstevel@tonic-gate if (Mflag) {
311*0Sstevel@tonic-gate (void) fprintf(stderr,
312*0Sstevel@tonic-gate gettext("pcfs fsck: sanity check failed: "));
313*0Sstevel@tonic-gate }
314*0Sstevel@tonic-gate }
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gate /*
317*0Sstevel@tonic-gate * preenBail
318*0Sstevel@tonic-gate * Routine that other routines can call if they would go into a
319*0Sstevel@tonic-gate * state where they need user input. They can send an optional
320*0Sstevel@tonic-gate * message string to be printed before the exit. Caller should
321*0Sstevel@tonic-gate * send a NULL string if they don't have an exit message.
322*0Sstevel@tonic-gate */
323*0Sstevel@tonic-gate void
preenBail(char * outString)324*0Sstevel@tonic-gate preenBail(char *outString)
325*0Sstevel@tonic-gate {
326*0Sstevel@tonic-gate /*
327*0Sstevel@tonic-gate * If we are running in the 'preen' mode, we got here because
328*0Sstevel@tonic-gate * we reached a situation that would require user intervention.
329*0Sstevel@tonic-gate * We have no choice but to bail at this point.
330*0Sstevel@tonic-gate */
331*0Sstevel@tonic-gate if (Preen) {
332*0Sstevel@tonic-gate if (outString)
333*0Sstevel@tonic-gate (void) printf("%s", outString);
334*0Sstevel@tonic-gate (void) printf(gettext("FILE SYSTEM FIX REQUIRES USER "
335*0Sstevel@tonic-gate "INTERVENTION; RUN fsck MANUALLY.\n"));
336*0Sstevel@tonic-gate exit(36);
337*0Sstevel@tonic-gate }
338*0Sstevel@tonic-gate }
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate int
main(int argc,char * argv[])341*0Sstevel@tonic-gate main(int argc, char *argv[])
342*0Sstevel@tonic-gate {
343*0Sstevel@tonic-gate char *string;
344*0Sstevel@tonic-gate int ifd, ofd;
345*0Sstevel@tonic-gate int c;
346*0Sstevel@tonic-gate
347*0Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
350*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
351*0Sstevel@tonic-gate #endif
352*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
353*0Sstevel@tonic-gate
354*0Sstevel@tonic-gate if (argc < 2)
355*0Sstevel@tonic-gate usage();
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "F:VYNynmo:")) != EOF) {
358*0Sstevel@tonic-gate switch (c) {
359*0Sstevel@tonic-gate case 'F':
360*0Sstevel@tonic-gate string = optarg;
361*0Sstevel@tonic-gate if (strcmp(string, "pcfs") != 0)
362*0Sstevel@tonic-gate usage();
363*0Sstevel@tonic-gate break;
364*0Sstevel@tonic-gate case 'V': {
365*0Sstevel@tonic-gate char *opt_text;
366*0Sstevel@tonic-gate int opt_count;
367*0Sstevel@tonic-gate
368*0Sstevel@tonic-gate (void) printf(gettext("fsck -F pcfs "));
369*0Sstevel@tonic-gate for (opt_count = 1; opt_count < argc;
370*0Sstevel@tonic-gate opt_count++) {
371*0Sstevel@tonic-gate opt_text = argv[opt_count];
372*0Sstevel@tonic-gate if (opt_text)
373*0Sstevel@tonic-gate (void) printf(" %s ",
374*0Sstevel@tonic-gate opt_text);
375*0Sstevel@tonic-gate }
376*0Sstevel@tonic-gate (void) printf("\n");
377*0Sstevel@tonic-gate exit(0);
378*0Sstevel@tonic-gate }
379*0Sstevel@tonic-gate break;
380*0Sstevel@tonic-gate case 'N':
381*0Sstevel@tonic-gate case 'n':
382*0Sstevel@tonic-gate AlwaysYes = 0;
383*0Sstevel@tonic-gate AlwaysNo = 1;
384*0Sstevel@tonic-gate ReadOnly = 1;
385*0Sstevel@tonic-gate break;
386*0Sstevel@tonic-gate case 'Y':
387*0Sstevel@tonic-gate case 'y':
388*0Sstevel@tonic-gate AlwaysYes = 1;
389*0Sstevel@tonic-gate AlwaysNo = 0;
390*0Sstevel@tonic-gate break;
391*0Sstevel@tonic-gate case 'm':
392*0Sstevel@tonic-gate Mflag++;
393*0Sstevel@tonic-gate ReadOnly = 1;
394*0Sstevel@tonic-gate break;
395*0Sstevel@tonic-gate case 'o':
396*0Sstevel@tonic-gate string = optarg;
397*0Sstevel@tonic-gate parseSubOptions(string);
398*0Sstevel@tonic-gate break;
399*0Sstevel@tonic-gate }
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate sanityCheckOpts();
403*0Sstevel@tonic-gate if (InputImage == NULL && (optind < 0 || optind >= argc))
404*0Sstevel@tonic-gate usage();
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate openFS(argv[optind], &ifd, &ofd);
407*0Sstevel@tonic-gate readBPB(ifd);
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate /*
410*0Sstevel@tonic-gate * -m mountable fs check. This call will not return.
411*0Sstevel@tonic-gate */
412*0Sstevel@tonic-gate if (Mflag)
413*0Sstevel@tonic-gate confirmMountable(argv[optind], ifd);
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate /*
416*0Sstevel@tonic-gate * Pass 1: Find any bad clusters and adjust the FAT and directory
417*0Sstevel@tonic-gate * entries accordingly
418*0Sstevel@tonic-gate */
419*0Sstevel@tonic-gate passOne(ifd);
420*0Sstevel@tonic-gate
421*0Sstevel@tonic-gate /*
422*0Sstevel@tonic-gate * XXX - future passes?
423*0Sstevel@tonic-gate * Ideas:
424*0Sstevel@tonic-gate * Data relocation for bad clusters with partial read success?
425*0Sstevel@tonic-gate * Syncing backup FAT copies with main copy?
426*0Sstevel@tonic-gate * Syncing backup root sector for FAT32?
427*0Sstevel@tonic-gate */
428*0Sstevel@tonic-gate
429*0Sstevel@tonic-gate /*
430*0Sstevel@tonic-gate * No problems if we made it this far.
431*0Sstevel@tonic-gate */
432*0Sstevel@tonic-gate printSummary(stdout);
433*0Sstevel@tonic-gate writeBackChanges(ofd);
434*0Sstevel@tonic-gate return (0);
435*0Sstevel@tonic-gate }
436