Documentation
¶
Index ¶
- Constants
- func DecodeDirectoryEntry(d *Directory, entries []*DirectoryClusterEntry) (*DirectoryEntry, []*DirectoryClusterEntry, error)
- func FATEntryCount(bs *BootSectorCommon) uint32
- func FormatSuperFloppy(device fs.BlockDevice, config *SuperFloppyConfig) error
- type BootSectorCommon
- func (b *BootSectorCommon) Bytes() ([]byte, error)
- func (b *BootSectorCommon) BytesPerCluster() uint32
- func (b *BootSectorCommon) ClusterOffset(n int) uint32
- func (b *BootSectorCommon) DataOffset() uint32
- func (b *BootSectorCommon) FATOffset(n int) int
- func (b *BootSectorCommon) FATType() FATType
- func (b *BootSectorCommon) RootDirOffset() int
- type BootSectorFat16
- type BootSectorFat32
- type ClusterChain
- type Directory
- type DirectoryAttr
- type DirectoryCluster
- func DecodeDirectoryCluster(startCluster uint32, device fs.BlockDevice, fat *FAT) (*DirectoryCluster, error)
- func DecodeFAT16RootDirectoryCluster(device fs.BlockDevice, bs *BootSectorCommon) (*DirectoryCluster, error)
- func NewDirectoryCluster(start uint32, parent uint32, t time.Time) *DirectoryCluster
- func NewFat16RootDirectoryCluster(bs *BootSectorCommon, label string) (*DirectoryCluster, error)
- type DirectoryClusterEntry
- type DirectoryEntry
- type FAT
- type FATType
- type File
- type FileSystem
- type MediaType
- type SuperFloppyConfig
Constants ¶
const ( AttrReadOnly DirectoryAttr = 0x01 AttrHidden = 0x02 AttrSystem = 0x04 AttrVolumeId = 0x08 AttrDirectory = 0x10 AttrArchive = 0x20 AttrLongName = AttrReadOnly | AttrHidden | AttrSystem | AttrVolumeId )
const DirectoryEntrySize = 32
The size in bytes of a single directory entry.
const FirstCluster = 2
The first cluster that can really hold user data is always 2
const LastLongEntryMask = 0x40
Mask applied to the ord of the last long entry.
Variables ¶
This section is empty.
Functions ¶
func DecodeDirectoryEntry ¶
func DecodeDirectoryEntry(d *Directory, entries []*DirectoryClusterEntry) (*DirectoryEntry, []*DirectoryClusterEntry, error)
DecodeDirectoryEntry takes a list of entries, decodes the next full DirectoryEntry, and returns the newly created entry, the remaining entries, and an error, if there was one.
func FATEntryCount ¶
func FATEntryCount(bs *BootSectorCommon) uint32
FATEntryCount returns the number of entries per fat for the given boot sector.
func FormatSuperFloppy ¶
func FormatSuperFloppy(device fs.BlockDevice, config *SuperFloppyConfig) error
Formats an fs.BlockDevice with the "super floppy" format according to the given configuration. The "super floppy" standard means that the device will be formatted so that it does not contain a partition table. Instead, the entire device holds a single FAT file system.
Types ¶
type BootSectorCommon ¶
type BootSectorCommon struct { OEMName string BytesPerSector uint16 SectorsPerCluster uint8 ReservedSectorCount uint16 NumFATs uint8 RootEntryCount uint16 TotalSectors uint32 Media MediaType SectorsPerFat uint32 SectorsPerTrack uint16 NumHeads uint16 }
func DecodeBootSector ¶
func DecodeBootSector(device fs.BlockDevice) (*BootSectorCommon, error)
DecodeBootSector takes a BlockDevice and decodes the FAT boot sector from it.
func (*BootSectorCommon) Bytes ¶
func (b *BootSectorCommon) Bytes() ([]byte, error)
func (*BootSectorCommon) BytesPerCluster ¶
func (b *BootSectorCommon) BytesPerCluster() uint32
BytesPerCluster returns the number of bytes per cluster.
func (*BootSectorCommon) ClusterOffset ¶
func (b *BootSectorCommon) ClusterOffset(n int) uint32
ClusterOffset returns the offset of the data section of a particular cluster.
func (*BootSectorCommon) DataOffset ¶
func (b *BootSectorCommon) DataOffset() uint32
DataOffset returns the offset of the data section of the disk.
func (*BootSectorCommon) FATOffset ¶
func (b *BootSectorCommon) FATOffset(n int) int
FATOffset returns the offset in bytes for the given index of the FAT
func (*BootSectorCommon) FATType ¶
func (b *BootSectorCommon) FATType() FATType
Calculates the FAT type that this boot sector represents.
func (*BootSectorCommon) RootDirOffset ¶
func (b *BootSectorCommon) RootDirOffset() int
RootDirOffset returns the byte offset when the root directory entries for FAT12/16 filesystems start. NOTE: This is absolutely useless for FAT32 because the root directory is just the beginning of the data region.
type BootSectorFat16 ¶
type BootSectorFat16 struct { BootSectorCommon DriveNumber uint8 VolumeID uint32 VolumeLabel string FileSystemTypeLabel string }
BootSectorFat16 is the BootSector for FAT12 and FAT16 filesystems. It contains the common fields to all FAT filesystems and also some unique.
func (*BootSectorFat16) Bytes ¶
func (b *BootSectorFat16) Bytes() ([]byte, error)
type BootSectorFat32 ¶
type BootSectorFat32 struct { BootSectorCommon RootCluster uint32 FSInfoSector uint16 BackupBootSector uint16 DriveNumber uint8 VolumeID uint32 VolumeLabel string FileSystemTypeLabel string }
func (*BootSectorFat32) Bytes ¶
func (b *BootSectorFat32) Bytes() ([]byte, error)
type ClusterChain ¶
type ClusterChain struct {
// contains filtered or unexported fields
}
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory implements fs.Directory and is used to interface with a directory on a FAT filesystem.
func (*Directory) AddDirectory ¶
type DirectoryAttr ¶
type DirectoryAttr uint8
type DirectoryCluster ¶
type DirectoryCluster struct {
// contains filtered or unexported fields
}
DirectoryCluster represents a cluster on the disk that contains entries/contents.
func DecodeDirectoryCluster ¶
func DecodeDirectoryCluster(startCluster uint32, device fs.BlockDevice, fat *FAT) (*DirectoryCluster, error)
func DecodeFAT16RootDirectoryCluster ¶
func DecodeFAT16RootDirectoryCluster(device fs.BlockDevice, bs *BootSectorCommon) (*DirectoryCluster, error)
DecodeFAT16RootDirectory decodes the FAT16 root directory structure from the device.
func NewDirectoryCluster ¶
func NewDirectoryCluster(start uint32, parent uint32, t time.Time) *DirectoryCluster
func NewFat16RootDirectoryCluster ¶
func NewFat16RootDirectoryCluster(bs *BootSectorCommon, label string) (*DirectoryCluster, error)
NewFat16RootDirectory creates a new DirectoryCluster that is meant only to be the root directory of a FAT12/FAT16 filesystem.
func (*DirectoryCluster) Bytes ¶
func (d *DirectoryCluster) Bytes() []byte
Bytes returns the on-disk byte data for this directory structure.
func (*DirectoryCluster) WriteToDevice ¶
func (d *DirectoryCluster) WriteToDevice(device fs.BlockDevice, fat *FAT) error
WriteToDevice writes the cluster to the device.
type DirectoryClusterEntry ¶
type DirectoryClusterEntry struct {
// contains filtered or unexported fields
}
DirectoryClusterEntry is a single 32-byte entry that is part of the chain of entries in a directory cluster.
func DecodeDirectoryClusterEntry ¶
func DecodeDirectoryClusterEntry(data []byte) (*DirectoryClusterEntry, error)
DecodeDirectoryClusterEntry decodes a single directory entry in the Directory structure.
func NewLongDirectoryClusterEntry ¶
func NewLongDirectoryClusterEntry(name string, shortName string) ([]*DirectoryClusterEntry, error)
NewLongDirectoryClusterEntry returns the series of directory cluster entries that need to be written for a long directory entry. This list of entries does NOT contain the short name entry.
func (*DirectoryClusterEntry) Bytes ¶
func (d *DirectoryClusterEntry) Bytes() []byte
Bytes returns the on-disk byte data for this directory entry.
func (*DirectoryClusterEntry) IsLong ¶
func (d *DirectoryClusterEntry) IsLong() bool
IsLong returns true if this is a long entry.
func (*DirectoryClusterEntry) IsVolumeId ¶
func (d *DirectoryClusterEntry) IsVolumeId() bool
type DirectoryEntry ¶
type DirectoryEntry struct {
// contains filtered or unexported fields
}
DirectoryEntry implements fs.DirectoryEntry and represents a single file/folder within a directory in a FAT filesystem. Note that there may be more than one underlying directory entry data structure on the disk to account for long filenames.
func (*DirectoryEntry) Dir ¶
func (d *DirectoryEntry) Dir() (fs.Directory, error)
func (*DirectoryEntry) File ¶
func (d *DirectoryEntry) File() (fs.File, error)
func (*DirectoryEntry) IsDir ¶
func (d *DirectoryEntry) IsDir() bool
func (*DirectoryEntry) Name ¶
func (d *DirectoryEntry) Name() string
func (*DirectoryEntry) ShortName ¶
func (d *DirectoryEntry) ShortName() string
type FAT ¶
type FAT struct {
// contains filtered or unexported fields
}
FAT is the actual file allocation table data structure that is stored on disk to describe the various clusters on the disk.
func NewFAT ¶
func NewFAT(bs *BootSectorCommon) (*FAT, error)
NewFAT creates a new FAT data structure, properly initialized.
func (*FAT) AllocChain ¶
func (*FAT) Bytes ¶
Bytes returns the raw bytes for the FAT that should be written to the block device.
func (*FAT) ResizeChain ¶
ResizeChain takes a given cluster number and resizes the chain to the given length. It returns the new chain of clusters.
func (*FAT) WriteToDevice ¶
type FATType ¶
type FATType uint8
FATType is a simple enum of the available FAT filesystem types.
func TypeForDevice ¶
func TypeForDevice(device fs.BlockDevice) FATType
TypeForDevice determines the usable FAT type based solely on size information about the block device.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem is the implementation of fs.FileSystem that can read a FAT filesystem.
func New ¶
func New(device fs.BlockDevice) (*FileSystem, error)
New returns a new FileSystem for accessing a previously created FAT filesystem.
func (*FileSystem) RootDir ¶
func (f *FileSystem) RootDir() (fs.Directory, error)
type MediaType ¶
type MediaType uint8
const MediaFixed MediaType = 0xF8
The standard value for "fixed", non-removable media, directly from the FAT specification.
type SuperFloppyConfig ¶
type SuperFloppyConfig struct { // The type of FAT filesystem to use. FATType FATType // The label of the drive. Defaults to "NONAME" Label string // The OEM name for the FAT filesystem. Defaults to "gofs" if not set. OEMName string }
SuperFloppyConfig is the configuration for various properties of a new super floppy formatted block device. Once this configuration is used to format a device, it must not be modified.