Documentation
¶
Index ¶
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 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.
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 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.
