Skip to content

client: fix CPIO9P Readdir pagination, synthetic ancestor dirs, and Walk - #330

Merged
rminnich merged 1 commit into
u-root:mainfrom
brho:cpio9p-fixes
Oct 27, 2026
Merged

rminnich merged 1 commit into
u-root:mainfrom
brho:cpio9p-fixes

Conversation

@brho

@brho brho commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

CPIO9P previously assumed that CPIO archives always start with a "." directory record at index 0 and store all children of each directory contiguously after the parent record. In addition, Readdir unconditionally prepended "." even on continuation calls with a non-zero offset and used global record indices as Dirent.Offset cookies, causing 9P clients to loop infinitely or skip entries, while Walk failed on ".." at root and rec() had an off-by-one bounds check.

Normalize record names in NewCPIO9PReaderAt, synthesize "." and any missing parent directory records, and index direct children per directory so Attach and Readdir work regardless of record ordering in the archive. Emit sequential 1-based Dirent.Offset continuation cookies in Readdir, clean Walk paths relative to "/" so "." and ".." resolve properly at any depth, and fix the rec() bounds check.

CPIO9P previously assumed that CPIO archives always start with a "."
directory record at index 0 and store all children of each directory
contiguously after the parent record. In addition, Readdir
unconditionally prepended "." even on continuation calls with a
non-zero offset and used global record indices as Dirent.Offset
cookies, causing 9P clients to loop infinitely or skip entries, while
Walk failed on ".." at root and rec() had an off-by-one bounds check.

Normalize record names in NewCPIO9PReaderAt, synthesize "." and any
missing parent directory records, and index direct children per
directory so Attach and Readdir work regardless of record ordering in
the archive. Emit sequential 1-based Dirent.Offset continuation cookies
in Readdir, clean Walk paths relative to "/" so "." and ".." resolve
properly at any depth, and fix the rec() bounds check.

Signed-off-by: Barret Rhoden <brho@google.com>
@brho
brho requested a review from rminnich October 27, 2026 17:34
@rminnich
rminnich merged commit 8af161e into u-root:main Oct 27, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants