static BOOL ValidityChecker(RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure) { char message[80], *p; CLUSTER thisCluster; struct Pipe* pipe = *((struct Pipe**) structure); if (!IsLabelValid(handle, label)) { thisCluster = DataSectorToCluster(handle, datasector); if (!thisCluster) return FAIL; sprintf(message, "Invalid cluster found at: %lu\n", thisCluster); ReportFileSysError(message, 0, &p, 0, FALSE); pipe->invalidfound = TRUE; if (pipe->fixit) { if (!WriteFatLabel(handle, thisCluster, FAT_LAST_LABEL)) return FAIL; } } return TRUE; }
BOOL FindClusterInFAT(RDWRHandle handle, CLUSTER tofind, CLUSTER* result) { struct Pipe pipe, *ppipe=&pipe; CLUSTER cluster; pipe.tofind = tofind; pipe.sector = 0; pipe.found = FALSE; if (!LinearTraverseFat(handle, ClusterInFATFinder, (void**) &ppipe)) return FALSE; if (!pipe.found) { *result = 0; return TRUE; } if (!pipe.sector) /* This should never happen */ { *result = 0; return FALSE; } cluster = DataSectorToCluster(handle, pipe.sector); if (!cluster) return FALSE; *result = cluster; return TRUE; }
static BOOL LargestFreeSpaceFinder(RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure) { struct Pipe* pipe = (struct Pipe*) *structure; if (FAT_FREE(label)) { if (!PreviousFilled) { pipe->count++; } else { LastFreeBlock = DataSectorToCluster(handle, datasector); if (!LastFreeBlock) { pipe.error = TRUE; return FALSE; } } PreviousFilled = FALSE; } else { if (!PreviousFilled) { if (pipe->count > pipe->FoundMax) { pipe->FoundMax = pipe->count; pipe->count = 0; pipe->FoundCluster = DataSectorToCluster(handle, datasector); if (!pipe->FoundCluster) { pipe->error = TRUE; return FALSE; } } PreviousFilled = TRUE; } } return TRUE; }
static BOOL ClusterPreReader(RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure) { SECTOR firstsector; CLUSTER cluster; unsigned char sectorspercluster; struct Pipe* pipe = *((struct Pipe**) structure); if (label); sectorspercluster = GetSectorsPerCluster(handle); if (!sectorspercluster) return FAIL; if (pipe->maxindex == 0) /* cluster > read buf */ { if (!PreReadLargeCluster(handle, datasector, sectorspercluster, pipe->buf, pipe->bufsize)) return FAIL; } else { cluster = DataSectorToCluster(handle, datasector); if ((pipe->index > 0) && ((pipe->prevcluster != cluster-1) || (pipe->index == pipe->maxindex))) { firstsector = ConvertToDataSector(handle, pipe->firstcluster); if (!firstsector) return FAIL; if (ReadSectors(handle, pipe->index*sectorspercluster, firstsector, pipe->buf) == -1) { return FAIL; } pipe->index = 0; pipe->firstcluster = cluster; } else { pipe->index++; } } pipe->prevcluster = cluster; return TRUE; }
static BOOL NthFileClusterFinder(RDWRHandle handle, CLUSTER label, SECTOR datasector, void** structure) { struct Pipe* pipe = *((struct Pipe**) structure); label = label; if (pipe->n == pipe->count) { pipe->result = DataSectorToCluster(handle, datasector); if (!pipe->result) RETURN_FTEERROR(FAIL); pipe->found = TRUE; return FALSE; } pipe->count++; return TRUE; }
static BOOL OnlyFilledRead(RDWRHandle handle, SECTOR lsect, unsigned numsectors, char* buf) { unsigned i; SECTOR start = lsect; CLUSTER cluster, label; for (i = 0; i < numsectors; i++) { cluster = DataSectorToCluster(handle, lsect+i); if (!cluster) return FALSE; if (!GetNthCluster(handle, cluster, &label)) { return FALSE; } if (FAT_FREE(label) || FAT_BAD(label)) { if (i) { if (ReadSectors(handle, i, start, buf) == -1) { return FALSE; } } start = lsect+i+1; } } if (start < lsect+numsectors) { if (ReadSectors(handle, numsectors - (unsigned)(start - lsect), start, buf) == -1) { return FALSE; } } return TRUE; }
static BOOL DirSizeGetter(RDWRHandle handle, struct DirectoryPosition* pos, void** structure) { BOOL InRoot; unsigned long **dirsize = (unsigned long**) structure; unsigned char sectorspercluster; CLUSTER label; pos = pos, handle = handle; /* Check for loops in the directory structure */ InRoot = IsRootDirPosition(handle, pos); if (InRoot == -1) return FAIL; if (!InRoot && (pos->offset == 0)) { sectorspercluster = GetSectorsPerCluster(handle); if (!sectorspercluster) return FAIL; if ((pos->sector % sectorspercluster) == 0) { label = DataSectorToCluster(handle, pos->sector); if (!label) return FAIL; if (GetBitfieldBit(fatmap, label)) { return FALSE; } SetBitfieldBit(fatmap, label); } } **dirsize += sizeof(struct DirectoryEntry); return TRUE; }