1 /* dosfsck.c - User interface */
3 /* Written 1993 by Werner Almesberger */
5 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
6 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
27 int interactive
= 0,list
= 0,test
= 0,verbose
= 0,write_immed
= 0;
30 void *mem_queue
= NULL
;
33 static void usage(char *name
)
35 fprintf(stderr
,"usage: %s [-aAflrtvVwy] [-d path -d ...] "
36 "[-u path -u ...]\n%15sdevice\n",name
,"");
37 fprintf(stderr
," -a automatically repair the file system\n");
38 fprintf(stderr
," -A toggle Atari file system format\n");
39 fprintf(stderr
," -d path drop that file\n");
40 fprintf(stderr
," -f salvage unused chains to files\n");
41 fprintf(stderr
," -l list path names\n");
42 fprintf(stderr
," -n no-op, check non-interactively without changing\n");
43 fprintf(stderr
," -r interactively repair the file system\n");
44 fprintf(stderr
," -t test for bad clusters\n");
45 fprintf(stderr
," -u path try to undelete that (non-directory) file\n");
46 fprintf(stderr
," -v verbose mode\n");
47 fprintf(stderr
," -V perform a verification pass\n");
48 fprintf(stderr
," -w write changes to disk immediately\n");
49 fprintf(stderr
," -y same as -a, for compat with other *fsck\n");
55 * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
56 * of MS-DOS filesystem by default.
58 static void check_atari( void )
64 if (!(f
= fopen( "/proc/hardware", "r" ))) {
65 perror( "/proc/hardware" );
69 while( fgets( line
, sizeof(line
), f
) ) {
70 if (strncmp( line
, "Model:", 6 ) == 0) {
72 p
+= strspn( p
, " \t" );
73 if (strncmp( p
, "Atari ", 6 ) == 0)
83 int main(int argc
,char **argv
)
86 int rw
,salvage_files
,verify
,c
;
87 unsigned long free_clusters
;
89 rw
= salvage_files
= verify
= 0;
93 while ((c
= getopt(argc
,argv
,"Aad:flnrtu:vVwy")) != EOF
)
95 case 'A': /* toggle Atari format */
96 atari_format
= !atari_format
;
105 file_add(optarg
,fdt_drop
);
125 file_add(optarg
,fdt_undelete
);
129 printf("dosfsck " VERSION
" (" VERSION_DATE
")\n");
141 if ((test
|| write_immed
) && !rw
) {
142 fprintf(stderr
,"-t and -w require -a or -r\n");
145 if (optind
!= argc
-1) usage(argv
[0]);
147 printf( "dosfsck " VERSION
", " VERSION_DATE
", FAT32, LFN\n" );
148 fs_open(argv
[optind
],rw
);
150 if (verify
) printf("Starting check/repair pass.\n");
151 while (read_fat(&fs
), scan_root(&fs
)) qfree(&mem_queue
);
152 if (test
) fix_bad(&fs
);
153 if (salvage_files
) reclaim_file(&fs
);
154 else reclaim_free(&fs
);
155 free_clusters
= update_free(&fs
);
159 printf("Starting verification pass.\n");
169 rw
= get_key("yn","Perform changes ? (y/n)") == 'y';
170 else printf("Performing changes.\n");
173 printf("Leaving file system unchanged.\n");
176 printf( "%s: %u files, %lu/%lu clusters\n", argv
[optind
],
177 n_files
, fs
.clusters
- free_clusters
, fs
.clusters
);
179 return fs_close(rw
) ? 1 : 0;
182 /* Local Variables: */