static FRESULT dir_read ( DIR *dj, /* Pointer to the directory object to store read object name */ BYTE *dir /* 32-byte working buffer */ ) { FRESULT res; BYTE a, c; res = FR_NO_FILE; while (dj->sect) { res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */ ? FR_DISK_ERR : FR_OK; if (res != FR_OK) break; c = dir[DIR_Name]; if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ a = dir[DIR_Attr] & AM_MASK; if (c != 0xE5 && c != '.' && !(a & AM_VOL)) /* Is it a valid entry? */ break; res = dir_next(dj); /* Next entry */ if (res != FR_OK) break; } if (res != FR_OK) dj->sect = 0; return res; }
static FRESULT dir_find ( DIR *dj, /* Pointer to the directory object linked to the file name */ BYTE *dir /* 32-byte working buffer */ ) { FRESULT res; BYTE c; res = dir_rewind(dj); /* Rewind directory object */ if (res != FR_OK) return res; do { res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */ ? FR_DISK_ERR : FR_OK; if (res != FR_OK) break; c = dir[DIR_Name]; /* First character */ if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */ break; res = dir_next(dj); /* Next entry */ } while (res == FR_OK); return res; }
static FRESULT dir_find ( DIR *dj, /* Pointer to the directory object linked to the file name */ BYTE *dir /* 32-byte working buffer */ ) { FRESULT res; BYTE c; res = dir_rewind(dj); /* Rewind directory object */ if (res != FR_OK) return res; do { if ( (dj->index & 7) == 0 ) { // Need to read data res = disk_readp( Abuff.DirBuffer, dj->sect, (WORD)((dj->index & 8) * 32), 256) /* Read half a sector */ ? FR_DISK_ERR : FR_OK; } else { res = FR_OK ; } if (res != FR_OK) break; memcpy( dir, &Abuff.DirBuffer[((dj->index % 8) * 32)], 32 ) ; c = dir[DIR_Name]; /* First character */ if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */ break; res = dir_next(dj); /* Next entry */ } while (res == FR_OK); return res; }
FRESULT pf_readdir ( DIR *dj, /* Pointer to the open directory object */ FILINFO *fno /* Pointer to file information to return */ ) { FRESULT res; BYTE sp[12], dir[32]; FATFS *fs = FatFs; if (!fs) { /* Check file system */ res = FR_NOT_ENABLED; } else { dj->fn = sp; if (!fno) { res = dir_rewind(dj); } else { res = dir_read(dj, dir); /* Get current directory item */ if (res == FR_NO_FILE) res = FR_OK; if (res == FR_OK) { /* A valid entry is found */ get_fileinfo(dj, dir, fno); /* Get the object information */ res = dir_next(dj); /* Increment read index for next */ if (res == FR_NO_FILE) res = FR_OK; } } } return res; }
static FRESULT dir_read(DIR *dj) { FRESULT res; u8 adir,c,*dir; res = FR_NO_FILE; dir = FatFs->buf; while (dj->sect) { res = disk_readp(dir, dj->sect, (u16)((dj->index % 16) * 32), 32) /* Read an entry */ ? FR_DISK_ERR : FR_OK; if (res != FR_OK) break; c = dir[DIR_Name]; if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ adir = dir[DIR_Attr] & AM_MASK; if (c != 0xE5 && c != '.' && !(adir & AM_VOL)) /* Is it a valid entry? */ break; res = dir_next(dj); /* Next entry */ if (res != FR_OK) break; } if (res != FR_OK) dj->sect = 0; return res; }