Documentation
¶
Overview ¶
Package hfsplus is a pure-Go, CGO-free read/write driver for the HFS+ (Mac OS Extended) on-disk format, including its HFSX (case-sensitive) variant.
HFS+ stores every multi-byte field big-endian. The volume header lives at byte offset 1024 and carries the block size, block counts, and the special fork descriptors for the catalog, extents-overflow, and allocation files. File and directory metadata live in the catalog B-tree, keyed by the parent CNID plus the UTF-16 node name; file contents are addressed by allocation blocks via up to eight inline extents per fork, spilling into the extents-overflow B-tree for fragmented files.
The package implements the full shared github.com/go-filesystems/interface Filesystem contract:
- Open / OpenFile open a volume read-only.
- OpenWritable / OpenFileWritable open it for read/write, in place: no copy of the image is held, and each mutation writes only what it changed.
- Format (and the lower-level Mkfs) lay down a fresh, empty HFS+/HFSX volume in pure Go — no host tooling — that passes fsck_hfs -n clean and mounts read/write on macOS.
- WriteFile, MkDir, DeleteFile, DeleteDir, Rename mutate the catalog B-tree (insert/delete with node splitting and tree-height growth), manage the allocation bitmap, and keep the volume-header counters in sync. The optional Labeller (SetLabel), Symlinker (Symlink), and Truncater (Truncate) capabilities are implemented too.
Every write path is validated against the native macOS tooling: fsck_hfs -n reports the volume clean and macOS mounts the image read/write and reads the exact files and bytes the Go side wrote, in both directions (Go-formatted → macOS-read and macOS-created → Go-written → macOS-read). The cross-arch, big-endian (s390x) round-trip runs in pure Go on every architecture.
Case-folding: case-insensitive name comparison implements Apple's FastUnicodeCompare for the practical character set (ASCII, Latin-1, Latin Extended-A, and the ignorable-NUL handling fsck requires) rather than embedding the full 8 KiB fold table; exotic case-folding corner cases outside that range fall back to identity ordering.
Out of scope (deliberate non-goals, as with the btrfs/xfs siblings):
- Journaling, decmpfs compression, resource forks, and indirect-node hardlink following are not implemented; see the README Status section. A journaled volume with an empty journal is written directly; one with transactions in its journal is refused read/write with ErrJournaled.
Fragmented data forks (more than eight extents), catalog and extents-overflow B-tree growth, and node-underflow rebalancing/merging on delete ARE implemented: a written fork fills its eight inline extents and spills the remainder into the extents-overflow tree, the B-tree files grow their backing forks when their node reservation is exhausted, and deletion rebalances/merges underflowing nodes and frees emptied ones.
Index ¶
- Constants
- Variables
- func Format(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
- func FormatAppleDmg(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
- func Mkfs(sizeBytes int64, cfg FormatConfig) ([]byte, error)
- func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
- type Durability
- type FormatConfig
- type OpenOption
- type ReadWriteSyncerAt
- type TimeRangeError
- type Volume
- func Open(rs io.ReaderAt, size int64, opts ...OpenOption) (*Volume, error)
- func OpenFile(path string, opts ...OpenOption) (*Volume, error)
- func OpenFileWritable(path string) (*Volume, error)
- func OpenWritable(img []byte, wa io.WriterAt) (*Volume, error)
- func OpenWritableAt(rw ReadWriteSyncerAt, size int64) (*Volume, error)
- func (v *Volume) Batch(fn func() error) error
- func (v *Volume) Bytes() []byte
- func (v *Volume) CaseSensitive() bool
- func (v *Volume) Chmod(p string, perm os.FileMode) error
- func (v *Volume) Chown(p string, uid, gid uint32) error
- func (v *Volume) Chtimes(p string, atime, mtime time.Time) error
- func (v *Volume) Close() error
- func (v *Volume) DeleteDir(p string) error
- func (v *Volume) DeleteFile(p string) error
- func (v *Volume) Durability() Durability
- func (v *Volume) EnableJournalWrites() error
- func (v *Volume) FinderInfo(p string) ([finderInfoLen]byte, error)
- func (v *Volume) JournalWritesReason() error
- func (v *Volume) Label() string
- func (v *Volume) ListDir(path string) ([]filesystem.DirEntry, error)
- func (v *Volume) MkDir(p string, perm os.FileMode) error
- func (v *Volume) OpenFile(path string) (filesystem.File, error)
- func (v *Volume) ReadFile(path string) ([]byte, error)
- func (v *Volume) ReadLink(path string) (string, error)
- func (v *Volume) Rename(oldPath, newPath string) error
- func (v *Volume) SetDurability(d Durability) error
- func (v *Volume) SetFinderInfo(p string, info [finderInfoLen]byte) error
- func (v *Volume) SetLabel(label string) error
- func (v *Volume) Stat(path string) (filesystem.Stat, error)
- func (v *Volume) Symlink(target, linkPath string) error
- func (v *Volume) Sync() error
- func (v *Volume) Times(path string) (filesystem.FileTimes, error)
- func (v *Volume) Truncate(p string, newSize int64) error
- func (v *Volume) VolumeHeader() *volumeHeader
- func (v *Volume) WriteFile(p string, data []byte, perm os.FileMode) error
Constants ¶
const ( // FinderFlagHasCustomIcon marks a folder or volume as carrying its own // icon — for a volume root, that is what makes the Finder look for // .VolumeIcon.icns and draw it instead of the generic disk. Writing the // file without the flag does nothing at all. FinderFlagHasCustomIcon = uint16(0x0400) // FinderFlagIsInvisible hides an entry, which is how a disk image keeps // its .background folder out of the window it decorates. FinderFlagIsInvisible = uint16(0x4000) )
Finder flags worth naming. The rest are documented in TN1150 and in CarbonCore/Finder.h; these are the ones a disk-image builder needs.
const ( // FinderFlagsOffset is where the flags word lives inside the 32 bytes // FinderInfo returns: DInfo.frFlags for a folder, FInfo.fdFlags for a // file. Big-endian, like everything else in HFS+. FinderFlagsOffset = 8 )
The Finder's own 32 bytes, which every catalog record carries and which nothing here could read or write until now.
HFS+ (Apple TN1150) puts them at the same place in both record kinds: a 16-byte userInfo at record offset 48 followed by a 16-byte finderInfo at 64. For a file those are FInfo/FXInfo, for a folder DInfo/DXInfo, and the two differ in what the first eight bytes mean — but the FLAGS word sits at +8 of userInfo either way, so it is addressable without knowing which kind a record is.
Variables ¶
var ( // ErrReadOnly is returned by every mutating method when the volume was // opened read-only (Open / OpenFile). Open it writable (OpenWritable / // OpenFileWritable / Format) to mutate it. ErrReadOnly = errors.New("hfsplus: filesystem is read-only") // ErrClosed is returned by every mutating method of a writable volume after // Close. ErrClosed = errors.New("hfsplus: volume is closed") // ErrVolumeFailed is returned by every mutating method of a writable volume // after a write or fsync to its backing store failed. What reached the disk is // then unknown (some B-tree sectors written, the headers not), so no further // mutation is attempted -- one would write over a half-written volume and mark // it cleanly unmounted. Close it and open it again; reads still work. ErrVolumeFailed = errors.New("hfsplus: an earlier write failed; reopen the volume") // ErrBadHeader is returned when the volume header at offset 1024 lacks a // recognized HFS+ ("H+") or HFSX ("HX") signature. ErrBadHeader = errors.New("hfsplus: no valid volume header") // ErrNotFound is returned when a path component cannot be located in the // catalog. ErrNotFound = fmt.Errorf("hfsplus: path not found: %w", iofs.ErrNotExist) // ErrNotDirectory is returned when ListDir targets a non-directory. ErrNotDirectory = errors.New("hfsplus: not a directory") // ErrNotRegular is returned when ReadFile targets a non-regular file. ErrNotRegular = errors.New("hfsplus: not a regular file") // ErrNotSymlink is returned by ReadLink when the target is not a symlink. ErrNotSymlink = errors.New("hfsplus: not a symbolic link") // ErrCorrupt is returned when an on-disk structure fails a sanity check. ErrCorrupt = errors.New("hfsplus: corrupt image") // ErrUnsupported is returned for on-disk features the driver does not yet // decode/encode (e.g. compressed forks). ErrUnsupported = errors.New("hfsplus: unsupported feature") // ErrNoSpace is returned by the write path when the volume has no free // allocation blocks (or no contiguous run) to satisfy a request. ErrNoSpace = errors.New("hfsplus: no space left on volume") // ErrExists is returned by mutators when the target path already exists. ErrExists = errors.New("hfsplus: path already exists") // ErrNotEmpty is returned by DeleteDir when the directory still has // children. ErrNotEmpty = errors.New("hfsplus: directory not empty") )
Sentinel errors. Compare with errors.Is so wrapped errors keep matching.
var ErrJournalReplay = fmt.Errorf("%w: journal cannot be replayed", ErrJournaled)
ErrJournalReplay is returned when a journal that holds transactions cannot be replayed: the kernel would abandon it (hfs_journal.c, bad_replay), or a size in it is outside the bounds the replayer accepts. It wraps ErrJournaled.
ErrJournalWritesUnavailable is returned by EnableJournalWrites when the volume cannot be written through its journal. The volume stays usable and keeps writing directly.
var ErrJournaled = errors.New("hfsplus: journaled volume with a journal that is not empty")
ErrJournaled is returned by OpenWritable / OpenFileWritable for a journaled volume whose journal is not provably empty: it holds transactions macOS would replay over the driver's writes, or its journal cannot be read, is on another device, or fails its checksum. Open it read-only, or let macOS replay it (mount and unmount the volume) first.
var ErrReplayBudget = fmt.Errorf("%w: replayed blocks exceed the replay memory budget", ErrJournalReplay)
ErrReplayBudget is returned when the blocks a journal would replay exceed this driver's own resource bound, min(journal size, 256 MiB). The kernel has no such bound (it streams blocks to the device); it protects the memory of a process that replays an untrusted journal into an overlay. It wraps ErrJournalReplay.
var ErrSyncUnsupported = fmt.Errorf("hfsplus: the backing store has no Sync, so durability cannot be promised: %w", errors.ErrUnsupported)
ErrSyncUnsupported is what Sync returns when the volume's backing store is writable but has no Sync of its own. It wraps errors.ErrUnsupported, the way fsync(2) answers EINVAL for an object that cannot be synchronised. A caller that only wants the data written, not durable, may treat errors.Is(err, ErrSyncUnsupported) as success.
var ErrTimeOutOfRange = errors.New("hfsplus: time outside the HFS+ range 1904-2040")
ErrTimeOutOfRange is what Chtimes returns, wrapped in a *TimeRangeError, for a time a catalog date cannot hold: an unsigned 32-bit count of seconds since 1904-01-01 00:00:00 GMT, so 1904-01-01 00:00:01 .. 2040-02-06 06:28:15 GMT. The value 0 (1904-01-01 00:00:00 itself) means "not recorded" to a reader, so it is refused too rather than written as a date that reads back as none.
var ErrVolumeSize = errors.New("hfsplus: image size does not match the volume")
ErrVolumeSize is returned by the writable opens when the size given for the image does not fit the volume it holds: smaller than the volume says it is, or with no volume header where the alternate header must be. Nothing is written in that case; a write at the wrong place would land inside the volume.
Functions ¶
func Format ¶
func Format(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
Format creates a fresh, empty HFS+ (or HFSX) volume image at path of sizeBytes bytes using the pure-Go formatter (Mkfs), then opens it read/write. Pure Go, CGO-free, big-endian — works on every architecture.
The produced image passes `fsck_hfs -n` clean on macOS and mounts read/write; on every platform Open/OpenWritable round-trip it. The returned Volume is writable: WriteFile/MkDir/DeleteFile/DeleteDir/Rename mutate it and flush back to path.
The signature matches the apfs sibling (Format(path, sizeBytes, cfg)).
func FormatAppleDmg ¶
func FormatAppleDmg(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
FormatAppleDmg is the optional darwin-only alternative that shells out to the native hdiutil to author a real HFS+ image (the same tool that produced the read-path fixtures). It is provided as a parity escape hatch alongside the primary pure-Go Format, mirroring the apfs sibling's FormatAppleDmg. On non-darwin platforms it returns ErrUnsupported.
func Mkfs ¶
func Mkfs(sizeBytes int64, cfg FormatConfig) ([]byte, error)
Mkfs lays down a valid empty HFS+/HFSX volume of sizeBytes bytes into a freshly-allocated byte slice and returns it. Pure Go, big-endian, no host tooling — runs on every architecture. The returned image passes fsck_hfs -n on macOS and can be opened with Open/OpenWritable.
func OpenReader ¶ added in v0.3.0
func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
OpenReader opens the HFS+ volume at the start of r, exactly as Open does, and returns it as a filesystem.Filesystem.
It exists so every driver in go-filesystems answers to ONE name for the same thing. github.com/go-filesystems/detect's Opener is func(io.ReaderAt, int64) (filesystem.Filesystem, error): Open here is the right shape but returns a concrete *Volume, which is a different type and does not fit. The drivers that could only be opened from a PATH have grown this function; this one is that same function, so a caller can write
detect.Register(detect.T, driver.OpenReader)
for every driver instead of a closure per driver.
The concrete type is still there for a caller that wants what it has beyond the common interface: Open returns it.
Types ¶
type Durability ¶ added in v0.12.0
type Durability int
Durability says when a mutation of a writable volume is on the medium and what the volume looks like to fsck if the machine dies meanwhile (hfsplus#35).
Every level keeps the one guarantee the format needs: a volume whose header still says "cleanly unmounted" (kHFSVolumeUnmountedBit, and not journaled) is consistent. They differ in how many barriers (fsync, which on macOS is F_FULLFSYNC: Go's File.Sync) a commit pays and in when the header says so again.
const ( // DurabilityStrict is the default and the strongest: every commit is durable // when its mutator returns, and the volume is marked cleanly unmounted again // between commits, so a crash at ANY point outside a commit leaves a volume // fsck_hfs -q passes. Cost: three barriers per commit on a volume that was // clean when opened (data and the cleared bit; B-tree and bitmap sectors; // alternate and primary header). On a journaled volume whose journal passes the // checks (the default, see JournalWritesReason) a commit is a journal // transaction instead: one barrier, two for a session's first. DurabilityStrict Durability = iota // DurabilityMounted behaves like a mounted HFS+ volume: the first commit // marks the volume as not cleanly unmounted (one barrier), later commits write // everything and take ONE barrier, and the clean mark is restored by Sync, // Close or SetDurability(DurabilityStrict). Each commit is durable when its // mutator returns, but a crash between Syncs leaves the volume marked dirty // (the next mount runs fsck_hfs, which finds nothing to repair unless a commit // was torn). Nothing inside the metadata of a commit is ordered: the dirty // mark is what protects it. Data is ordered (like ext4 data=ordered): a // commit that wrote file data takes a barrier between the data and the // metadata that points at it, so a crash never shows a file holding bytes it // was not written with; a commit without data takes one barrier. The // journaled bit stays cleared for the whole held span, so after a crash in it // the journal stays off until diskutil enableJournal. None of this applies on a // journaled volume written through its journal (the default, see // JournalWritesReason): there Mounted is the journal commit, the same as Strict, // and the volume is never held dirty. A commit that cannot be journaled (see the // list in journal_writer.go) takes the Strict direct path at Mounted too, bracketed // and three barriers, so the volume is not held dirty while it journals. DurabilityMounted // DurabilityLazy is DurabilityMounted without the per-commit barrier: a // mutation is durable only after Sync, Close or a switch to another level // (Batch does this for a group of mutations). A crash before that loses the // mutations made since the last Sync. // // On a journaled volume written through its journal (the default) Lazy is a // GROUP COMMIT: a commit writes nothing and pays no barrier, its sectors (and // small file data) are kept in memory, and Sync, Close, a switch away from Lazy, // Bytes (an in-memory volume only) or the group's size bound write them as ONE journal transaction (one barrier, // two for a session's first; a Sync right after pays one more for the flush's in-place // writes, then none). The volume is never // marked dirty, a crash leaves the volume as of the last flush (a prefix of whole // commits), and the stale-data exposure below does not exist: data written in // place goes only into blocks no durable state references, ordered by a barrier // before the transaction. The memory held is bounded by the journal's data bound // (see journal_group.go): at most min(1 MiB, journal/8) of sectors, 30 runs and // 4096 freed spans. // // On every other volume it is data-writeback: the volume is held dirty, nothing // orders file data before the metadata that references it, and after a crash a // file may contain stale bytes of a previously deleted file. Do not use it there // where different users share a volume. DurabilityLazy )
func (Durability) String ¶ added in v0.12.0
func (d Durability) String() string
String names the level.
type FormatConfig ¶
type FormatConfig struct {
// Label is the volume name. Defaults to "GOTEST" when empty.
Label string
// CaseSensitive requests an HFSX (case-sensitive) volume instead of plain
// case-insensitive HFS+.
CaseSensitive bool
}
FormatConfig configures Format/Mkfs.
type OpenOption ¶ added in v0.13.0
type OpenOption func(*openConfig)
OpenOption configures Open and OpenFile.
func WithJournalReplay ¶ added in v0.13.0
func WithJournalReplay() OpenOption
WithJournalReplay makes Open replay a non-empty journal in memory (see replay.go). The volume stays read-only and the backing store is not written; OpenWritable and its variants still return ErrJournaled for such a volume. The size passed to Open must be known (not -1). A journal the replayer refuses makes Open fail with ErrJournalReplay.
type ReadWriteSyncerAt ¶ added in v0.11.0
ReadWriteSyncerAt is the store OpenWritableAt reads and writes in place: an *os.File satisfies it, and so does a block device or any other random-access store. Sync is part of it because the order in which a commit reaches the medium (data, then B-tree and bitmap sectors, then the headers) is only a guarantee if each stage is made durable before the next begins.
type TimeRangeError ¶ added in v0.8.0
type TimeRangeError struct {
Field string // "atime", "mtime" or "now" (the clock, for attributeModDate)
Time time.Time
}
TimeRangeError names the field and the value Chtimes refused.
func (*TimeRangeError) Error ¶ added in v0.8.0
func (e *TimeRangeError) Error() string
func (*TimeRangeError) Unwrap ¶ added in v0.8.0
func (e *TimeRangeError) Unwrap() error
type Volume ¶
type Volume struct {
// contains filtered or unexported fields
}
Volume is an opened HFS+ (or HFSX) volume. When opened read-only (Open / OpenFile) the mutating methods return ErrReadOnly. When opened writable (OpenWritable / OpenFileWritable / Format) the image is read and written in place: nothing but the structures one mutation touches is held in memory, and each mutation writes only the sectors it changed (see store.go).
func Open ¶
Open parses an HFS+ volume from rs. The caller retains ownership of rs unless it implements io.Closer (then Close releases it). Pass size = -1 if unknown.
WithJournalReplay serves a journaled volume whose journal holds transactions as macOS would see it after replaying them, read-only and without writing anything to rs.
func OpenFile ¶
func OpenFile(path string, opts ...OpenOption) (*Volume, error)
OpenFile opens the image at path read-only.
func OpenFileWritable ¶
OpenFileWritable opens the image at path for read/write, in place: the image is not copied into memory. Each mutation reads what it needs from the file and writes back only what it changed (see store.go); the mutators sync as they go.
func OpenWritable ¶
OpenWritable opens an HFS+ image held entirely in img for read/write. The volume edits img in place; callers can retrieve the mutated bytes with Bytes() or, if wa is non-nil, flush them with Sync. Pass wa = nil for a purely in-memory writable volume.
A journaled volume whose journal holds transactions and whose lastMountedVersion is 'HFSJ' is replayed first (replay_write.go): the blocks, a barrier, the empty journal header, a barrier. If wa is non-nil the replay is written to it too.
func OpenWritableAt ¶ added in v0.11.0
func OpenWritableAt(rw ReadWriteSyncerAt, size int64) (*Volume, error)
OpenWritableAt opens the size-byte HFS+ image held by rw for read/write, in place, exactly as OpenFileWritable does: no copy of the image is made, a journaled volume whose journal holds transactions is replayed first if its lastMountedVersion is 'HFSJ' (replay_write.go) and refused with ErrJournaled if it is not, and every mutation reads what it needs from rw and writes back only what it changed (see store.go).
It exists so a caller that already holds the image open -- an *os.File it opened itself, with the checks it needs (an os.Root, O_NOFOLLOW, a descriptor passed in) -- is not made to reopen it by name, which another process can swap in between.
Ownership: rw belongs to the caller. Volume.Close does NOT close it, even if it implements io.Closer; the caller closes it, after the last use of the Volume and not before (the Volume reads and writes through it until then). size is the number of bytes of the image (the volume's alternate header is 1024 bytes before its end), usually the file's size; it must be positive. Use only one writable Volume at a time over a store: two would each keep their own view of it.
func (*Volume) Batch ¶ added in v0.12.0
Batch runs fn with DurabilityLazy, then makes everything fn wrote durable with one Sync and restores the previous level: a group of mutations pays one set of barriers instead of one per mutation (an SMB request that writes and sets times, say).
On a journaled volume written through its journal, a Batch whose mutations fit one group (the bounds on DurabilityLazy) is ATOMIC: after a crash the volume shows all of it or none of it, file bytes included. A larger Batch is a sequence of groups made of whole mutations: a crash leaves a prefix of the mutations, never part of one (an overwrite's delete and create are one mutation: a group is never flushed between them). The one exception is a single mutation too large for even an empty group, which is as torn as it is on DurabilityStrict. On any other volume it is not a transaction: the mutations may be partly lost and the volume is left marked dirty, with DurabilityLazy's data-writeback exposure.
If fn fails, the mutations it already made stay and are committed by the Sync (they are not rolled back); fn's error is returned in preference to Sync's. Like SetDurability, it must not run concurrently with mutators.
func (*Volume) Bytes ¶
Bytes returns the current (possibly mutated) image bytes of a volume opened with OpenWritable over a []byte, or nil for any other volume (read-only, or file-backed, which holds no copy of the image). The slice aliases the volume's buffer; copy it if you need a stable snapshot. On a journaled volume at DurabilityLazy the commits not yet written (the open group, journal_group.go) are flushed first, as one journal transaction, so the image is current; a failure of that flush latches like any other write failure and shows in the next call that returns an error.
func (*Volume) CaseSensitive ¶
CaseSensitive reports whether the volume is HFSX with binary key comparison.
func (*Volume) Chmod ¶ added in v0.8.0
Chmod replaces the permission bits (including setuid, setgid and sticky) of the file or folder at path, keeping the file-type bits of fileMode. ctime (attributeModDate) is set to the clock. The root folder is refused, as it is for Chtimes.
func (*Volume) Chown ¶ added in v0.8.0
Chown sets ownerID and groupID of the file or folder at path (HFSPlusBSDInfo, stored as given). ctime (attributeModDate) is set to the clock; mode, body and the other dates are left alone.
func (*Volume) Chtimes ¶ added in v0.8.0
Chtimes sets the access and modification times of path (Apple TN1150, "HFS Plus Dates" and "Catalog File Data Records").
- mtime is the record's contentModDate and atime its accessDate, each a GMT count of whole seconds since 1904, rounded down.
- attributeModDate (what Times reports as Ctime) is set to the current time, as POSIX utimes refreshes ctime. createDate (Btime) is untouched.
A zero time.Time leaves that field unchanged; with both zero nothing is touched at all, ctime included. A time outside 1904-01-01 00:00:01 .. 2040-02-06 06:28:15 GMT is refused with a *TimeRangeError (errors.Is ErrTimeOutOfRange) before anything is written. The root folder is not served by Times and is refused here too.
The record is patched in place in its catalog leaf node (the length does not change, so no node is split or merged and the B-tree stays valid), then the image is committed like every other mutation.
func (*Volume) Close ¶
Close releases the backing handle if Volume opened one.
After Close a writable volume refuses every mutation with ErrClosed, and its cache and edit state are dropped. A store given to OpenWritableAt is not closed (it is the caller's).
func (*Volume) DeleteFile ¶
DeleteFile removes the regular file (or symlink) at path.
func (*Volume) Durability ¶ added in v0.12.0
func (v *Volume) Durability() Durability
Durability returns the current level.
func (*Volume) EnableJournalWrites ¶ added in v0.15.0
EnableJournalWrites turns journal writes on (see the comment at the top of journal_writer.go). The writable opens already call it, so a caller needs it only to retry after an open that fell back; it is a no-op when journal writes are already on. It returns ErrJournalWritesUnavailable, with the reason, when the volume is not journaled or its journal fails the checks of section 4; the volume then keeps writing directly, unchanged. It must be called on a writable volume, between mutations, and the journal must be empty (a non-empty one is replayed at open, see replay_write.go).
func (*Volume) FinderInfo ¶ added in v0.2.0
FinderInfo returns the 32 Finder bytes of the entry at p.
p may be "/" for the volume root, which is the case that matters for a volume icon.
func (*Volume) JournalWritesReason ¶ added in v0.18.0
JournalWritesReason reports why the volume writes directly instead of through its journal: nil when journal writes are on, ErrReadOnly for a read-only volume, otherwise an error wrapping ErrJournalWritesUnavailable that says which check failed (not journaled, journal never initialised, a writer that cannot Sync, ...). A non-journaled volume always answers that error: it is the expected case, not a fault.
func (*Volume) ListDir ¶
func (v *Volume) ListDir(path string) ([]filesystem.DirEntry, error)
ListDir enumerates the directory at path.
func (*Volume) OpenFile ¶ added in v0.6.0
func (v *Volume) OpenFile(path string) (filesystem.File, error)
OpenFile opens the regular file at path for positional reads of its data fork. Nothing of the file is read here: each ReadAt reads only the extents of its own window (fork.readAt). A compressed file is ErrUnsupported, as in ReadFile.
func (*Volume) ReadLink ¶
ReadLink returns the target of a symbolic link. HFS+ stores the target as the data-fork contents of a file whose BSD mode marks it S_IFLNK.
func (*Volume) Rename ¶
Rename moves/renames oldPath to newPath. Both parents must exist; newPath must not already exist. The data fork and CNID are preserved (catalog key change + thread parent/name update).
func (*Volume) SetDurability ¶ added in v0.12.0
func (v *Volume) SetDurability(d Durability) error
SetDurability selects the level for the following mutations. Leaving a level that holds the volume dirty first settles it: everything written is made durable and, for DurabilityStrict, the clean mark is restored. It returns the error of that settling, and the level is unchanged when it fails. Like every mutator, it must not run concurrently with another mutator, Sync, Batch or Close.
func (*Volume) SetFinderInfo ¶ added in v0.2.0
SetFinderInfo replaces the 32 Finder bytes of the entry at p.
The record is re-keyed rather than patched in place, because the catalog is a B-tree and its writer owns node layout; delete-then-insert with the same key is how SetLabel already does it.
func (*Volume) SetLabel ¶
SetLabel renames the volume. The label lives as the root folder's catalog key (parent=1, name=label); SetLabel rewrites that key (and the root thread name) and is reflected by the reader and by macOS.
func (*Volume) Stat ¶
func (v *Volume) Stat(path string) (filesystem.Stat, error)
Stat resolves path and returns mode, size, and the CNID as a pseudo-inode.
func (*Volume) Symlink ¶
Symlink creates a symbolic link at linkPath pointing at target. HFS+ stores the target as the data fork of an S_IFLNK file.
func (*Volume) Sync ¶
Sync makes what the volume has written durable. Every mutator has already written its changes (data, then B-trees and bitmap, then the alternate and the primary volume header, with an fsync after each stage), so this is a final fsync; it is a no-op for read-only or purely in-memory volumes.
Over a writable backing store that has no Sync of its own (an OpenWritable wa that is a bare io.WriterAt), nothing can be made durable and Sync returns ErrSyncUnsupported instead of nil (it used to say nil, which a fsync-failure latch above could not tell from a real flush). A volume with no backing store (wa nil, the caller reads Bytes) or opened read-only still returns nil. Close, SetDurability and Batch settle through sync, which keeps that supported no-Sync path working.
func (*Volume) Times ¶ added in v0.7.0
func (v *Volume) Times(path string) (filesystem.FileTimes, error)
Times returns the times recorded in the catalog record of path.
- Btime is createDate, Mtime is contentModDate, Ctime is attributeModDate (Mac OS X's BSD layer returns it as st_ctime), Atime is accessDate.
- All are GMT in catalog records, resolution 1 s. (Only the Volume Header's createDate is local time, per TN1150; it is not used here.)
- A date of 0 is reported as not recorded: TN1150 says traditional Mac OS leaves accessDate at zero, and attributeModDate "may be treated as reserved" by an implementation.
- The root folder is synthesised by this reader without its catalog record, so none of its times are recorded. Symbolic links are not followed.
func (*Volume) Truncate ¶
Truncate resizes the regular file at path to newSize bytes. Growing reallocates a larger contiguous run (zero-filled); shrinking reallocates a smaller run. Both rewrite the file's single inline extent.
func (*Volume) VolumeHeader ¶
func (v *Volume) VolumeHeader() *volumeHeader
VolumeHeader exposes the decoded volume header (owned by Volume).
func (*Volume) WriteFile ¶
WriteFile creates or overwrites the regular file at path with data. The data fork is allocated across the volume's free allocation blocks: a single contiguous run when one is available, otherwise multiple fragments. The first numInlineExtents runs are stored in the inline extent descriptors and any remaining runs are inserted into the extents-overflow B-tree, so an arbitrarily fragmented file (more than numInlineExtents extents) round-trips correctly.
Source Files
¶
- alloc.go
- btdelete.go
- btgrow.go
- btmap.go
- btops.go
- btree.go
- btwrite.go
- catalog.go
- catalog_search.go
- catwrite.go
- chmod.go
- durability.go
- errors.go
- extents.go
- extwrite.go
- finderinfo.go
- fork.go
- format.go
- format_other.go
- hfsplus.go
- journal.go
- journal_data.go
- journal_group.go
- journal_writer.go
- mkfs.go
- openfile.go
- openreader.go
- replay.go
- replay_write.go
- store.go
- times.go
- times_set.go
- volume.go
- write.go
