Skip to content

squashfs: expose inode number and type via Sys()#395

Closed
luthermonson wants to merge 1 commit into
diskfs:masterfrom
luthermonson:squashfs-expose-inode-info
Closed

squashfs: expose inode number and type via Sys()#395
luthermonson wants to merge 1 commit into
diskfs:masterfrom
luthermonson:squashfs-expose-inode-info

Conversation

@luthermonson
Copy link
Copy Markdown
Contributor

Refs #301. Sibling of #393 (ext4) — same goal, but adapted to squashfs's existing public surface.

What this does

The other filesystems answering #301 (ext4, iso9660, fat) introduce a per-package StatT struct returned by Sys(). Squashfs is different: Sys() already returns *directoryEntry (aliased as the public squashfs.FileStat), which already exposes filesystem-specific metadata via accessor methods — UID(), GID(), Xattrs(), Readlink().

To stay consistent with that existing public surface — and to avoid breaking any caller already doing sys.(squashfs.FileStat).UID() — this PR adds two more accessors rather than introducing a parallel struct:

  • (*directoryEntry).Inode() uint32 — squashfs inode number
  • (*directoryEntry).InodeType() string — human-readable inode type ("basic-file", "extended-symlink", etc., one of 14 values)

Sys()'s return type is unchanged. Callers use it the same way they already use UID()/GID():

if st, ok := fi.Sys().(squashfs.FileStat); ok {
    fmt.Println(st.Inode(), st.InodeType(), st.UID())
}

Why not a StatT struct here

Two competing public shapes inside one package (squashfs.FileStat accessor methods + squashfs.StatT struct fields, both reachable from the same Sys() call) would be worse than mild inconsistency across packages. The existing pattern was set when squashfs first exposed UID/GID/Xattrs; this PR follows it.

Tests

New TestSquashfsInodeMetadata exercises ReadDir(".") + DirEntry.Info() and OpenFile().Stat() on the existing test image, asserts non-zero Inode(), no duplicate inode numbers across entries, and a sensible InodeType() (with the extra check that directories report basic-directory or extended-directory).

Adds Inode() and InodeType() accessors to directoryEntry so callers
typing the Sys() result to squashfs.FileStat can read squashfs-specific
metadata that fs.FileInfo doesn't carry. Sys() still returns
*directoryEntry (no breaking change to existing assertions).

Refs diskfs#301.
@luthermonson luthermonson force-pushed the squashfs-expose-inode-info branch from 13e13f2 to 0f6189e Compare May 14, 2026 05:32
Copy link
Copy Markdown
Collaborator

@deitch deitch left a comment

Choose a reason for hiding this comment

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

This looks good to me. I am not the biggest fan of the issue you raised - StatT everywhere else, just relying on the directoryEntry itself with exposed properties here - but it is good enough. The primary interfaces will work, and we can clean it up later.

If you think it is an issue, we can restructure this to a StatT as well. I am not sure how complicated that would be.

@deitch
Copy link
Copy Markdown
Collaborator

deitch commented May 14, 2026

Also, this still is draft

@luthermonson luthermonson marked this pull request as ready for review May 14, 2026 18:28
@luthermonson
Copy link
Copy Markdown
Contributor Author

i think i'd like to see this structured as a StatT, PRs are free so let me open a new one with that design and we compare what we want to go with.

@deitch deitch closed this in #398 May 15, 2026
deitch pushed a commit that referenced this pull request May 15, 2026
Alternative design to #395, applying the same StatT pattern used by
the iso9660 and ext4 siblings of #301. Breaking change: removes the
FileStat = *directoryEntry alias and the public UID()/GID()/Xattrs()
accessor methods. Sys() now returns *StatT with UID, GID, Inode,
InodeType, Xattrs, and LinkTarget fields.
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