Skip to content

Commit

Permalink
Additional improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jamersonpro committed Jan 9, 2023
1 parent b2baa26 commit bce1798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ typedef ULONG CLONG;

struct sectors_range
{
sectors_range(__int64 firstSector, __int64 lastSector)
sectors_range(unsigned __int64 firstSector, unsigned __int64 lastSector)
{
this->firstSector = firstSector;
this->lastSector = lastSector;
}

__int64 firstSector;
__int64 lastSector;
unsigned __int64 firstSector;
unsigned __int64 lastSector;

bool contains(__int64 sector) const
bool contains(unsigned __int64 sector) const
{
return firstSector <= sector && sector <= lastSector;
}
Expand Down
30 changes: 17 additions & 13 deletions untfs/src/ntfssa.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -869,22 +869,24 @@ Return Value:
--*/
{
PLOG_IO_DP_DRIVE drive;
PNTFS_BITMAP bitmap;
ULONG cluster_factor;
Message->Out("Scanning volume...");

Message->Out("Scanning free space...");

drive = Mft->GetDataAttribute()->GetDrive();
PLOG_IO_DP_DRIVE drive = Mft->GetDataAttribute()->GetDrive();

BIG_INT firstDriveSector = drive->QueryHiddenSectors();
BIG_INT lastDriveSector = firstDriveSector + drive->QuerySectors() - 1;

Message->Out("First volume sector: ", firstDriveSector.GetQuadPart());
Message->Out("Last volume sector: ", lastDriveSector.GetQuadPart());

bitmap = Mft->GetVolumeBitmap();
cluster_factor = Mft->QueryClusterFactor();
PNTFS_BITMAP bitmap = Mft->GetVolumeBitmap();
BIG_INT clustersCount = bitmap->QuerySize();
ULONG clusterFactor = Mft->QueryClusterFactor();

ULONG sectorSize = drive->QuerySectorSize();
Message->Out("Bytes per sector: ", sectorSize);
Message->Out("Sectors per cluster: ", clusterFactor);
Message->Out("Total cluster count: ", clustersCount.GetQuadPart());

BIG_INT skippedAlreadyBadClusters = 0;
BIG_INT skippedInUseClusters = 0;
Expand All @@ -894,24 +896,26 @@ Return Value:

for (std::vector<sectors_range>::const_iterator physicalDriveSectorsPair = physicalDriveSectorsTargets.begin(); physicalDriveSectorsPair != physicalDriveSectorsTargets.end(); ++physicalDriveSectorsPair)
{
BIG_INT firstPhysicalDriveSectorToMark = (unsigned __int64)physicalDriveSectorsPair->firstSector;
BIG_INT firstPhysicalDriveSectorToMark = physicalDriveSectorsPair->firstSector;
if (firstPhysicalDriveSectorToMark < firstDriveSector) firstPhysicalDriveSectorToMark = firstDriveSector;
if (firstPhysicalDriveSectorToMark > lastDriveSector) continue;

BIG_INT lastPhysicalDriveSectorToMark = (unsigned __int64)physicalDriveSectorsPair->lastSector;
BIG_INT lastPhysicalDriveSectorToMark = physicalDriveSectorsPair->lastSector;
if (lastPhysicalDriveSectorToMark > lastDriveSector) lastPhysicalDriveSectorToMark = lastDriveSector;
if (lastPhysicalDriveSectorToMark < firstDriveSector) continue;

if (firstPhysicalDriveSectorToMark > lastPhysicalDriveSectorToMark) continue;

BIG_INT firstSectorToMark = (firstPhysicalDriveSectorToMark - firstDriveSector) / cluster_factor;
BIG_INT lastSectorToMark = (lastPhysicalDriveSectorToMark - firstDriveSector) / cluster_factor;
for (BIG_INT clusterNumber = firstSectorToMark; clusterNumber <= lastSectorToMark; ++clusterNumber)
BIG_INT firstClusterToMark = (firstPhysicalDriveSectorToMark - firstDriveSector) / clusterFactor;
BIG_INT lastClusterToMark = (lastPhysicalDriveSectorToMark - firstDriveSector) / clusterFactor;
for (BIG_INT clusterNumber = firstClusterToMark; clusterNumber <= lastClusterToMark; ++clusterNumber)
{
if (clusterNumber == lastProcessedCluster) continue;

lastProcessedCluster = clusterNumber;

if (clusterNumber < 0 || clusterNumber >= clustersCount) continue; //check clusterNumber is valid

if (BadClusterFile->IsInList(clusterNumber))
{
++skippedAlreadyBadClusters;
Expand Down

0 comments on commit bce1798

Please sign in to comment.