rendered paste bodyint fmsGetNextDirEntry(int *dirNum, char* mask, DirEntry* dirEntry, const int dir){
if (mask == 0)
mask = "*.*";
DirEntry buf[16];
int i = 0;
unsigned short curSector = dir == 0 ? 19 : C_2_S(dir);
int unread = 1;
do {
while (i < (*dirNum / 16)) {
// assuming dir is 0 when we're in the root directory
if (dir != 0) {
unsigned short fatEntry = getFatEntry(S_2_C(curSector), FAT1);
if (fatEntry == FAT_EOC)
return ERR66;
assert(fatEntry != FAT_BAD && fatEntry != 0);
curSector = C_2_S(fatEntry);
} else {
assert(curSector >= 19 && curSector <=32);
// ok we're traversing the root directory
// so curCluster is actually the sector number
curSector++;
if (curSector> 32) {
return ERR66;
}
assert(curSector >= 19 && curSector <=32);
}
i++;
unread = 1;
}
if (unread) {
fmsReadSector(buf, curSector);
unread = 0;
}
DirEntry * e = &buf[*dirNum % 16];
if (e->name[0] == 0)
return ERR66;
*dirEntry = *e;
(*dirNum)++;
} while (dirEntry->attributes & LONGNAME
|| !matches_mask(mask, dirEntry) || dirEntry->name[0] == 0xe5);
assert(dirEntry->name[0] != 0xe5);
return 0;
}