From 4b57c7b2d7b704b38b9efcdce00eef2ce6d06f3c Mon Sep 17 00:00:00 2001 From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:26:11 -0500 Subject: [PATCH] add "." and ".." in directory listings --- dir.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dir.c b/dir.c index 2dbe945..7c14cea 100644 --- a/dir.c +++ b/dir.c @@ -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 */ @@ -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)