1 /* dosfsck.c - User interface
3 Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4 Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 On Debian systems, the complete text of the GNU General Public License
20 can be found in /usr/share/common-licenses/GPL-3 file.
23 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
24 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
45 int interactive = 0,rw = 0,list = 0,test = 0,verbose = 0,write_immed = 0;
48 void *mem_queue = NULL;
51 static void usage(char *name)
53 fprintf(stderr,"usage: %s [-aAflrtvVwy] [-d path -d ...] "
54 "[-u path -u ...]\n%15sdevice\n",name,"");
55 fprintf(stderr," -a automatically repair the file system\n");
56 fprintf(stderr," -A toggle Atari file system format\n");
57 fprintf(stderr," -d path drop that file\n");
58 fprintf(stderr," -f salvage unused chains to files\n");
59 fprintf(stderr," -l list path names\n");
60 fprintf(stderr," -n no-op, check non-interactively without changing\n");
61 fprintf(stderr," -p same as -a, for compat with other *fsck\n");
62 fprintf(stderr," -r interactively repair the file system\n");
63 fprintf(stderr," -t test for bad clusters\n");
64 fprintf(stderr," -u path try to undelete that (non-directory) file\n");
65 fprintf(stderr," -v verbose mode\n");
66 fprintf(stderr," -V perform a verification pass\n");
67 fprintf(stderr," -w write changes to disk immediately\n");
68 fprintf(stderr," -y same as -a, for compat with other *fsck\n");
74 * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
75 * of MS-DOS filesystem by default.
77 static void check_atari( void )
83 if (!(f = fopen( "/proc/hardware", "r" ))) {
84 perror( "/proc/hardware" );
88 while( fgets( line, sizeof(line), f ) ) {
89 if (strncmp( line, "Model:", 6 ) == 0) {
91 p += strspn( p, " \t" );
92 if (strncmp( p, "Atari ", 6 ) == 0)
102 int main(int argc,char **argv)
105 int salvage_files,verify,c;
106 unsigned n_files_check=0, n_files_verify=0;
107 unsigned long free_clusters;
109 memset(&fs, 0, sizeof(fs));
110 rw = salvage_files = verify = 0;
114 while ((c = getopt(argc,argv,"Aad:flnprtu:vVwy")) != EOF)
116 case 'A': /* toggle Atari format */
117 atari_format = !atari_format;
127 file_add(optarg,fdt_drop);
147 file_add(optarg,fdt_undelete);
151 printf("dosfsck " VERSION " (" VERSION_DATE ")\n");
162 if ((test || write_immed) && !rw) {
163 fprintf(stderr,"-t and -w require -a or -r\n");
166 if (optind != argc-1) usage(argv[0]);
168 printf( "dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
169 fs_open(argv[optind],rw);
171 if (verify) printf("Starting check/repair pass.\n");
172 while (read_fat(&fs), scan_root(&fs)) qfree(&mem_queue);
173 if (test) fix_bad(&fs);
174 if (salvage_files) reclaim_file(&fs);
175 else reclaim_free(&fs);
176 free_clusters = update_free(&fs);
179 n_files_check = n_files;
182 printf("Starting verification pass.\n");
187 n_files_verify = n_files;
193 rw = get_key("yn","Perform changes ? (y/n)") == 'y';
194 else printf("Performing changes.\n");
197 printf("Leaving file system unchanged.\n");
200 printf( "%s: %u files, %lu/%lu clusters\n", argv[optind],
201 n_files, fs.clusters - free_clusters, fs.clusters );
203 return fs_close(rw) ? 1 : 0;