Uploaded image for project: 'Core ReactOS'
  1. Core ReactOS
  2. CORE-11283

FAT32 wrong calculation of FATSectors32 possible

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 0.4.2
    • Setup

    Description

      After partitioning the disk with an external tool, I tried to let the reactos installer format the disk. This caused an error in
      reactos\sdk\lib\fslib\vfatlib\check\boot.c:441

          if (fs->data_clusters >
              ((uint64_t)fs->fat_size * 8 / fs->fat_bits) - 2)
              die("Filesystem has %d clusters but only space for %d FAT entries.",
                  fs->data_clusters,
                  ((unsigned long long)fs->fat_size * 8 / fs->fat_bits) - 2);

      The following parameters were used:

      BootSector.SectorsHuge 41926656
      BootSector.ReservedSectors 32
      BootSector.BytesPerSector 512
      BootSector.SectorsPerCluster 32
      BootSector.FATCount 2

      In reactos\sdk\lib\fslib\vfatlib\fat32.c

          /* Calculate number of FAT sectors */
          /* (BytesPerSector / 4) FAT entries (32bit) fit into one sector */
          TmpVal1 = BootSector.SectorsHuge - BootSector.ReservedSectors;
          TmpVal2 = ((BootSector.BytesPerSector / 4) * BootSector.SectorsPerCluster) + BootSector.FATCount;
          BootSector.FATSectors32 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2;
          DPRINT("FATSectors32 = %lu\n", BootSector.FATSectors32);

      Resulting in BootSector.FATSectors32=10231, which results in the (fatal) error "Filesystem has 1309567 clusters but only space for 1309566 FAT entries" later during installation.

      The current calculation is would be perfect if all entries of a fat table are usable. But the first two entries are not, see (1).

      Attached a patch which simply verifies the calculation, and add a sector to the fat table if required. The attached logfile and spreadsheet are just for reference.

      (1): https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html#ss1.3

      Attachments

        Activity

          People

            Heis Spiter Pierre Schweitzer
            wimh wimh
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: