+static int8_t
+_ao_fat_readdir(uint16_t *entry, struct ao_fat_dirent *dirent)
+{
+ uint8_t *dent;
+
+ if (_ao_fat_setup() != AO_FAT_FILESYSTEM_SUCCESS)
+ return -AO_FAT_EIO;
+
+ for (;;) {
+ dent = _ao_fat_root_get(*entry);
+ if (!dent)
+ return -AO_FAT_EDIREOF;
+
+ if (dent[0] == AO_FAT_DENT_END) {
+ _ao_fat_root_put(dent, *entry, 0);
+ return -AO_FAT_EDIREOF;
+ }
+ if (dent[0] != AO_FAT_DENT_EMPTY && (dent[0xb] & 0xf) != 0xf) {
+ _ao_fat_dirent_init(dirent, dent, *entry);
+ _ao_fat_root_put(dent, *entry, 0);
+ (*entry)++;
+ return AO_FAT_SUCCESS;
+ }
+ _ao_fat_root_put(dent, *entry, 0);
+ (*entry)++;
+ }
+}
+
+int8_t
+ao_fat_readdir(uint16_t *entry, struct ao_fat_dirent *dirent)
+{
+ int8_t status;
+
+ ao_mutex_get(&ao_fat_mutex);
+ status = _ao_fat_readdir(entry, dirent);
+ ao_mutex_put(&ao_fat_mutex);
+ return status;
+}
+