From bef162cd24a7568b93f33d30de2ed49c7be46042 Mon Sep 17 00:00:00 2001 From: "Enrico Fraccaroli (Galfurian)" Date: Thu, 27 Jan 2022 15:00:33 -0500 Subject: [PATCH] Fix ext2_directory_is_empty function, thus fixing rmdir. --- mentos/src/fs/ext2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mentos/src/fs/ext2.c b/mentos/src/fs/ext2.c index 57fb25d..bdc467d 100644 --- a/mentos/src/fs/ext2.c +++ b/mentos/src/fs/ext2.c @@ -1635,9 +1635,12 @@ void ext2_direntry_iterator_next(ext2_direntry_iterator_t *iterator) static inline bool_t ext2_directory_is_empty(ext2_filesystem_t *fs, uint8_t *cache, ext2_inode_t *inode) { - if (ext2_read_inode_block(fs, inode, 0U, cache) == -1) - return true; - return ((ext2_dirent_t *)cache) == NULL; + ext2_direntry_iterator_t it = ext2_direntry_iterator_begin(fs, cache, inode); + for (; ext2_direntry_iterator_valid(&it); ext2_direntry_iterator_next(&it)) { + if (it.direntry->inode != 0) + return false; + } + return true; } // ============================================================================