1 /* fsck.fat.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>
5 Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 The complete text of the GNU General Public License
21 can be found in /usr/share/common-licenses/GPL-3 file.
24 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
25 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
45 int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0;
46 int atari_format = 0, boot_only = 0;
48 void *mem_queue = NULL;
50 static void usage(char *name)
52 fprintf(stderr, "usage: %s [-aAbflrtvVwy] [-d path -d ...] "
53 "[-u path -u ...]\n%15sdevice\n", name, "");
54 fprintf(stderr, " -a automatically repair the filesystem\n");
55 fprintf(stderr, " -A toggle Atari filesystem format\n");
56 fprintf(stderr, " -b make read-only boot sector check\n");
58 " -c N use DOS codepage N to decode short file names (default: %d)\n",
59 DEFAULT_DOS_CODEPAGE);
60 fprintf(stderr, " -d path drop that file\n");
61 fprintf(stderr, " -f salvage unused chains to files\n");
62 fprintf(stderr, " -l list path names\n");
64 " -n no-op, check non-interactively without changing\n");
65 fprintf(stderr, " -p same as -a, for compat with other *fsck\n");
66 fprintf(stderr, " -r interactively repair the filesystem\n");
67 fprintf(stderr, " -t test for bad clusters\n");
68 fprintf(stderr, " -u path try to undelete that (non-directory) file\n");
69 fprintf(stderr, " -v verbose mode\n");
70 fprintf(stderr, " -V perform a verification pass\n");
71 fprintf(stderr, " -w write changes to disk immediately\n");
72 fprintf(stderr, " -y same as -a, for compat with other *fsck\n");
77 * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
78 * of MS-DOS filesystem by default.
80 static void check_atari(void)
86 if (!(f = fopen("/proc/hardware", "r"))) {
87 perror("/proc/hardware");
91 while (fgets(line, sizeof(line), f)) {
92 if (strncmp(line, "Model:", 6) == 0) {
94 p += strspn(p, " \t");
95 if (strncmp(p, "Atari ", 6) == 0)
104 int main(int argc, char **argv)
107 int salvage_files, verify, c;
108 uint32_t free_clusters = 0;
110 memset(&fs, 0, sizeof(fs));
111 rw = salvage_files = verify = 0;
115 while ((c = getopt(argc, argv, "Aac:d:bflnprtu:vVwy")) != EOF)
117 case 'A': /* toggle Atari format */
118 atari_format = !atari_format;
133 set_dos_codepage(atoi(optarg));
136 file_add(optarg, fdt_drop);
156 file_add(optarg, fdt_undelete);
170 set_dos_codepage(-1); /* set default codepage if none was given in command line */
171 if ((test || write_immed) && !rw) {
172 fprintf(stderr, "-t and -w require -a or -r\n");
175 if (optind != argc - 1)
178 printf("fsck.fat " VERSION " (" VERSION_DATE ")\n");
179 fs_open(argv[optind], rw);
186 printf("Starting check/repair pass.\n");
187 while (read_fat(&fs), scan_root(&fs))
195 free_clusters = update_free(&fs);
200 printf("Starting verification pass.\n");
211 rw = get_key("yn", "Perform changes ? (y/n)") == 'y';
213 printf("Performing changes.\n");
215 printf("Leaving filesystem unchanged.\n");
219 printf("%s: %u files, %lu/%lu clusters\n", argv[optind],
220 n_files, (unsigned long)fs.clusters - free_clusters, (unsigned long)fs.clusters);
222 return fs_close(rw) ? 1 : 0;