Changeset 1229 for trunk/eraser6


Ignore:
Timestamp:
9/30/2009 4:52:22 AM (5 years ago)
Author:
lowjoel
Message:

-Fixed the calculation of cluster positions in FAT12 and FAT16 (used sectors per cluster instead of sector size)
-Standardise the input of the DirectoryToCluster? function, volume root is "", subfolder level 1 is "\Subfolder" so process the input string properly
-Fixed multi-level path parsing (index-off-by-one)
-Apparently, in the directory list certain LFNs may be interrupted by deleted entries, handle those.
-Fixed directory corruption when clearing deleted entries -- insufficient data was coped (I used the wrong sizeof operator -- it was using the old type which was changed earlier)

Location:
trunk/eraser6/Eraser.Util.FileSystem
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.Util.FileSystem/Fat12Or16Api.cpp

    r1228 r1229  
    6666    long long Fat12Or16Api::ClusterToOffset(unsigned cluster) 
    6767    { 
    68         unsigned long long sector = BootSector->ReservedSectorCount +                                           //Reserved area 
    69             BootSector->FatCount * BootSector->SectorsPerFat +                                                  //FAT area 
    70             (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / (ClusterSize / SectorSize)) +  //Root directory area 
     68        unsigned long long sector = BootSector->ReservedSectorCount +                           //Reserved area 
     69            BootSector->FatCount * BootSector->SectorsPerFat +                                  //FAT area 
     70            (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / SectorSize) +  //Root directory area 
    7171            (static_cast<unsigned long long>(cluster) - 2) * (ClusterSize / SectorSize); 
    7272        return SectorToOffset(sector); 
     
    7676    { 
    7777        //The path must start with a backslash as it must be volume-relative. 
    78         if (path->Length != 0 && path[0] != L'\\') 
    79             throw gcnew ArgumentException(L"The path provided is not volume relative. " + 
    80                 gcnew String(L"Volume relative paths must begin with a backslash.")); 
     78        if (path->Length != 0) 
     79        { 
     80            if (path[0] != L'\\') 
     81                throw gcnew ArgumentException(L"The path provided is not volume relative. " + 
     82                    gcnew String(L"Volume relative paths must begin with a backslash.")); 
     83            path = path->Remove(0, 1); 
     84        } 
    8185 
    8286        //Chop the path into it's constituent directory components 
     
    8690        //Traverse the directories until we get the cluster we want. 
    8791        unsigned cluster = 0; 
    88         FatDirectoryBase^ parentDir = gcnew RootDirectory(this); 
     92        FatDirectoryBase^ parentDir = nullptr; 
    8993        for each (String^ component in components) 
    9094        { 
     
    9296                break; 
    9397 
    94             parentDir = LoadDirectory(cluster, parentDir == nullptr ? nullptr : parentDir->Name, 
     98            parentDir = LoadDirectory(cluster, parentDir == nullptr ? String::Empty : parentDir->Name, 
    9599                parentDir); 
    96100            cluster = parentDir->Items[component]->Cluster; 
     
    105109            BootSector->SectorCount32 : BootSector->SectorCount16); 
    106110        unsigned long long availableSectors = numberOfSectors - ( 
    107             BootSector->ReservedSectorCount +                                                                   //Reserved area 
    108             BootSector->FatCount * BootSector->SectorsPerFat +                                                  //FAT area 
    109             (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / (ClusterSize / SectorSize))    //Root directory area 
     111            BootSector->ReservedSectorCount +                                                   //Reserved area 
     112            BootSector->FatCount * BootSector->SectorsPerFat +                                  //FAT area 
     113            (BootSector->RootDirectoryEntryCount * sizeof(::FatDirectoryEntry) / SectorSize)    //Root directory area 
    110114        ); 
    111115        unsigned long long numberOfClusters = availableSectors / (ClusterSize / SectorSize); 
  • trunk/eraser6/Eraser.Util.FileSystem/Fat32Api.cpp

    r1226 r1229  
    114114    { 
    115115        //The path must start with a backslash as it must be volume-relative. 
    116         if (path->Length != 0 && path[0] != L'\\') 
    117             throw gcnew ArgumentException(L"The path provided is not volume relative. " + 
    118                 gcnew String(L"Volume relative paths must begin with a backslash.")); 
     116        if (path->Length != 0) 
     117        { 
     118            if (path[0] != L'\\') 
     119                throw gcnew ArgumentException(L"The path provided is not volume relative. " + 
     120                    gcnew String(L"Volume relative paths must begin with a backslash.")); 
     121            path = path->Remove(0, 1); 
     122        } 
    119123 
    120124        //Chop the path into it's constituent directory components 
     
    130134                break; 
    131135 
    132             parentDir = LoadDirectory(cluster, parentDir == nullptr ? nullptr : parentDir->Name, 
     136            parentDir = LoadDirectory(cluster, parentDir == nullptr ? String::Empty : parentDir->Name, 
    133137                parentDir); 
    134138            cluster = parentDir->Items[component]->Cluster; 
  • trunk/eraser6/Eraser.Util.FileSystem/FatApi.cpp

    r1226 r1229  
    8484        int lastIndex = directory->LastIndexOfAny(pathSeparators); 
    8585        return LoadDirectory(DirectoryToCluster(directory), directory->Substring(lastIndex + 1), 
    86             LoadDirectory(directory->Substring(0, lastIndex == 0 ? 0 : lastIndex - 1))); 
     86            LoadDirectory(directory->Substring(0, lastIndex))); 
    8787    } 
    8888 
     
    200200                for (unsigned char sequence = 0; i->Short.Attributes == 0x0F; ++i) 
    201201                { 
    202                     if (!(i->LongFileName.Sequence & 0x40)) //Second entry onwards 
     202                    if (static_cast<unsigned char>(i->Short.Name[0]) == 0xE5) 
     203                        continue; 
     204                    else if (!(i->LongFileName.Sequence & 0x40)) //Second entry onwards 
    203205                    { 
    204206                        //Check that the checksum of the file name is the same as the previous 
     
    226228                    validEntries.insert(validEntries.end(), longFileNameBegin, i); 
    227229                } 
     230                else 
     231                { 
     232                    --i; 
     233                    continue; 
     234                } 
    228235            } 
    229236 
     
    234241        //the memory used. 
    235242        memset(Directory, 0, DirectorySize * sizeof(::FatDirectoryEntry)); 
    236         memcpy(Directory, &validEntries.front(), validEntries.size() * sizeof(::FatDirectory)); 
     243        memcpy(Directory, &validEntries.front(), validEntries.size() * sizeof(::FatDirectoryEntry)); 
    237244 
    238245        //Write the entries to disk 
     
    262269                for (unsigned char sequence = 0; i->Short.Attributes == 0x0F; ++i) 
    263270                { 
    264                     if (!(i->LongFileName.Sequence & 0x40)) //Second entry onwards 
     271                    if (static_cast<unsigned char>(i->Short.Name[0]) == 0xE5) 
     272                        continue; 
     273                    else if (!(i->LongFileName.Sequence & 0x40)) //Second entry onwards 
    265274                    { 
    266275                        //Check that the checksum of the file name is the same as the previous 
     
    273282                            throw gcnew ArgumentException(L"Invalid directory entry."); 
    274283                    } 
     284                    else 
     285                        longFileName.clear(); 
    275286                     
    276287                    sequence = i->LongFileName.Sequence & ~0x40; 
     
    297308                            FatDirectoryEntryTypes::Directory : FatDirectoryEntryTypes::File, 
    298309                        GetStartCluster(*i))); 
     310                } 
     311                else 
     312                { 
     313                    --i; 
     314                    continue; 
    299315                } 
    300316            } 
Note: See TracChangeset for help on using the changeset viewer.