335{
337 unsigned total_sectors;
338 unsigned int logical_sector_size,
sectors;
340 unsigned total_fat_entries;
342
345 if (!logical_sector_size)
346 die(
"Logical sector size is zero.");
347
348
349
350
352 die(
"Logical sector size (%d bytes) is not a multiple of the physical "
353 "sector size.", logical_sector_size);
354
355 fs->cluster_size =
b.cluster_size * logical_sector_size;
356 if (!
fs->cluster_size)
357 die(
"Cluster size is zero.");
358 if (
b.fats != 2 &&
b.fats != 1)
359 die(
"Currently, only 1 or 2 FATs are supported, not %d.\n",
b.fats);
364 printf(
"Checking we can access the last sector of the filesystem\n");
365
366 fs_test((
off_t)((total_sectors & ~1) - 1) * logical_sector_size,
367 logical_sector_size);
368
372 die(
"FAT size is zero.");
373
374 fs->fat_start = (
off_t)le16toh(
b.reserved) * logical_sector_size;
376 logical_sector_size;
380 logical_sector_size);
381
382 data_size = (
off_t)total_sectors * logical_sector_size -
fs->data_start;
384 die(
"Filesystem has no space for any data clusters");
385
386 fs->data_clusters = data_size /
fs->cluster_size;
387 fs->root_cluster = 0;
388 fs->fsinfo_start = 0;
389 fs->free_clusters = -1;
390 if (!
b.fat_length &&
b.fat32_length) {
392 fs->root_cluster = le32toh(
b.root_cluster);
393 if (!
fs->root_cluster &&
fs->root_entries)
394
395
396
397
398
399 printf(
"Warning: FAT32 root dir not in cluster chain! "
400 "Compatibility mode...\n");
401 else if (!
fs->root_cluster && !
fs->root_entries)
402 die(
"No root directory!");
403 else if (
fs->root_cluster &&
fs->root_entries)
404 printf(
"Warning: FAT32 root dir is in a cluster chain, but "
405 "a separate root dir\n"
406 " area is defined. Cannot fix this easily.\n");
408 printf(
"Warning: Filesystem is FAT32 according to fat_length "
409 "and fat32_length fields,\n"
410 " but has only %lu clusters, less than the required "
411 "minimum of %d.\n"
412 " This may lead to problems on some systems.\n",
414
416 fs->backupboot_start = le16toh(
b.backup_boot) * logical_sector_size;
418
421
422
425 die(
"Too many clusters (%lu) for FAT16 filesystem.",
426 (
unsigned long)
fs->data_clusters);
428 } else {
429
430
432
433
434 if (
fs->data_clusters + 2 >
fat_length * logical_sector_size * 8 / 16 ||
435
436 (total_sectors == 720 || total_sectors == 1440 ||
437 total_sectors == 2880))
439 }
440
441 fs->eff_fat_bits = (
fs->fat_bits == 32) ? 28 :
fs->fat_bits;
443
445 if (
fs->fat_bits == 12 ||
fs->fat_bits == 16) {
449 else
450#ifdef __REACTOS__
451 {
453#endif
455#ifdef __REACTOS__
456 }
457#endif
458 }
else if (
fs->fat_bits == 32) {
459 if (
b.extended_sig == 0x29)
461 else
462#ifdef __REACTOS__
463 {
465#endif
467#ifdef __REACTOS__
468 }
469#endif
470 }
471
472 total_fat_entries = (
uint64_t)
fs->fat_size * 8 /
fs->fat_bits;
473 if (
fs->data_clusters > total_fat_entries - 2)
474 die(
"Filesystem has %u clusters but only space for %u FAT entries.",
475 fs->data_clusters, total_fat_entries - 2);
476 if (!
fs->root_entries && !
fs->root_cluster)
477 die(
"Root directory has zero size.");
479 die(
"Root directory (%d entries) doesn't span an integral number of "
480 "sectors.",
fs->root_entries);
482 die(
"Logical sector size (%u bytes) is not a multiple of the physical "
483 "sector size.", logical_sector_size);
484#if 0
485
487 die(
"Invalid disk format in boot sector.");
488#endif
491}
GLboolean GLboolean GLboolean b
#define memmove(s1, s2, n)
static void read_fsinfo(DOS_FS *fs, struct boot_sector *b, unsigned int lss)
static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, unsigned int lss)
#define ROUND_TO_MULTIPLE(n, m)
#define GET_UNALIGNED_W(f)
static void check_fat_state_bit(DOS_FS *fs, void *b)
static void dump_boot(DOS_FS *fs, struct boot_sector *b, unsigned lss)
int fs_test(off_t pos, int size)