Changeset 292


Ignore:
Timestamp:
Jul 16, 2017, 8:18:06 PM (3 years ago)
Author:
Valery V. Sedletski
Message:

FORMAT: Use dp.SectorsPerCluster? instead of params->sectors_per_cluster (it may be zero in some cases, so it cause FORMAT trap).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ufat32/format.c

    r289 r292  
    479479
    480480    // Checks on Disk Size
    481     // qTotalSectors = dp.PartitionLength / dp.BytesPerSect;
    482481    qTotalSectors = dp.TotalSectors;
    483482
     
    488487
    489488    FatSize = get_fat_size_sectors ( params, dp.TotalSectors,
    490         dp.ReservedSectCount, params->sectors_per_cluster,
     489        dp.ReservedSectCount, dp.SectorsPerCluster,
    491490        dp.NumFATs, dp.BytesPerSect );
    492491
     
    495494    if (params->bFatType < FAT_TYPE_FAT32)
    496495        // root dir is excluded from user area on FAT12/FAT16
    497         UserAreaSize -= params->sectors_per_cluster; // ???!
    498 
    499     ClusterCount = UserAreaSize / params->sectors_per_cluster;
     496        UserAreaSize -= dp.SectorsPerCluster; // ???!
     497
     498    ClusterCount = UserAreaSize / dp.SectorsPerCluster;
    500499
    501500    if ( (ClusterCount >= FAT12_BAD_CLUSTER && params->bFatType == FAT_TYPE_FAT12) ||
     
    627626        pFATBootSect->wBytsPerSec = (WORD) dp.BytesPerSect;
    628627
    629         pFATBootSect->bSecPerClus = (BYTE) params->sectors_per_cluster;
     628        pFATBootSect->bSecPerClus = (BYTE) dp.SectorsPerCluster;
    630629        pFATBootSect->wRsvdSecCnt = (WORD) dp.ReservedSectCount;
    631630        pFATBootSect->bNumFATs = (BYTE) dp.NumFATs;
    632         pFATBootSect->wRootEntCnt = (params->sectors_per_cluster * dp.BytesPerSect) /
     631        pFATBootSect->wRootEntCnt = (dp.SectorsPerCluster * dp.BytesPerSect) /
    633632            sizeof(DIRENTRY); // number of dir entries per cluster
    634633
     
    674673        pFAT32BootSect->wBytsPerSec = (WORD) dp.BytesPerSect;
    675674
    676         pFAT32BootSect->bSecPerClus = (BYTE) params->sectors_per_cluster;
     675        pFAT32BootSect->bSecPerClus = (BYTE) dp.SectorsPerCluster;
    677676        pFAT32BootSect->wRsvdSecCnt = (WORD) dp.ReservedSectCount;
    678677        pFAT32BootSect->bNumFATs = (BYTE) dp.NumFATs;
     
    708707    {
    709708        USHORT usSectorSize  = (USHORT)dp.BytesPerSect;
    710         USHORT usClusterSize = (USHORT)params->sectors_per_cluster;
     709        USHORT usClusterSize = (USHORT)dp.SectorsPerCluster;
    711710
    712711        // fill out the boot sector and fs info
     
    722721        pEXFATBootSect->ulClusterHeapOffset = pEXFATBootSect->ulFatOffset + pEXFATBootSect->ulFatLength;
    723722        pEXFATBootSect->ulClusterCount = (ULONG)((dp.TotalSectors - FatSize
    724             - dp.ReservedSectCount) / params->sectors_per_cluster);
     723            - dp.ReservedSectCount) / dp.SectorsPerCluster);
    725724        ulExfatBitmapLen = (pEXFATBootSect->ulClusterCount / 8) +
    726725           (pEXFATBootSect->ulClusterCount % 8 ? 1 : 0);
    727         ulExfatBitmapClusters = ulExfatBitmapLen / (params->sectors_per_cluster * dp.BytesPerSect);
    728         ulExfatBitmapClusters = (ulExfatBitmapLen % (params->sectors_per_cluster * dp.BytesPerSect)) ?
     726        ulExfatBitmapClusters = ulExfatBitmapLen / (dp.SectorsPerCluster * dp.BytesPerSect);
     727        ulExfatBitmapClusters = (ulExfatBitmapLen % (dp.SectorsPerCluster * dp.BytesPerSect)) ?
    729728            ulExfatBitmapClusters + 1 : ulExfatBitmapClusters;
    730729        ulExfatUpCaseLen = sizeof(pUpCase);
    731         ulExfatUpCaseClusters = ulExfatUpCaseLen / (params->sectors_per_cluster * dp.BytesPerSect);
    732         ulExfatUpCaseClusters = (ulExfatUpCaseLen % (params->sectors_per_cluster * dp.BytesPerSect)) ?
     730        ulExfatUpCaseClusters = ulExfatUpCaseLen / (dp.SectorsPerCluster * dp.BytesPerSect);
     731        ulExfatUpCaseClusters = (ulExfatUpCaseLen % (dp.SectorsPerCluster * dp.BytesPerSect)) ?
    733732            ulExfatUpCaseClusters + 1 : ulExfatUpCaseClusters;
    734733        pEXFATBootSect->RootDirStrtClus = 2 + ulExfatBitmapClusters + ulExfatUpCaseClusters;
     
    762761        pEXFATBootSect->usBootSig = 0xaa55;
    763762
    764         mem_alloc ( (void **)&pBitmap,  ulExfatBitmapClusters * params->sectors_per_cluster * dp.BytesPerSect);
     763        mem_alloc ( (void **)&pBitmap,  ulExfatBitmapClusters * dp.SectorsPerCluster * dp.BytesPerSect);
    765764
    766765        if ( !pBitmap )
    767766             die ( "Failed to allocate memory", -2 );
    768767
    769         mem_alloc ( (void **)&pRootDir,  params->sectors_per_cluster * dp.BytesPerSect);
     768        mem_alloc ( (void **)&pRootDir,  dp.SectorsPerCluster * dp.BytesPerSect);
    770769
    771770        if ( !pRootDir )
    772771             die ( "Failed to allocate memory", -2 );
    773772
    774         mem_alloc ( (void **)&pUpCaseTbl,  ulExfatUpCaseClusters * params->sectors_per_cluster * dp.BytesPerSect);
     773        mem_alloc ( (void **)&pUpCaseTbl,  ulExfatUpCaseClusters * dp.SectorsPerCluster * dp.BytesPerSect);
    775774
    776775        if ( !pRootDir )
     
    837836    // Now we're commited - print some info first
    838837    show_message ( "Size: %g MB %u sectors.\n", 0, 0, 2, (double) ((dp.TotalSectors / (1024*1024)) * dp.BytesPerSect), dp.TotalSectors );
    839     show_message ( "%d Bytes Per Sector, Cluster size %d bytes.\n", 0, 0, 2, dp.BytesPerSect, params->sectors_per_cluster * dp.BytesPerSect );
     838    show_message ( "%d Bytes Per Sector, Cluster size %d bytes.\n", 0, 0, 2, dp.BytesPerSect, dp.SectorsPerCluster * dp.BytesPerSect );
    840839
    841840    show_message ( "Volume label is %1.\n", 0, 1375, 1, TYPE_STRING, vol );
     
    851850   
    852851    // fix up the FSInfo sector
    853     pFAT32FsInfo->dFree_Count = (UserAreaSize/params->sectors_per_cluster)-1;
     852    pFAT32FsInfo->dFree_Count = (UserAreaSize/dp.SectorsPerCluster)-1;
    854853    pFAT32FsInfo->dNxt_Free = 3; // clusters 0-1 resered, we used cluster 2 for the root dir
    855854
    856     sprintf(szString, "%lu", (pFAT32FsInfo->dFree_Count / 1024) * (params->sectors_per_cluster * dp.BytesPerSect));
     855    sprintf(szString, "%lu", (pFAT32FsInfo->dFree_Count / 1024) * (dp.SectorsPerCluster * dp.BytesPerSect));
    857856    show_message ( "%1 kilobytes are available.\n", 0, 537, 1, TYPE_STRING, szString);
    858857
     
    865864
    866865    // First zero out ReservedSect + FatSize * NumFats + SectorsPerCluster
    867     SystemAreaSize = (dp.ReservedSectCount+((DWORD)dp.NumFATs*FatSize) + params->sectors_per_cluster);
     866    SystemAreaSize = (dp.ReservedSectCount+((DWORD)dp.NumFATs*FatSize) + dp.SectorsPerCluster);
    868867
    869868#ifdef EXFAT
     
    10301029
    10311030        // write bitmap
    1032         memset( pBitmap, 0, ulExfatBitmapClusters * params->sectors_per_cluster * dp.BytesPerSect );
     1031        memset( pBitmap, 0, ulExfatBitmapClusters * dp.SectorsPerCluster * dp.BytesPerSect );
    10331032        // bitmap clusters
    10341033        for ( i = 0; i < ulExfatBitmapClusters; i++)
     
    10431042        // root dir cluster
    10441043        SetBmpEntry2(pBitmap, &dp, 2 + ulExfatBitmapClusters + i, 1);
    1045         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pBitmap, ulExfatBitmapClusters * params->sectors_per_cluster );
     1044        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pBitmap, ulExfatBitmapClusters * dp.SectorsPerCluster );
    10461045
    10471046        // write upcase table
    1048         memset( pUpCaseTbl, 0, ulExfatUpCaseClusters * params->sectors_per_cluster * dp.BytesPerSect );
     1047        memset( pUpCaseTbl, 0, ulExfatUpCaseClusters * dp.SectorsPerCluster * dp.BytesPerSect );
    10491048        memcpy( pUpCaseTbl, pUpCase, ulExfatUpCaseLen );
    1050         SectorStart += ulExfatBitmapClusters * params->sectors_per_cluster;
    1051         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pUpCaseTbl, ulExfatUpCaseClusters * params->sectors_per_cluster );
     1049        SectorStart += ulExfatBitmapClusters * dp.SectorsPerCluster;
     1050        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pUpCaseTbl, ulExfatUpCaseClusters * dp.SectorsPerCluster );
    10521051
    10531052        // write root dir
    1054         memset( pRootDir, 0, params->sectors_per_cluster * dp.BytesPerSect );
     1053        memset( pRootDir, 0, dp.SectorsPerCluster * dp.BytesPerSect );
    10551054        // volume label
    10561055        pDir->bEntryType = ENTRY_TYPE_VOLUME_LABEL;
     
    10691068        pDir->u.UpCaseTbl.ulTblCheckSum = GetChkSum2((char *)pUpCase, ulExfatUpCaseLen);
    10701069        //
    1071         SectorStart += ulExfatUpCaseClusters * params->sectors_per_cluster;
    1072         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pRootDir, params->sectors_per_cluster );
     1070        SectorStart += ulExfatUpCaseClusters * dp.SectorsPerCluster;
     1071        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pRootDir, dp.SectorsPerCluster );
    10731072    }
    10741073#endif
     
    11361135    {
    11371136        mem_free ( (void *)pEXFATBootSect, dp.BytesPerSect );
    1138         mem_free ( (void *)pBitmap,  params->sectors_per_cluster * dp.BytesPerSect );
    1139         mem_free ( (void *)pRootDir, params->sectors_per_cluster * dp.BytesPerSect );
     1137        mem_free ( (void *)pBitmap,  dp.SectorsPerCluster * dp.BytesPerSect );
     1138        mem_free ( (void *)pRootDir, dp.SectorsPerCluster * dp.BytesPerSect );
    11401139    }
    11411140#endif
Note: See TracChangeset for help on using the changeset viewer.