Documentation
¶
Index ¶
- Constants
- Variables
- func Format(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
- func FormatImage(rw ReaderWriterAt, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
- func Open(imagePath string, partIndex int) (filesystem.Filesystem, error)
- func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
- type FormatConfig
- type Info
- type ReaderWriterAt
- type TimeRangeError
Constants ¶
const MaxLabelLen = 11
MaxLabelLen is the maximum number of UTF-16 code units storable in the exFAT Volume Label entry (per the exFAT specification §7.3).
Variables ¶
var ErrNotSupported = fmt.Errorf("exfat: the format has no POSIX mode bits or owners: %w", errors.ErrUnsupported)
ErrNotSupported is what Chmod and Chown return: exFAT records no owner and no POSIX mode bits (only the read-only, hidden, system and archive attributes), so there is nothing to store. It wraps errors.ErrUnsupported.
var ErrReadOnlyReader = errors.New("exfat: this filesystem was opened over a reader that cannot be written")
ErrReadOnlyReader is what a write gets when the filesystem was opened over something that can only be read.
var ErrSyncUnsupported = fmt.Errorf("exfat: 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 (an in-memory image, a caller's bare io.WriterAt). It wraps errors.ErrUnsupported, the way fsync(2) answers EINVAL for an object that cannot be synchronised: the caller learns that durability was NOT established instead of being told it was. A caller that only wants the data written, not durable, may treat it as success with errors.Is(err, ErrSyncUnsupported).
var ErrTimeOutOfRange = errors.New("exfat: time outside the exFAT range 1980-2107")
ErrTimeOutOfRange is what Chtimes returns, wrapped in a *TimeRangeError, for a time the exFAT Timestamp field cannot hold: a 7-bit year counted from 1980, so the representable years are 1980..2107. The driver never clamps.
Functions ¶
func Format ¶
func Format(path string, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
Format creates a new exFAT filesystem in the file at path. The file is created (or truncated) and formatted. sizeBytes must be a multiple of the cluster size (4096) and large enough to hold the metadata region plus at least one data cluster.
On success the newly formatted filesystem is opened and returned; the caller must Close it when done.
func FormatImage ¶ added in v0.7.0
func FormatImage(rw ReaderWriterAt, sizeBytes int64, cfg FormatConfig) (filesystem.Filesystem, error)
FormatImage creates a new exFAT filesystem in the first sizeBytes of rw and opens it, with the same layout and size rules as Format.
It is Format without a path: for a caller that has no host file to give -- an encrypted volume, a WebAssembly page building an image in memory, a test, a partition inside a larger image. rw must already hold at least sizeBytes (a shorter one is refused); FormatImage never grows it, and writes no file on disk.
Unlike Format, which writes a file it has just truncated, FormatImage cannot assume rw reads back as zeros. It therefore writes zeros over every region an exFAT reader interprets -- the boot regions, the FAT, the allocation bitmap, the up-case table and the root directory cluster -- so a reused buffer holding an older volume does not leak entries into the new one. Data clusters past the root directory are left as they are: they are free in the new bitmap, and nothing reads a free cluster. An image formatted this way is byte-identical to the file Format produces for the same size and cfg, in every byte that region covers.
The returned filesystem reads and writes through rw (see OpenReader); it does not close rw.
func Open ¶
func Open(imagePath string, partIndex int) (filesystem.Filesystem, error)
Open opens imagePath, optionally selecting a partition, and parses the exFAT boot sector.
func OpenReader ¶ added in v0.4.0
func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
OpenReader opens the exFAT filesystem that starts at offset zero of r.
It exists so this driver fits the one shape the rest of go-filesystems agrees on: github.com/go-filesystems/detect's Opener is func(io.ReaderAt, int64) (filesystem.Filesystem, error), and until now this driver could only be opened from a PATH. A caller with an image already open -- a partition inside a disk image, a section of a larger file, an image in memory -- had to write it to a temporary file first, and detect.Register could not be given this driver at all.
There is no partition index: r is expected to begin at the filesystem, which is what detect has just established by reading the magic there. Open remains the way to look through a partition table.
WRITES need an io.WriterAt. A reader that is only a reader gives a filesystem that serves every read and refuses every write with ErrReadOnlyReader -- rather than one that accepts a write and loses it.
The reader is NOT closed by Close: the caller opened it and still owns it. That is the same division as iso9660, squashfs, hfsplus and ufs, whose reader-based constructors have always worked this way.
Types ¶
type FormatConfig ¶
type FormatConfig struct {
// Label is the volume label (stored as a volume-label directory entry;
// not in the boot sector for exFAT). Trimmed to 11 characters.
Label string
// VolumeSerialNumber is the 32-bit serial number. A random value is generated when zero.
VolumeSerialNumber uint32
}
FormatConfig holds optional parameters for Format. All fields are optional; sensible defaults are used when left at their zero value.
type Info ¶
type Info struct {
PartitionStartSector uint64
VolumeLength uint64
FATOffset uint32
FATLength uint32
ClusterHeapOffset uint32
ClusterCount uint32
RootDirectoryCluster uint32
VolumeSerialNumber uint32
FileSystemRevision uint16
VolumeFlags uint16
BytesPerSectorShift uint8
SectorsPerClusterShift uint8
NumberOfFATs uint8
DriveSelect uint8
PercentInUse uint8
}
Info holds the fields decoded from the exFAT main boot sector.
func (Info) BytesPerSector ¶
BytesPerSector returns the logical sector size in bytes.
func (Info) ClusterHeapOffsetBytes ¶
ClusterHeapOffsetBytes returns the absolute byte offset of the cluster heap.
func (Info) ClusterSize ¶
ClusterSize returns the allocation cluster size in bytes.
func (Info) FATOffsetBytes ¶
FATOffsetBytes returns the absolute byte offset of the first FAT.
func (Info) RootDirOffset ¶
RootDirOffset returns the absolute byte offset of the root directory cluster.
func (Info) SectorsPerCluster ¶
SectorsPerCluster returns the cluster size expressed in sectors.
type ReaderWriterAt ¶ added in v0.7.0
ReaderWriterAt is the image FormatImage formats: anything that can be read and written at an offset, such as a buffer in memory.
type TimeRangeError ¶ added in v0.6.0
TimeRangeError names the field and the value Chtimes refused.
func (*TimeRangeError) Error ¶ added in v0.6.0
func (e *TimeRangeError) Error() string
func (*TimeRangeError) Unwrap ¶ added in v0.6.0
func (e *TimeRangeError) Unwrap() error
