Skip to content

squashfs: expose metadata via StatT (alternative to #395)#398

Merged
deitch merged 1 commit into
diskfs:masterfrom
luthermonson:squashfs-statt
May 15, 2026
Merged

squashfs: expose metadata via StatT (alternative to #395)#398
deitch merged 1 commit into
diskfs:masterfrom
luthermonson:squashfs-statt

Conversation

@luthermonson
Copy link
Copy Markdown
Contributor

Refs #301. Alternative design to #395 — same goal, restructured around a StatT struct to match the pattern used by the ext4 (#393) and iso9660 (#394) siblings.

What changed vs #395

#395 added two more accessor methods (Inode(), InodeType()) on top of the existing UID()/GID()/Xattrs()/Readlink() surface reachable through squashfs.FileStat. That kept squashfs internally consistent but left it stylistically out of step with the other filesystems answering #301, which all expose a StatT struct.

This PR goes the other way: it converts the squashfs Sys() surface to a StatT struct too, accepting the breaking change to get one consistent shape across the package.

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

Fields

Field Source
UID uint32 directory entry
GID uint32 directory entry
Inode uint32 inode index
InodeType string one of 14 documented values, or "unknown"
Xattrs map[string]string directory entry
LinkTarget string symlink target, empty for non-symlinks

Breaking changes

Removed from the public surface:

  • type FileStat = *directoryEntry alias
  • (FileStat).UID() uint32
  • (FileStat).GID() uint32
  • (FileStat).Xattrs() map[string]string

External callers migrate:

// before
if st, ok := fi.Sys().(squashfs.FileStat); ok {
    fmt.Println(st.UID(), st.Xattrs())
}

// after
if st, ok := fi.Sys().(*squashfs.StatT); ok {
    fmt.Println(st.UID, st.Xattrs)
}

Readlink() and Open() remain as methods on the now-unexported directoryEntry for internal use, but are no longer reachable externally. Symlink targets are exposed via StatT.LinkTarget; opening files continues through FileSystem.OpenFile.

Tests

  • TestSquashfsStatT covers the new struct: non-zero Inode, valid InodeType, directory entries report a directory type, empty LinkTarget for regular files, also reachable from OpenFile().Stat().
  • TestDirectoryEntry (internal) updated to assert on *StatT.
  • TestSquashfsOpen, TestSquashfsCheckListing, TestSquashfsReadDirXattr updated to the new shape.

Which to merge

This is meant as a comparison PR — if you prefer the consistency across packages, merge this and close #395; if you prefer keeping squashfs's existing accessor surface, merge #395 and close this.

Alternative design to diskfs#395, applying the same StatT pattern used by
the iso9660 and ext4 siblings of diskfs#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.
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 is nice and clean. Merging this, closing #395

@deitch deitch merged commit fce3c88 into diskfs:master May 15, 2026
20 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