Skip to content

Commit

Permalink
fixed listing the root of a directory not mounted at /
Browse files Browse the repository at this point in the history
fixed a file named "" appearing at the end of readdir

todo: listing the root dir when mounted at / still fails
  • Loading branch information
cleverca22 committed Aug 20, 2021
1 parent 1a0ae20 commit a644add
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/fs/ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ status_t ext2_opendir(fscookie *cookie, const char *name, dircookie **dcookie) {
int err;
inodenum_t inum;
//uint file_blocknum;
err = ext2_lookup(ext2, name, &inum);
if (err < 0) {
LTRACEF("err = %d\n", err);
return err;
if (name[0] == 0) {
inum = EXT2_ROOT_INO;
} else {
err = ext2_lookup(ext2, name, &inum);
if (err < 0) {
LTRACEF("err = %d\n", err);
return err;
}
}
LTRACEF("inum = %d\n", inum);

Expand Down Expand Up @@ -302,6 +306,12 @@ status_t ext2_readdir(dircookie *cookie, struct dirent *ent_out) {
}

pos += ROUNDUP(LE16(ent->rec_len), 4);
if (ent->inode == 0) { // deleted file
// TODO, assumes end of dir listing
// it should continue to the next record, potentially in the next block
free(buf);
return ERR_NOT_FOUND;
}
if (pos >= EXT2_BLOCK_SIZE(cookie->fs->sb)) {
cookie->fileblock++;
cookie->cursor = 0;
Expand Down

0 comments on commit a644add

Please sign in to comment.