Changeset 289


Ignore:
Timestamp:
Jul 6, 2017, 9:53:56 AM (8 years ago)
Author:
Valery V. Sedletski
Message:
  • Fix skipping 2nd cluster on exFAT when cluster size is 128+ KB when reading and writing files.
  • Make FORMAT create FS'es with 128 KB or more clusters. Support the case with a very small (1kb or so) clusters, when the allocation bitmap uses many clusters, so they don't fit into one FAT sector.
  • Add support for adding timestamps for files created by CHKDSK.
Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/ifs/fat32a.c

    r287 r289  
    60316031         pNew1->u.File.ulLastModifiedTimestp.month = pGI->month;
    60326032         pNew1->u.File.ulLastModifiedTimestp.day = pGI->day;
    6033          pNew1->u.File.ulLastModifiedTimestp.hour = pGI->day;
     6033         pNew1->u.File.ulLastModifiedTimestp.hour = pGI->hour;
    60346034         pNew1->u.File.ulLastModifiedTimestp.minutes = pGI->minutes;
    60356035         pNew1->u.File.ulLastModifiedTimestp.seconds = pGI->seconds;
  • TabularUnified trunk/src/ifs/ifsfile.c

    r286 r289  
    12491249PBYTE  pbCluster;
    12501250ULONG  ulClusterSector;
    1251 USHORT usClusterOffset;
     1251ULONG  ulClusterOffset;
    12521252USHORT usBlockOffset;
    12531253ULONG  ulBytesPerCluster;
     
    15181518        ulBytesPerBlock   = pVolInfo->ulBlockSize;
    15191519#ifdef INCL_LONGLONG
    1520         usClusterOffset   = (USHORT)(pos % ulBytesPerCluster); /* get remainder */
     1520        ulClusterOffset   = (ULONG)(pos % ulBytesPerCluster); /* get remainder */
    15211521        usBlockOffset     = (USHORT)(pos % ulBytesPerBlock);   /* get remainder */
    15221522#else
     
    15251525
    15261526        llRes = iModUL(pos, ulBytesPerCluster);
    1527         usClusterOffset = (USHORT)llRes.ulLo;
     1527        ulClusterOffset = (ULONG)llRes.ulLo;
    15281528        llRes = iModUL(pos, ulBytesPerBlock);
    15291529        usBlockOffset   = (USHORT)llRes.ulLo;
     
    15891589            }
    15901590
    1591             if (((ULONG)usClusterOffset + ulCurrBytesToRead) >= ulBytesPerCluster)
     1591            if (ulClusterOffset + ulCurrBytesToRead >= ulBytesPerCluster)
    15921592            {
    15931593                pOpenInfo->ulCurCluster     = GetNextCluster(pVolInfo, pOpenInfo->pSHInfo, pOpenInfo->ulCurCluster);
     
    18701870PBYTE  pbCluster;
    18711871ULONG  ulClusterSector;
    1872 USHORT usClusterOffset;
     1872ULONG  ulClusterOffset;
    18731873USHORT usBlockOffset;
    18741874ULONG  ulBytesPerCluster;
     
    22992299        ulBytesPerBlock   = pVolInfo->ulBlockSize;
    23002300#ifdef INCL_LONGLONG
    2301         usClusterOffset   = (USHORT)(pos % ulBytesPerCluster); /* get remainder */
     2301        ulClusterOffset   = (ULONG)(pos % ulBytesPerCluster); /* get remainder */
    23022302        usBlockOffset     = (USHORT)(pos % ulBytesPerBlock);   /* get remainder */
    23032303#else
     
    23062306
    23072307        llRes = iModUL(pos, ulBytesPerCluster);
    2308         usClusterOffset   = (USHORT)llRes.ulLo;
     2308        ulClusterOffset   = (ULONG)llRes.ulLo;
    23092309        llRes = iModUL(pos, ulBytesPerBlock);
    23102310        usBlockOffset     = (USHORT)llRes.ulLo;
     
    23762376            }
    23772377
    2378             if (((ULONG)usClusterOffset + ulCurrBytesToWrite) >= ulBytesPerCluster)
     2378            if (ulClusterOffset + ulCurrBytesToWrite >= ulBytesPerCluster)
    23792379            {
    23802380                pOpenInfo->ulCurCluster     = GetNextCluster(pVolInfo, pOpenInfo->pSHInfo, pOpenInfo->ulCurCluster);
  • TabularUnified trunk/src/include/fat32c.h

    r282 r289  
    259259ULONG query_vol_label(char *path, char *pszVolLabel, int cbVolLabel);
    260260void set_datetime(DIRENTRY *pDir);
     261void set_datetime1(DIRENTRY1 *pDir);
    261262char *get_error(USHORT rc);
    262263void query_current_disk(char *pszDrive);
  • TabularUnified trunk/src/ufat32/fatfunc.c

    r286 r289  
    9494
    9595void set_datetime(DIRENTRY *pDir);
     96void set_datetime1(DIRENTRY1 *pDir);
    9697
    9798/******************************************************************
     
    16751676            return ERROR_FILE_EXISTS;
    16761677            }
     1678         set_datetime1(&DirNew);
    16771679         memcpy(pNew, &DirNew, sizeof (DIRENTRY));
    16781680
     
    18431845                     //   Message(" Updating cluster");
    18441846                     memcpy(pWorkFile, pNew, sizeof (DIRENTRY1));
     1847                     set_datetime1(pWorkFile);
    18451848                     if (pStreamNew)
    18461849                        {
     
    33633366      memcpy(DirEntry.bExtention, szFileName + 6, 3);
    33643367
    3365    set_datetime(&DirEntry);
     3368
     3369#ifdef EXFAT
     3370   if (pCD->bFatType < FAT_TYPE_EXFAT)
     3371#endif
     3372      set_datetime(&DirEntry);
     3373#ifdef EXFAT
     3374   else
     3375      set_datetime1((PDIRENTRY1)&DirEntry);
     3376#endif
     3377
    33663378   if (!ulDirCluster)
    33673379      ulDirCluster = MakeDir(pCD, pCD->BootSect.bpb.RootDirStrtClus, &DirEntry, szFileName);
     
    34023414      strncpy(pData, szFileName, cbData);
    34033415
    3404    set_datetime(&DirEntry);
     3416#ifdef EXFAT
     3417   if (pCD->bFatType < FAT_TYPE_EXFAT)
     3418#endif
     3419      set_datetime(&DirEntry);
     3420#ifdef EXFAT
     3421   else
     3422      set_datetime1((PDIRENTRY1)&DirEntry);
     3423#endif
    34053424
    34063425#ifdef EXFAT
     
    34553474                    PDIRENTRY pNew, PDIRENTRY1 pNewStream, PSZ pszName)
    34563475{
     3476#ifdef EXFAT
     3477   if (pCD->bFatType < FAT_TYPE_EXFAT)
     3478      {
     3479#endif
     3480      set_datetime(pNew);
     3481#ifdef EXFAT
     3482      }
     3483   else
     3484      {
     3485      set_datetime1((PDIRENTRY1)pNew);
     3486      }
     3487#endif
     3488
    34573489   return ModifyDirectory(pCD, ulDirCluster, pDirSHInfo, MODIFY_DIR_INSERT,
    34583490      NULL, pNew, NULL, pNewStream, pszName);
  • TabularUnified trunk/src/ufat32/format.c

    r288 r289  
    196196#ifdef EXFAT
    197197    case FAT_TYPE_EXFAT:
    198         // 7 MB to 256 MB - 4 KB
    199         if ( DiskSizeMB > 7 )
     198        // 256 MB to 512 MB - 1 KB
     199        if ( DiskSizeMB > 256 )
     200            ret = get_spc( 1, BytesPerSect );  // ret = 0x2;
     201
     202        // 512 MB to 1,024 MB - 2 KB
     203        if ( DiskSizeMB > 512 )
     204            ret = get_spc( 2, BytesPerSect );  // ret = 0x4;
     205
     206        // 1,024 MB to 2,048 MB - 4 KB
     207        if ( DiskSizeMB > 1024 )
    200208            ret = get_spc( 4, BytesPerSect );  // ret = 0x8;
    201209
    202         // 256 MB to 1,024 MB - 32 KB
    203         if ( DiskSizeMB > 256 )
     210        // 2,048 MB to 4,096 MB - 8 KB
     211        if ( DiskSizeMB > 2048 )
     212            ret = get_spc( 8, BytesPerSect );  // ret = 0x10;
     213
     214        // 4,096 MB to 8,192 MB - 16 KB
     215        if ( DiskSizeMB > 4096 )
     216            ret = get_spc( 16, BytesPerSect );  // ret = 0x20;
     217
     218        // 8,192 MB to 16,384 MB - 32 KB
     219        if ( DiskSizeMB > 8192 )
    204220            ret = get_spc( 32, BytesPerSect );  // ret = 0x40;
     221
     222        // 16,384 MB to 32,768 MB - 64 KB
     223        if ( DiskSizeMB > 16384 )
     224            ret = get_spc( 64, BytesPerSect );  // ret = 0x80;
    205225
    206226        // Larger than 32,784 MB - 128 KB
    207227        if ( DiskSizeMB > 32784 )
    208             ret = get_spc( 128, BytesPerSect );  // ret = 0x80;
     228            ret = get_spc( 128, BytesPerSect );  // ret = 0x100;
    209229#endif
    210230    }
     
    382402    FAT_FSINFO *pFAT32FsInfo;
    383403    DWORD *pFirstSectOfFat;
     404    DWORD FatSize;
    384405
    385406#ifdef EXFAT
     
    466487        dp.SectorsPerCluster = get_sectors_per_cluster( params, ((LONGLONG)dp.TotalSectors) * dp.BytesPerSect, dp.BytesPerSect );
    467488
    468     dp.FatSize = get_fat_size_sectors ( params, dp.TotalSectors,
    469         dp.ReservedSectCount, dp.SectorsPerCluster,
     489    FatSize = get_fat_size_sectors ( params, dp.TotalSectors,
     490        dp.ReservedSectCount, params->sectors_per_cluster,
    470491        dp.NumFATs, dp.BytesPerSect );
    471492
    472     UserAreaSize = dp.TotalSectors - dp.ReservedSectCount - (dp.NumFATs*dp.FatSize);
     493    UserAreaSize = dp.TotalSectors - dp.ReservedSectCount - ((DWORD)dp.NumFATs*FatSize);
    473494
    474495    if (params->bFatType < FAT_TYPE_FAT32)
    475496        // root dir is excluded from user area on FAT12/FAT16
    476         UserAreaSize -= dp.SectorsPerCluster;
    477 
    478     ClusterCount = UserAreaSize / dp.SectorsPerCluster;
     497        UserAreaSize -= params->sectors_per_cluster; // ???!
     498
     499    ClusterCount = UserAreaSize / params->sectors_per_cluster;
    479500
    480501    if ( (ClusterCount >= FAT12_BAD_CLUSTER && params->bFatType == FAT_TYPE_FAT12) ||
     
    542563    FatNeeded /= dp.BytesPerSect;
    543564
    544     if ( FatNeeded > dp.FatSize )
     565    if ( FatNeeded > FatSize )
    545566    {
    546567        die ( "This drive is too big for this version\n"
     
    606627        pFATBootSect->wBytsPerSec = (WORD) dp.BytesPerSect;
    607628
    608         pFATBootSect->bSecPerClus = (BYTE) dp.SectorsPerCluster;
     629        pFATBootSect->bSecPerClus = (BYTE) params->sectors_per_cluster;
    609630        pFATBootSect->wRsvdSecCnt = (WORD) dp.ReservedSectCount;
    610631        pFATBootSect->bNumFATs = (BYTE) dp.NumFATs;
    611         pFATBootSect->wRootEntCnt = (dp.SectorsPerCluster * dp.BytesPerSect) /
     632        pFATBootSect->wRootEntCnt = (params->sectors_per_cluster * dp.BytesPerSect) /
    612633            sizeof(DIRENTRY); // number of dir entries per cluster
    613634
     
    618639
    619640        pFATBootSect->bMedia = 0xF8;
    620         pFATBootSect->wFATSz16 = dp.FatSize;
     641        pFATBootSect->wFATSz16 = (WORD)FatSize;
    621642        pFATBootSect->wSecPerTrk = (WORD) dp.SectorsPerTrack;
    622643        pFATBootSect->wNumHeads = (WORD) dp.TracksPerCylinder;
     
    653674        pFAT32BootSect->wBytsPerSec = (WORD) dp.BytesPerSect;
    654675
    655         pFAT32BootSect->bSecPerClus = (BYTE) dp.SectorsPerCluster;
     676        pFAT32BootSect->bSecPerClus = (BYTE) params->sectors_per_cluster;
    656677        pFAT32BootSect->wRsvdSecCnt = (WORD) dp.ReservedSectCount;
    657678        pFAT32BootSect->bNumFATs = (BYTE) dp.NumFATs;
     
    666687        pFAT32BootSect->dTotSec32 = dp.TotalSectors;
    667688   
    668         pFAT32BootSect->dFATSz32 = dp.FatSize;
     689        pFAT32BootSect->dFATSz32 = (WORD)FatSize;
    669690        pFAT32BootSect->wExtFlags = 0;
    670691        pFAT32BootSect->wFSVer = 0;
     
    687708    {
    688709        USHORT usSectorSize  = (USHORT)dp.BytesPerSect;
    689         USHORT usClusterSize = (USHORT)dp.SectorsPerCluster;
     710        USHORT usClusterSize = (USHORT)params->sectors_per_cluster;
    690711
    691712        // fill out the boot sector and fs info
     
    698719        pEXFATBootSect->ullVolumeLength = (ULONGLONG)dp.TotalSectors;
    699720        pEXFATBootSect->ulFatOffset = (WORD) dp.ReservedSectCount;
    700         pEXFATBootSect->ulFatLength = dp.FatSize;
     721        pEXFATBootSect->ulFatLength = FatSize;
    701722        pEXFATBootSect->ulClusterHeapOffset = pEXFATBootSect->ulFatOffset + pEXFATBootSect->ulFatLength;
    702         pEXFATBootSect->ulClusterCount = (ULONG)((dp.TotalSectors - dp.FatSize
    703             - dp.ReservedSectCount) / dp.SectorsPerCluster);
     723        pEXFATBootSect->ulClusterCount = (ULONG)((dp.TotalSectors - FatSize
     724            - dp.ReservedSectCount) / params->sectors_per_cluster);
    704725        ulExfatBitmapLen = (pEXFATBootSect->ulClusterCount / 8) +
    705726           (pEXFATBootSect->ulClusterCount % 8 ? 1 : 0);
    706         ulExfatBitmapClusters = ulExfatBitmapLen / (dp.SectorsPerCluster * dp.BytesPerSect);
    707         ulExfatBitmapClusters = (ulExfatBitmapLen % (dp.SectorsPerCluster * dp.BytesPerSect)) ?
     727        ulExfatBitmapClusters = ulExfatBitmapLen / (params->sectors_per_cluster * dp.BytesPerSect);
     728        ulExfatBitmapClusters = (ulExfatBitmapLen % (params->sectors_per_cluster * dp.BytesPerSect)) ?
    708729            ulExfatBitmapClusters + 1 : ulExfatBitmapClusters;
    709730        ulExfatUpCaseLen = sizeof(pUpCase);
    710         ulExfatUpCaseClusters = ulExfatUpCaseLen / (dp.SectorsPerCluster * dp.BytesPerSect);
    711         ulExfatUpCaseClusters = (ulExfatUpCaseLen % (dp.SectorsPerCluster * dp.BytesPerSect)) ?
     731        ulExfatUpCaseClusters = ulExfatUpCaseLen / (params->sectors_per_cluster * dp.BytesPerSect);
     732        ulExfatUpCaseClusters = (ulExfatUpCaseLen % (params->sectors_per_cluster * dp.BytesPerSect)) ?
    712733            ulExfatUpCaseClusters + 1 : ulExfatUpCaseClusters;
    713734        pEXFATBootSect->RootDirStrtClus = 2 + ulExfatBitmapClusters + ulExfatUpCaseClusters;
     
    741762        pEXFATBootSect->usBootSig = 0xaa55;
    742763
    743         mem_alloc ( (void **)&pBitmap,  ulExfatBitmapClusters * dp.SectorsPerCluster * dp.BytesPerSect);
     764        mem_alloc ( (void **)&pBitmap,  ulExfatBitmapClusters * params->sectors_per_cluster * dp.BytesPerSect);
    744765
    745766        if ( !pBitmap )
    746767             die ( "Failed to allocate memory", -2 );
    747768
    748         mem_alloc ( (void **)&pRootDir,  dp.SectorsPerCluster * dp.BytesPerSect);
     769        mem_alloc ( (void **)&pRootDir,  params->sectors_per_cluster * dp.BytesPerSect);
    749770
    750771        if ( !pRootDir )
    751772             die ( "Failed to allocate memory", -2 );
    752773
    753         mem_alloc ( (void **)&pUpCaseTbl,  ulExfatUpCaseClusters * dp.SectorsPerCluster * dp.BytesPerSect);
     774        mem_alloc ( (void **)&pUpCaseTbl,  ulExfatUpCaseClusters * params->sectors_per_cluster * dp.BytesPerSect);
    754775
    755776        if ( !pRootDir )
     
    797818        pFirstSectOfFat[2] = 0x0fffffff;  // end of cluster chain for root dir
    798819    }
    799 #ifdef EXFAT
    800     else if (params->bFatType == FAT_TYPE_EXFAT)
    801     {
    802         pFirstSectOfFat[0] = 0xfffffff8;  // Reserved cluster 1 media id in low byte
    803         pFirstSectOfFat[1] = 0xffffffff;  // Reserved cluster 2 EOC
    804 
    805         for (i = 0; i < ulExfatBitmapClusters - 1; i++)
    806         {
    807             // next cluster for alloc bitmap
    808             pFirstSectOfFat[2 + i] = 3 + i;
    809         }
    810         // end of cluster chain for alloc bitmap
    811         pFirstSectOfFat[2 + i++] = 0xffffffff;
    812 
    813         for (i = 0; i < ulExfatUpCaseClusters - 1; i++)
    814         {
    815             // next cluster for upcase table
    816             pFirstSectOfFat[2 + ulExfatBitmapClusters + i] = 3 + ulExfatBitmapClusters + i;
    817         }
    818         // end of cluster chain for upcase table
    819         pFirstSectOfFat[2 + ulExfatBitmapClusters + i++] = 0xffffffff;
    820 
    821         // root dir
    822         pFirstSectOfFat[2 + ulExfatBitmapClusters + i++] = 0xffffffff;
    823     }
    824 #endif
    825820
    826821    // Write boot sector, fats
     
    842837    // Now we're commited - print some info first
    843838    show_message ( "Size: %g MB %u sectors.\n", 0, 0, 2, (double) ((dp.TotalSectors / (1024*1024)) * dp.BytesPerSect), dp.TotalSectors );
    844     show_message ( "%d Bytes Per Sector, Cluster size %d bytes.\n", 0, 0, 2, dp.BytesPerSect, dp.SectorsPerCluster * dp.BytesPerSect );
     839    show_message ( "%d Bytes Per Sector, Cluster size %d bytes.\n", 0, 0, 2, dp.BytesPerSect, params->sectors_per_cluster * dp.BytesPerSect );
    845840
    846841    show_message ( "Volume label is %1.\n", 0, 1375, 1, TYPE_STRING, vol );
     
    848843    show_message ( "The Volume Serial Number is %1.\n", 0, 1243, 1, TYPE_STRING, szString);
    849844
    850     show_message ( "%d Reserved Sectors, %d Sectors per FAT, %d fats.\n", 0, 0, 3, dp.ReservedSectCount, dp.FatSize, dp.NumFATs );
     845    show_message ( "%d Reserved Sectors, %lu Sectors per FAT, %d fats.\n", 0, 0, 3, dp.ReservedSectCount, FatSize, dp.NumFATs );
    851846
    852847    // Work out the Cluster count
     
    856851   
    857852    // fix up the FSInfo sector
    858     pFAT32FsInfo->dFree_Count = (UserAreaSize/dp.SectorsPerCluster)-1;
     853    pFAT32FsInfo->dFree_Count = (UserAreaSize/params->sectors_per_cluster)-1;
    859854    pFAT32FsInfo->dNxt_Free = 3; // clusters 0-1 resered, we used cluster 2 for the root dir
    860855
    861     sprintf(szString, "%lu", (pFAT32FsInfo->dFree_Count / 1024) * (dp.SectorsPerCluster * dp.BytesPerSect));
     856    sprintf(szString, "%lu", (pFAT32FsInfo->dFree_Count / 1024) * (params->sectors_per_cluster * dp.BytesPerSect));
    862857    show_message ( "%1 kilobytes are available.\n", 0, 537, 1, TYPE_STRING, szString);
    863858
     
    870865
    871866    // First zero out ReservedSect + FatSize * NumFats + SectorsPerCluster
    872     SystemAreaSize = (dp.ReservedSectCount+(dp.NumFATs*dp.FatSize) + dp.SectorsPerCluster);
     867    SystemAreaSize = (dp.ReservedSectCount+((DWORD)dp.NumFATs*FatSize) + params->sectors_per_cluster);
    873868
    874869#ifdef EXFAT
     
    935930#endif
    936931
    937     // Write the first fat sector in the right places
    938     for ( i=0; i<dp.NumFATs; i++ )
    939     {
    940         int SectorStart = dp.ReservedSectCount + (i * dp.FatSize );
    941         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pFirstSectOfFat, 1 );
    942     }
     932#ifdef EXFAT
     933    if (params->bFatType < FAT_TYPE_EXFAT)
     934    {
     935#endif
     936       // Write the first fat sector in the right places
     937       for ( i = 0; i < dp.NumFATs; i++ )
     938       {
     939          int SectorStart = dp.ReservedSectCount + (i * FatSize );
     940          write_sect ( hDevice, SectorStart, dp.BytesPerSect, pFirstSectOfFat, 1 );
     941       }
     942#ifdef EXFAT
     943    }
     944   else
     945   {
     946      int j;
     947
     948      for ( j = 0; j < dp.NumFATs; j++ )
     949      {
     950         int SectorStart = dp.ReservedSectCount + (j * FatSize);
     951         int EntriesPerSec = dp.BytesPerSect / 4;
     952
     953         pFirstSectOfFat[0] = 0xfffffff8;  // Reserved cluster 1 media id in low byte
     954         pFirstSectOfFat[1] = 0xffffffff;  // Reserved cluster 2 EOC
     955
     956         for (i = 2; i < ulExfatBitmapClusters + 2; i++)
     957         {
     958            if (!(i % EntriesPerSec))
     959            {
     960               // next sector
     961               if (i / EntriesPerSec)
     962               {
     963                  // write previous sector
     964                  write_sect ( hDevice,
     965                               SectorStart + (i / EntriesPerSec - 1),
     966                               dp.BytesPerSect,
     967                               pFirstSectOfFat,
     968                               1 );
     969               }
     970               memset(pFirstSectOfFat, 0, dp.BytesPerSect);
     971            }
     972
     973            if (i == ulExfatBitmapClusters + 1)
     974            {
     975               // end of cluster chain for alloc bitmap
     976               pFirstSectOfFat[i % EntriesPerSec] = 0xffffffff;
     977            }
     978            else
     979               // next cluster for alloc bitmap
     980               pFirstSectOfFat[i % EntriesPerSec] = i + 1;
     981         }
     982
     983         for (i = 0; i < ulExfatUpCaseClusters; i++)
     984         {
     985            int k = 2 + ulExfatBitmapClusters + i;
     986
     987            if (!(k % EntriesPerSec))
     988            {
     989               // next sector
     990               if (k / EntriesPerSec)
     991               {
     992                  write_sect ( hDevice,
     993                               SectorStart + (k / EntriesPerSec - 1),
     994                               dp.BytesPerSect,
     995                               pFirstSectOfFat,
     996                               1 );
     997               }
     998               memset(pFirstSectOfFat, 0, dp.BytesPerSect);
     999            }
     1000
     1001            if (i == ulExfatUpCaseClusters - 1)
     1002            {
     1003               // end of cluster chain for alloc bitmap
     1004               pFirstSectOfFat[k % EntriesPerSec] = 0xffffffff;
     1005            }
     1006            else
     1007               // next cluster for alloc bitmap
     1008               pFirstSectOfFat[k % EntriesPerSec] = k + 1;
     1009         }
     1010
     1011         // root dir
     1012         pFirstSectOfFat[(2 + ulExfatBitmapClusters + ulExfatUpCaseClusters) % EntriesPerSec] = 0xffffffff;
     1013
     1014         // write last sector
     1015         write_sect ( hDevice,
     1016                      SectorStart + ((2 + ulExfatBitmapClusters + ulExfatUpCaseClusters) / EntriesPerSec),
     1017                      dp.BytesPerSect,
     1018                      pFirstSectOfFat,
     1019                      1 );
     1020      }
     1021   }
     1022#endif
    9431023
    9441024#ifdef EXFAT
     
    9501030
    9511031        // write bitmap
    952         memset( pBitmap, 0, ulExfatBitmapClusters * dp.SectorsPerCluster * dp.BytesPerSect );
     1032        memset( pBitmap, 0, ulExfatBitmapClusters * params->sectors_per_cluster * dp.BytesPerSect );
    9531033        // bitmap clusters
    9541034        for ( i = 0; i < ulExfatBitmapClusters; i++)
     
    9631043        // root dir cluster
    9641044        SetBmpEntry2(pBitmap, &dp, 2 + ulExfatBitmapClusters + i, 1);
    965         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pBitmap, ulExfatBitmapClusters * dp.SectorsPerCluster );
     1045        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pBitmap, ulExfatBitmapClusters * params->sectors_per_cluster );
    9661046
    9671047        // write upcase table
    968         memset( pUpCaseTbl, 0, ulExfatUpCaseClusters * dp.SectorsPerCluster * dp.BytesPerSect );
     1048        memset( pUpCaseTbl, 0, ulExfatUpCaseClusters * params->sectors_per_cluster * dp.BytesPerSect );
    9691049        memcpy( pUpCaseTbl, pUpCase, ulExfatUpCaseLen );
    970         SectorStart += ulExfatBitmapClusters * dp.SectorsPerCluster;
    971         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pUpCaseTbl, ulExfatUpCaseClusters * dp.SectorsPerCluster );
     1050        SectorStart += ulExfatBitmapClusters * params->sectors_per_cluster;
     1051        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pUpCaseTbl, ulExfatUpCaseClusters * params->sectors_per_cluster );
    9721052
    9731053        // write root dir
    974         memset( pRootDir, 0, dp.SectorsPerCluster * dp.BytesPerSect );
     1054        memset( pRootDir, 0, params->sectors_per_cluster * dp.BytesPerSect );
    9751055        // volume label
    9761056        pDir->bEntryType = ENTRY_TYPE_VOLUME_LABEL;
     
    9891069        pDir->u.UpCaseTbl.ulTblCheckSum = GetChkSum2((char *)pUpCase, ulExfatUpCaseLen);
    9901070        //
    991         SectorStart += ulExfatUpCaseClusters * dp.SectorsPerCluster;
    992         write_sect ( hDevice, SectorStart, dp.BytesPerSect, pRootDir, dp.SectorsPerCluster );
     1071        SectorStart += ulExfatUpCaseClusters * params->sectors_per_cluster;
     1072        write_sect ( hDevice, SectorStart, dp.BytesPerSect, pRootDir, params->sectors_per_cluster );
    9931073    }
    9941074#endif
     
    10561136    {
    10571137        mem_free ( (void *)pEXFATBootSect, dp.BytesPerSect );
    1058         mem_free ( (void *)pBitmap,  dp.SectorsPerCluster * dp.BytesPerSect );
    1059         mem_free ( (void *)pRootDir, dp.SectorsPerCluster * dp.BytesPerSect );
     1138        mem_free ( (void *)pBitmap,  params->sectors_per_cluster * dp.BytesPerSect );
     1139        mem_free ( (void *)pRootDir, params->sectors_per_cluster * dp.BytesPerSect );
    10601140    }
    10611141#endif
     
    12471327        case 'C':
    12481328                p.sectors_per_cluster = atol(val);
    1249                 if (  (p.sectors_per_cluster != 1) &&  // 512 bytes, 0.5k
    1250                    (p.sectors_per_cluster != 2)    &&  // 1K
    1251                    (p.sectors_per_cluster != 4)    &&  // 2K
    1252                    (p.sectors_per_cluster != 8)    &&  // 4K
    1253                    (p.sectors_per_cluster != 16)   &&  // 8K
    1254                    (p.sectors_per_cluster != 32)   &&  // 16K
    1255                    (p.sectors_per_cluster != 64)   &&  // 32K
    1256                    (p.sectors_per_cluster != 128)      // 64K ( Microsoft say don't use 64K or bigger);               
    1257                    )
    1258                 {
    1259                     show_message ( "Ignoring bad cluster size %d\n", 0, 0, 1, p.sectors_per_cluster );
    1260                     p.sectors_per_cluster = 0;
    1261                     usage( argv[0] );
    1262                 }
     1329                if (p.bFatType < FAT_TYPE_EXFAT)
     1330                   {
     1331                   if (  (p.sectors_per_cluster != 1) &&  // 512 bytes, 0.5k
     1332                      (p.sectors_per_cluster != 2)    &&  // 1K
     1333                      (p.sectors_per_cluster != 4)    &&  // 2K
     1334                      (p.sectors_per_cluster != 8)    &&  // 4K
     1335                      (p.sectors_per_cluster != 16)   &&  // 8K
     1336                      (p.sectors_per_cluster != 32)   &&  // 16K
     1337                      (p.sectors_per_cluster != 64)   &&  // 32K
     1338                      (p.sectors_per_cluster != 128)      // 64K ( Microsoft say don't use 64K or bigger);
     1339                      )
     1340                      {
     1341                      show_message ( "Ignoring bad cluster size %d\n", 0, 0, 1, p.sectors_per_cluster );
     1342                      p.sectors_per_cluster = 0;
     1343                      usage( argv[0] );
     1344                      }
     1345                   }
    12631346                continue;
    12641347        case 'R':
  • TabularUnified trunk/src/ufat32/os2.c

    r282 r289  
    678678void set_datetime(DIRENTRY *pDir)
    679679{
     680   // FAT12/FAT16/FAT32
    680681   DATETIME datetime;
    681682
     
    692693   pDir->wCreateTime = pDir->wLastWriteTime;
    693694   pDir->wAccessDate = pDir->wLastWriteDate;
     695}
     696
     697void set_datetime1(DIRENTRY1 *pDir)
     698{
     699   // exFAT
     700   DATETIME datetime;
     701
     702   DosGetDateTime(&datetime);
     703
     704   pDir->u.File.ulLastModifiedTimestp.year = datetime.year - 1980;
     705   pDir->u.File.ulLastModifiedTimestp.month = datetime.month;
     706   pDir->u.File.ulLastModifiedTimestp.day = datetime.day;
     707   pDir->u.File.ulLastModifiedTimestp.hour = datetime.hours;
     708   pDir->u.File.ulLastModifiedTimestp.minutes = datetime.minutes;
     709   pDir->u.File.ulLastModifiedTimestp.seconds = datetime.seconds;
     710
     711   pDir->u.File.ulCreateTimestp = pDir->u.File.ulLastModifiedTimestp;
     712   pDir->u.File.ulLastAccessedTimestp = pDir->u.File.ulLastModifiedTimestp;
    694713}
    695714
  • TabularUnified trunk/src/ufat32/win32.c

    r282 r289  
    378378void set_datetime(DIRENTRY *pDir)
    379379{
     380    // FAT12/FAT16/FAT32
    380381    SYSTEMTIME datetime;
    381382
     
    394395}
    395396
     397
     398void set_datetime1(DIRENTRY1 *pDir)
     399{
     400   // exFAT
     401   SYSTEMTIME datetime;
     402
     403   GetSystemTime(&datetime);
     404
     405   pDir->u.File.ulLastModifiedTimestp.year = datetime.wYear - 1980;
     406   pDir->u.File.ulLastModifiedTimestp.month = datetime.wMonth;
     407   pDir->u.File.ulLastModifiedTimestp.day = datetime.wDay;
     408   pDir->u.File.ulLastModifiedTimestp.hour = datetime.wHour;
     409   pDir->u.File.ulLastModifiedTimestp.minutes = datetime.wMinute;
     410   pDir->u.File.ulLastModifiedTimestp.seconds = datetime.wSecond / 2;
     411
     412   pDir->u.File.ulCreateTimestp = pDir->u.File.ulLastModifiedTimestp;
     413   pDir->u.File.ulLastAccessedTimestp = pDir->u.File.ulLastModifiedTimestp;
     414}
    396415
    397416char *get_error(USHORT rc)
Note: See TracChangeset for help on using the changeset viewer.