fat

package
v0.0.0-...-7bae45d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2016 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrReadOnly  DirectoryAttr = 0x01
	AttrHidden                  = 0x02
	AttrSystem                  = 0x04
	AttrVolumeId                = 0x08
	AttrDirectory               = 0x10
	AttrArchive                 = 0x20
	AttrLongName                = AttrReadOnly | AttrHidden | AttrSystem | AttrVolumeId
)
View Source
const DirectoryEntrySize = 32

The size in bytes of a single directory entry.

View Source
const FirstCluster = 2

The first cluster that can really hold user data is always 2

View Source
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
}

func (*ClusterChain) Read

func (c *ClusterChain) Read(p []byte) (n int, err error)

func (*ClusterChain) Write

func (c *ClusterChain) Write(p []byte) (n int, err error)

Write will write to the cluster chain, expanding it if necessary.

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

func (d *Directory) AddDirectory(name string) (fs.DirectoryEntry, error)

func (*Directory) AddFile

func (d *Directory) AddFile(name string) (fs.DirectoryEntry, error)

func (*Directory) Entries

func (d *Directory) Entries() []fs.DirectoryEntry

func (*Directory) Entry

func (d *Directory) Entry(name string) fs.DirectoryEntry

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 the underlying directory entry data structures on the disk may be more than one to accomodate 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 DecodeFAT

func DecodeFAT(device fs.BlockDevice, bs *BootSectorCommon, n int) (*FAT, error)

func NewFAT

func NewFAT(bs *BootSectorCommon) (*FAT, error)

NewFAT creates a new FAT data structure, properly initialized.

func (*FAT) AllocChain

func (f *FAT) AllocChain() (uint32, error)

func (*FAT) Bytes

func (f *FAT) Bytes() []byte

Bytes returns the raw bytes for the FAT that should be written to the block device.

func (*FAT) Chain

func (f *FAT) Chain(start uint32) []uint32

Chain returns the chain of clusters starting at a certain cluster.

func (*FAT) ResizeChain

func (f *FAT) ResizeChain(start uint32, length int) ([]uint32, error)

ResizeChain takes a given cluster number and resizes the chain to the given length. It returns the new chain of clusters.

func (*FAT) WriteToDevice

func (f *FAT) WriteToDevice(device fs.BlockDevice) error

type FATType

type FATType uint8

FATType is a simple enum of the available FAT filesystem types.

const (
	FAT12 FATType = iota
	FAT16
	FAT32
)

func TypeForDevice

func TypeForDevice(device fs.BlockDevice) FATType

TypeForDevice determines the usable FAT type based solely on size information about the block device.

type File

type File struct {
	// contains filtered or unexported fields
}

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL