fat12/16/32: expose attribute flags and timestamps via FileInfo.Sys()#396
Open
luthermonson wants to merge 1 commit into
Open
fat12/16/32: expose attribute flags and timestamps via FileInfo.Sys()#396luthermonson wants to merge 1 commit into
luthermonson wants to merge 1 commit into
Conversation
FAT FileInfo.Sys() previously returned nil. Introduce fat12.StatT carrying the FAT directory-entry metadata that has no analogue in os.FileMode: read-only/hidden/system/archive/volume-label attribute bits, creation and access timestamps, and the starting cluster of the file's chain. Wire fat12.FileInfo.Sys() to populate and return a *StatT from data already parsed in parseDirEntries. Because fat12 is the shared base for FAT12, FAT16, and FAT32, this single change is reflected through type aliases in the fat16 and fat32 packages: fat32.StatT = fat12.StatT and fat16.StatT = fat12.StatT. Refs diskfs#301.
9c3bfc5 to
e50b9c1
Compare
deitch
approved these changes
May 14, 2026
Collaborator
deitch
left a comment
There was a problem hiding this comment.
Looks good to me. Needs to be removed from "Draft" to go ahead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #301. Sibling of #393 (ext4) — same pattern, applied to all three FAT variants in a single change by leveraging the recent FAT12/16 refactor.
What this does
FileInfo.Sys()previously returnednilfor fat12, fat16, and fat32. FAT has no inodes / uid / gid / POSIX permissions — that's a format limit, not a code one — but the directory entry does carry metadata that doesn't fitos.FileMode:This PR introduces
fat12.StatTcarrying those fields, wiresfat12.FileInfo.Sys()to return it, and exposes the same type fromfat32andfat16via type aliases.Why this lives in fat12 (not three separate copies)
The upstream FAT12/16 support PR (#358) restructured the FAT codebase: the implementation lives in
filesystem/fat12, andfilesystem/fat32+filesystem/fat16are thin wrappers that embed*fat12.FileSystemand overrideType(). Public API parity with the old fat32 surface is preserved through type aliases —type SectorSize = fat12.SectorSizealready exists infat32.go.This PR follows that same pattern for
StatT:Concrete benefits:
directoryEntry.stat()helper that builds theStatTis defined once infat12. fat16 and fat32 inherit the populatedSys()automatically.fat32writesfi.Sys().(*fat32.StatT)and it works; someone usingfat12writesfi.Sys().(*fat12.StatT)and it works. They get the same*StatTvalue because the types are aliases (not separate types with the same field shape) — so a downstream library that wants to handle any FAT variant can type-assert once against*fat12.StatTand it'll match all three.fat12.StatTand the other two get it for free. The alternative — three separateStatTstructs — would inevitably diverge.fat16/fat32are already wrappers aroundfat12.FileSystem; their public types are already aliases. AddingStatTas an alias is consistent withSectorSize, not a new pattern.Fields
All populated from data
parseDirEntriesalready extracts today; no new parsing.ReadOnly booldirectoryEntry.isReadOnlyHidden booldirectoryEntry.isHiddenSystem booldirectoryEntry.isSystemArchive booldirectoryEntry.isArchiveDirtyVolumeLabel booldirectoryEntry.isVolumeLabelCreateTime time.TimedirectoryEntry.createTimeAccessTime time.TimedirectoryEntry.accessTime(date-only per FAT spec)Cluster uint32directoryEntry.clusterLocationTests
New
TestFat12StatSyswrites a file to a freshly-created FAT12 image, assertsSys()returns*fat12.StatT,Cluster >= 2(data clusters start at 2),VolumeLabel == false, and that no unexpected attribute bits are set on a regular file. Coverage extends to fat16/fat32 automatically because they reuse the samedirectoryEntry.Info()andFile.Stat()code paths.