Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "." and ".." in directory listings #139

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: This probably looks a lot nicer using strncpy() (or similar) than doing character-by-character modification. Similarly below in traverse.c, using strcmp().

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
Loading