[Concept,16/21] dir.c: Advance ctx->pos before dir_emit() calls

Message ID 20260416165733.2923423-17-sjg@u-boot.org
State New
Headers
Series fs: Add ISO 9660 filesystem driver ported from Linux |

Commit Message

Simon Glass April 16, 2026, 4:57 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

U-Boot's VFS layer iterates directories one entry at a time,
calling iterate_shared() repeatedly. The Linux implementation
advances ctx->pos after a successful dir_emit(), but this causes
the U-Boot single-entry iterator to see the same entry twice
since it re-enters with the old position.

Move ctx->pos advancement before the dir_emit() call for '.', '..',
and regular entries so that when dir_emit() signals "buffer full"
and iteration resumes, the position already points past the current
entry.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 fs/isofs/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
index e40cdb68ff5..6065f46f762 100644
--- a/fs/isofs/dir.c
+++ b/fs/isofs/dir.c
@@ -175,9 +175,9 @@  static int do_isofs_readdir(struct inode *inode, struct file *file,
 
 		/* Handle the case of the '.' directory */
 		if (de->name_len[0] == 1 && de->name[0] == 0) {
+			ctx->pos += de_len;
 			if (!dir_emit_dot(file, ctx))
 				break;
-			ctx->pos += de_len;
 			continue;
 		}
 
@@ -185,9 +185,9 @@  static int do_isofs_readdir(struct inode *inode, struct file *file,
 
 		/* Handle the case of the '..' directory */
 		if (de->name_len[0] == 1 && de->name[0] == 1) {
+			ctx->pos += de_len;
 			if (!dir_emit_dotdot(file, ctx))
 				break;
-			ctx->pos += de_len;
 			continue;
 		}
 
@@ -232,11 +232,11 @@  static int do_isofs_readdir(struct inode *inode, struct file *file,
 				len = de->name_len[0];
 			}
 		}
+		ctx->pos += de_len;
 		if (len > 0) {
 			if (!dir_emit(ctx, p, len, inode_number, DT_UNKNOWN))
 				break;
 		}
-		ctx->pos += de_len;
 	}
 	if (bh)
 		brelse(bh);