Skip to content

Commit

Permalink
add "." and ".." in directory listings
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDaveD committed Oct 8, 2024
1 parent 4289904 commit 25d3d0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
21 changes: 21 additions & 0 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ sqfs_err sqfs_dir_open(sqfs *fs, sqfs_inode *inode, sqfs_dir *dir,
dir->offset = 0;
dir->total = inode->xtra.dir.dir_size <= 3 ? 0 :
inode->xtra.dir.dir_size - 3;
/* The first two offsets indicate unstored "." and ".." files */
dir->total += 2;

if (offset) {
/* Fast forward to the given offset */
Expand Down Expand Up @@ -129,6 +131,25 @@ bool sqfs_dir_next(sqfs *fs, sqfs_dir *dir, sqfs_dir_entry *entry,

*err = SQFS_OK;
entry->offset = dir->offset;

if (entry->offset < 2) {
/* offsets 0 and 1 are '.' and '..' which are not stored */
entry->type = SQUASHFS_DIR_TYPE;
if (entry->name != NULL) {
entry->name[0] = '.';
entry->name_size = 1;
if (entry->offset == 1) {
entry->name[1] = '.';
entry->name_size += 1;
}
entry->name[entry->name_size++] = '\0';
}
entry->inode = 0;
entry->inode_number = 0;
entry->next_offset = dir->offset;
dir->offset += 1;
return true;
}

while (dir->header.count == 0) {
if (dir->offset >= dir->total)
Expand Down
13 changes: 11 additions & 2 deletions traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,19 @@ bool sqfs_traverse_next(sqfs_traverse *trv, sqfs_err *err) {
found = sqfs_dir_next(trv->fs, &level->dir, &trv->entry, err);
if (*err)
goto error;
if (found)
if (found) {
char *name = trv->entry.name;
if ((name[0] == '.') &&
((name[1] == '\0') ||
((name[1] == '.') &&
(name[2] == '\0')))) {
/* ignore '.' and '..' */
break;
}
trv->state = TRAVERSE_NAME_ADD;
else
} else {
trv->state = TRAVERSE_ASCEND;
}
break;

case TRAVERSE_NAME_ADD:
Expand Down

0 comments on commit 25d3d0d

Please sign in to comment.