67 static void usage(
char *name,
int exitval)
69 fprintf(stderr,
"Usage: %s [OPTIONS] DEVICE\n", name);
70 fprintf(stderr,
"Check FAT filesystem on DEVICE for errors.\n");
71 fprintf(stderr,
"\n");
72 fprintf(stderr,
"Options:\n");
73 fprintf(stderr,
" -a automatically repair the filesystem\n");
74 fprintf(stderr,
" -A toggle Atari variant of the FAT filesystem\n");
75 fprintf(stderr,
" -b make read-only boot sector check\n");
76 fprintf(stderr,
" -c N use DOS codepage N to decode short file names (default: %d)\n",
78 fprintf(stderr,
" -d PATH drop file with name PATH (can be given multiple times)\n");
79 fprintf(stderr,
" -f salvage unused chains to files\n");
80 fprintf(stderr,
" -F NUM specify FAT table NUM used for filesystem access\n");
81 fprintf(stderr,
" -l list path names\n");
82 fprintf(stderr,
" -n no-op, check non-interactively without changing\n");
83 fprintf(stderr,
" -p same as -a, for compat with other *fsck\n");
84 fprintf(stderr,
" -r interactively repair the filesystem (default)\n");
85 fprintf(stderr,
" -S disallow spaces in the middle of short file names\n");
86 fprintf(stderr,
" -t test for bad clusters\n");
87 fprintf(stderr,
" -u PATH try to undelete (non-directory) file that was named PATH (can be\n");
88 fprintf(stderr,
" given multiple times)\n");
89 fprintf(stderr,
" -U allow only uppercase characters in volume and boot label\n");
90 fprintf(stderr,
" -v verbose mode\n");
91 fprintf(stderr,
" -V perform a verification pass\n");
92 fprintf(stderr,
" --variant=TYPE handle variant TYPE of the filesystem\n");
93 fprintf(stderr,
" -w write changes to disk immediately\n");
94 fprintf(stderr,
" -y same as -a, for compat with other *fsck\n");
95 fprintf(stderr,
" --help print this message\n");
99 int main(
int argc,
char **argv)
102 int salvage_files, verify, c;
103 uint32_t free_clusters = 0;
108 enum {OPT_HELP=1000, OPT_VARIANT};
109 const struct option long_options[] = {
110 {
"variant", required_argument, NULL, OPT_VARIANT},
111 {
"help", no_argument, NULL, OPT_HELP},
117 tio.c_lflag &= ~(ICANON | ECHO);
118 tcsetattr(0, TCSAFLUSH, &tio);
122 memset(&fs, 0,
sizeof(fs));
123 salvage_files = verify = 0;
127 while ((c = getopt_long(argc, argv,
"Aac:d:bfF:lnprStu:UvVwy",
128 long_options, NULL)) != -1)
147 codepage = strtol(optarg, &tmp, 10);
148 if (!*optarg || isspace(*optarg) || *tmp || errno || codepage < 0 || codepage > INT_MAX) {
149 fprintf(stderr,
"Invalid codepage : %s\n", optarg);
164 if (!*optarg || isspace(*optarg) || *tmp || errno || fat_table < 0 || fat_table > 255) {
165 fprintf(stderr,
"Invalid FAT table : %s\n", optarg);
199 if (!strcasecmp(optarg,
"standard")) {
201 }
else if (!strcasecmp(optarg,
"atari")) {
204 fprintf(stderr,
"Unknown variant: %s\n", optarg);
219 "Internal error: getopt_long() returned unexpected value %d\n", c);
225 fprintf(stderr,
"-t and -w can not be used in read only mode\n");
228 if (optind != argc - 1)
231 printf(
"fsck.fat " VERSION
" (" VERSION_DATE
")\n");
239 printf(
"Starting check/repair pass.\n");
256 printf(
"Starting verification pass.\n");
270 printf(
"\n*** Filesystem was changed ***\n");
272 printf(
"The changes have not yet been written, you can still choose to leave the\n"
273 "filesystem unmodified:\n");
278 2,
"Leave filesystem unchanged") == 1;
280 printf(
"\nLeaving filesystem unchanged.\n");
284 printf(
"%s: %u files, %lu/%lu clusters\n", argv[optind],
void read_boot(DOS_FS *fs)
int set_dos_codepage(int codepage)
#define DEFAULT_DOS_CODEPAGE
int scan_root(DOS_FS *fs)
void check_label(DOS_FS *fs)
void check_dirty_bits(DOS_FS *fs)
int get_choice(int noninteractive_result, const char *noninteractive_msg, int choices,...)
void reclaim_free(DOS_FS *fs)
void release_fat(DOS_FS *fs)
uint32_t update_free(DOS_FS *fs)
void read_fat(DOS_FS *fs, int mode)
void reclaim_file(DOS_FS *fs)
void file_add(char *path, FD_TYPE type)
static struct termios original_termios
static void restore_termios(void)
static void usage(char *name, int exitval)
int main(int argc, char **argv)
void fs_open(const char *path, int rw)