summaryrefslogtreecommitdiffstats
path: root/dosfstools/src/fsck.fat.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dosfstools/src/fsck.fat.c (renamed from dosfstools/src/dosfsck.c)79
1 files changed, 35 insertions, 44 deletions
diff --git a/dosfstools/src/dosfsck.c b/dosfstools/src/fsck.fat.c
index a7a59e1a1..2bc3dc216 100644
--- a/dosfstools/src/dosfsck.c
+++ b/dosfstools/src/fsck.fat.c
@@ -1,7 +1,8 @@
-/* dosfsck.c - User interface
+/* fsck.fat.c - User interface
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
+ Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
- On Debian systems, the complete text of the GNU General Public License
+ The complete text of the GNU General Public License
can be found in /usr/share/common-licenses/GPL-3 file.
*/
@@ -33,7 +34,7 @@
#include <getopt.h>
#include "common.h"
-#include "dosfsck.h"
+#include "fsck.fat.h"
#include "io.h"
#include "boot.h"
#include "fat.h"
@@ -41,40 +42,31 @@
#include "check.h"
int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0;
-int atari_format = 0;
+int atari_format = 0, boot_only = 0;
unsigned n_files = 0;
void *mem_queue = NULL;
-#ifdef USE_ANDROID_RETVALS
-unsigned retandroid = 1;
-#else
-unsigned retandroid = 0;
-#endif
-
static void usage(char *name)
{
- fprintf(stderr, "usage: %s [-aAflrtvVwy] [-d path -d ...] "
+ fprintf(stderr, "usage: %s [-aAbflrtvVwy] [-d path -d ...] "
"[-u path -u ...]\n%15sdevice\n", name, "");
- fprintf(stderr, " -a automatically repair the file system\n");
- fprintf(stderr, " -A toggle Atari file system format\n");
+ fprintf(stderr, " -a automatically repair the filesystem\n");
+ fprintf(stderr, " -A toggle Atari filesystem format\n");
+ fprintf(stderr, " -b make read-only boot sector check\n");
fprintf(stderr, " -d path drop that file\n");
- fprintf(stderr, " -f ignored\n");
+ fprintf(stderr, " -f salvage unused chains to files\n");
fprintf(stderr, " -l list path names\n");
fprintf(stderr,
" -n no-op, check non-interactively without changing\n");
fprintf(stderr, " -p same as -a, for compat with other *fsck\n");
- fprintf(stderr, " -r interactively repair the file system\n");
+ fprintf(stderr, " -r interactively repair the filesystem (default)\n");
fprintf(stderr, " -t test for bad clusters\n");
fprintf(stderr, " -u path try to undelete that (non-directory) file\n");
fprintf(stderr, " -v verbose mode\n");
fprintf(stderr, " -V perform a verification pass\n");
fprintf(stderr, " -w write changes to disk immediately\n");
fprintf(stderr, " -y same as -a, for compat with other *fsck\n");
- if (retandroid) {
- exit(1);
- } else {
- exit(2);
- }
+ exit(2);
}
/*
@@ -109,15 +101,14 @@ int main(int argc, char **argv)
{
DOS_FS fs;
int salvage_files, verify, c;
- unsigned n_files_check = 0, n_files_verify = 0;
- unsigned long free_clusters;
+ uint32_t free_clusters = 0;
memset(&fs, 0, sizeof(fs));
- rw = salvage_files = verify = 0;
- interactive = 1;
+ salvage_files = verify = 0;
+ rw = interactive = 1;
check_atari();
- while ((c = getopt(argc, argv, "Aad:flnprtu:vVwy")) != EOF)
+ while ((c = getopt(argc, argv, "Aad:bflnprtu:vVwy")) != -1)
switch (c) {
case 'A': /* toggle Atari format */
atari_format = !atari_format;
@@ -129,6 +120,11 @@ int main(int argc, char **argv)
interactive = 0;
salvage_files = 1;
break;
+ case 'b':
+ rw = 0;
+ interactive = 0;
+ boot_only = 1;
+ break;
case 'd':
file_add(optarg, fdt_drop);
break;
@@ -154,7 +150,6 @@ int main(int argc, char **argv)
break;
case 'v':
verbose = 1;
- printf("dosfsck " VERSION " (" VERSION_DATE ")\n");
break;
case 'V':
verify = 1;
@@ -166,33 +161,32 @@ int main(int argc, char **argv)
usage(argv[0]);
}
if ((test || write_immed) && !rw) {
- fprintf(stderr, "-t and -w require -a or -r\n");
- if (retandroid) {
- exit(1);
- } else {
- exit(2);
- }
+ fprintf(stderr, "-t and -w can not be used in read only mode\n");
+ exit(2);
}
if (optind != argc - 1)
usage(argv[0]);
- printf("dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n");
+ printf("fsck.fat " VERSION " (" VERSION_DATE ")\n");
fs_open(argv[optind], rw);
+
read_boot(&fs);
+ if (boot_only)
+ goto exit;
+
if (verify)
printf("Starting check/repair pass.\n");
while (read_fat(&fs), scan_root(&fs))
qfree(&mem_queue);
if (test)
fix_bad(&fs);
- if (salvage_files && 0)
+ if (salvage_files)
reclaim_file(&fs);
else
reclaim_free(&fs);
free_clusters = update_free(&fs);
file_unused();
qfree(&mem_queue);
- n_files_check = n_files;
if (verify) {
n_files = 0;
printf("Starting verification pass.\n");
@@ -200,9 +194,9 @@ int main(int argc, char **argv)
scan_root(&fs);
reclaim_free(&fs);
qfree(&mem_queue);
- n_files_verify = n_files;
}
+exit:
if (fs_changed()) {
if (rw) {
if (interactive)
@@ -210,15 +204,12 @@ int main(int argc, char **argv)
else
printf("Performing changes.\n");
} else
- printf("Leaving file system unchanged.\n");
+ printf("Leaving filesystem unchanged.\n");
}
- printf("%s: %u files, %lu/%lu clusters\n", argv[optind],
- n_files, fs.clusters - free_clusters, fs.clusters);
+ if (!boot_only)
+ printf("%s: %u files, %lu/%lu clusters\n", argv[optind],
+ n_files, (unsigned long)fs.clusters - free_clusters, (unsigned long)fs.clusters);
- if (retandroid) {
- return fs_close(rw) ? 4 : 0;
- } else {
- return fs_close(rw) ? 1 : 0;
- }
+ return fs_close(rw) ? 1 : 0;
}