Skip to content

Commit

Permalink
Merge pull request #135 from vasi/fuset2
Browse files Browse the repository at this point in the history
Allow handling broken directory offsets
  • Loading branch information
vasi authored Aug 8, 2024
2 parents 94f998c + 17b7c66 commit e6ecfb0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ AC_ARG_ENABLE([sigterm-handler],
])
AM_CONDITIONAL([SIGTERM_HANDLER], [test x$enable_sigterm_handler = xyes])

AC_ARG_ENABLE([broken-directory-offsets],
AS_HELP_STRING([--enable-broken-directory-offsets], [handle broken directory offsets, for implementations like FUSE-T]),
[broken_dir_offsets="yes"])
AS_IF([test x$broken_dir_offsets = xyes],
[AC_DEFINE(SQFS_BROKEN_DIR_OFFSETS, 1, [Handle broken directory offsets])])

AC_SUBST([sq_decompressors])
AC_SUBST([sq_high_level])
AC_SUBST([sq_low_level])
Expand Down
7 changes: 7 additions & 0 deletions hl.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,20 @@ static int sqfs_hl_op_readdir(const char *path, void *buf,
sqfs_hl_lookup(&fs, NULL, NULL);
inode = (sqfs_inode*)(intptr_t)fi->fh;

#ifdef SQFS_BROKEN_DIR_OFFSETS
offset = 0;
#endif
if (sqfs_dir_open(fs, inode, &dir, offset))
return -EINVAL;

memset(&st, 0, sizeof(st));
sqfs_dentry_init(&entry, namebuf);
while (sqfs_dir_next(fs, &dir, &entry, &err)) {
#ifdef SQFS_BROKEN_DIR_OFFSETS
sqfs_off_t doff = 0;
#else
sqfs_off_t doff = sqfs_dentry_next_offset(&entry);
#endif
st.st_mode = sqfs_dentry_mode(&entry);
if (filler(buf, sqfs_dentry_name(&entry), &st, doff
#if FUSE_USE_VERSION >= 30
Expand Down
18 changes: 17 additions & 1 deletion ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ void sqfs_ll_op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
int err = 0;

update_access_time();
if (sqfs_dir_open(&lli->ll->fs, &lli->inode, &dir, off))

#ifdef SQFS_BROKEN_DIR_OFFSETS
off_t dir_offset = 0;
#else
off_t dir_offset = off;
#endif

if (sqfs_dir_open(&lli->ll->fs, &lli->inode, &dir, dir_offset))
err = EINVAL;
if (!err && !(bufpos = buf = malloc(size)))
err = ENOMEM;
Expand All @@ -186,6 +193,15 @@ void sqfs_ll_op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,

esize = sqfs_ll_add_direntry(req, bufpos, size, sqfs_dentry_name(&entry),
&st, sqfs_dentry_next_offset(&entry));

#ifdef SQFS_BROKEN_DIR_OFFSETS
/* We couldn't fast-forwards earlier, so manually skip entries instead */
if (off > 0) {
off -= esize;
continue;
}
#endif

if (esize > size)
break;

Expand Down

0 comments on commit e6ecfb0

Please sign in to comment.