BOOL DiskSortEntries(RDWRHandle handle, CLUSTER cluster) { int i=0; long totalcount, lfncount, realcount; struct DiskEntryGetterStruct parameters; struct DirectoryPosition pos; struct DirectoryEntry entry; parameters.handle = handle; parameters.cluster = cluster; SetResourceConfiguration(&DiskConfig); totalcount = low_dircount(handle, cluster, 0xffff); if (totalcount == -1) RETURN_FTEERR(FALSE); lfncount = low_dircount(handle, cluster, LFN_ATTRIBUTES); if (lfncount == -1) RETURN_FTEERR(FALSE); realcount = totalcount - lfncount; for (i = 0; i < 2; i++) { if (!GetNthDirectoryPosition(handle, cluster, i, &pos)) { RETURN_FTEERR(FALSE); } if (!GetDirectory(handle, &pos, &entry)) { RETURN_FTEERR(FALSE); } switch (i) { case 0: if (IsCurrentDir(entry)) { realcount--; } break; case 1: if (IsPreviousDir(entry)) { realcount--; } } } if (realcount && realcount <= INT_MAX) SelectionSortEntries(¶meters, (int)realcount); return TRUE; }
BOOL GetNthSubDirectoryPosition(RDWRHandle handle, CLUSTER cluster, unsigned long n, struct DirectoryPosition* result) { int counter = 0; struct DirectoryPosition pos; struct DirectoryEntry* entry; entry = AllocateDirectoryEntry(); if (!entry) return FALSE; n++; /* n is 0 based */ while (n) { pos.sector = 0; pos.offset = 0; if (!GetNthDirectoryPosition(handle, cluster, counter++, &pos)) { FreeDirectoryEntry(entry); return FALSE; } if ((pos.sector == 0) && (pos.offset == 0)) /* Not found*/ { FreeDirectoryEntry(entry); return TRUE; } if (!GetDirectory(handle, &pos, entry)) { FreeDirectoryEntry(entry); return TRUE; } if (!IsLFNEntry((entry)) && (entry->attribute & FA_DIREC) && (!IsDeletedLabel(*entry)) && (!IsCurrentDir(*entry)) && (!IsPreviousDir(*entry))) { n--; } } memcpy(result, &pos, sizeof(struct DirectoryPosition)); FreeDirectoryEntry(entry); return TRUE; }
BOOL GetNthDirectorySector(RDWRHandle handle, CLUSTER cluster, unsigned long n, char* sector) { unsigned long entry; struct DirectoryPosition temp; /* Calculate which entry this corresponds to */ entry = n * ENTRIESPERSECTOR; if (!GetNthDirectoryPosition(handle, cluster, entry, &temp)) { return FALSE; } return ReadDataSectors(handle, 1, temp.sector, sector); }