gofat

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 12 Imported by: 0

README

GoFAT

A FAT filesystem implementation in Go.
It implements the interface of afero.

Current Status

Readonly File access works great. Write support is missing, yet.

Usage

// Get any io.ReadSeeker implementation which provides a reader to a FAT32 filesystem.
// You can use for example os.Open(...) to open an image file or even a `/dev/sdxy` device file from linux. 
var reader io.ReadSeeker = ...

// Then create a new gofat filesystem from the reader
fat, err := gofat.New(reader)
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}

// Now you can access any method from the afero.Fs filesystem like for example afero.Walk
afero.Walk(fat, "/", func(path string, info os.FileInfo, err error) error {
    if err != nil {
        fmt.Println(err)
        return err
    }
    fmt.Println(path, info.IsDir())
    return nil
})

// You can also access some FAT specific fields.
fmt.Printf("Opened volume '%v' with type %v\n\n", fat.Label(), fat.FSType())

That's it!

Test images

To get access to some test-images which already contain a FAT filesystem just run

go generate

This will extract the test images into ./testdata.

Contribution

Contributions are welcome, just create issues or even better PRs. You may open a draft or issue first to discuss the changes you would like to implement.

Some resources for how FAT works are:

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type BPB

type BPB struct {
	BSJumpBoot          [3]byte
	BSOEMName           [8]byte
	BytesPerSector      uint16
	SectorsPerCluster   byte
	ReservedSectorCount uint16
	NumFATs             byte
	RootEntryCount      uint16
	TotalSectors16      uint16
	Media               byte
	FATSize16           uint16
	SectorsPerTrack     uint16
	NumberOfHeads       uint16
	HiddenSectors       uint32
	TotalSectors32      uint32
	FATSpecificData     [54]byte
}

type EntryHeader

type EntryHeader struct {
	Name            [11]byte
	Attribute       byte
	NTReserved      byte
	CreateTimeTenth byte
	CreateTime      uint16
	CreateDate      uint16
	LastAccessDate  uint16
	FirstClusterHI  uint16
	WriteTime       uint16
	WriteDate       uint16
	FirstClusterLO  uint16
	FileSize        uint32
}

type ExtendedEntryHeader

type ExtendedEntryHeader struct {
	EntryHeader
	ExtendedName string
}

func (*ExtendedEntryHeader) FileInfo

func (h *ExtendedEntryHeader) FileInfo() os.FileInfo

type FAT16SpecificData

type FAT16SpecificData struct {
	BSDriveNumber    byte
	BSReserved1      byte
	BSBootSignature  byte
	BSVolumeId       uint32
	BSVolumeLabel    [11]byte
	BSFileSystemType [8]byte
}

type FAT32SpecificData

type FAT32SpecificData struct {
	FatSize          uint32
	ExtFlags         uint16
	FSVersion        uint16
	RootCluster      fatEntry
	FSInfo           uint16
	BkBootSector     uint16
	Reserved         [12]byte
	BSDriveNumber    byte
	BSReserved1      byte
	BSBootSignature  byte
	BSVolumeID       uint32
	BSVolumeLabel    [11]byte
	BSFileSystemType [8]byte
}

type FATType

type FATType string
const (
	FAT12 FATType = "FAT12"
	FAT16 FATType = "FAT16"
	FAT32 FATType = "FAT32"
)

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Read

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

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Truncate

func (f *File) Truncate(size int64) error

func (*File) Write

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

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

func (*File) WriteString

func (f *File) WriteString(s string) (ret int, err error)

type Fs

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

func New

func New(reader io.ReadSeeker) (*Fs, error)

func NewSkipChecks

func NewSkipChecks(reader io.ReadSeeker) (*Fs, error)

func (*Fs) Chmod

func (fs *Fs) Chmod(name string, mode os.FileMode) error

func (*Fs) Chown

func (fs *Fs) Chown(name string, uid, gid int) error

func (*Fs) Chtimes

func (fs *Fs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*Fs) Create

func (fs *Fs) Create(name string) (afero.File, error)

func (*Fs) FSType

func (fs *Fs) FSType() FATType

func (*Fs) Label

func (fs *Fs) Label() string

func (*Fs) Mkdir

func (fs *Fs) Mkdir(name string, perm os.FileMode) error

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(path string, perm os.FileMode) error

func (*Fs) Name

func (fs *Fs) Name() string

func (*Fs) Open

func (fs *Fs) Open(path string) (afero.File, error)

func (*Fs) OpenFile

func (fs *Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

func (*Fs) Remove

func (fs *Fs) Remove(name string) error

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(path string) error

func (*Fs) Rename

func (fs *Fs) Rename(oldname, newname string) error

func (*Fs) Stat

func (fs *Fs) Stat(path string) (os.FileInfo, error)

type Info

type Info struct {
	FSType              FATType
	FatCount            uint8
	FatSize             uint32
	SectorsPerCluster   uint8
	FirstDataSector     uint32
	TotalSectorCount    uint32
	ReservedSectorCount uint16
	BytesPerSector      uint16
	Label               string

	RootEntryCount uint16 // RootEntryCount is only needed for < FAT32.
	// contains filtered or unexported fields
}

Info contains all information about the whole filesystem.

type LongFilenameEntry

type LongFilenameEntry struct {
	Sequence  byte
	First     [5]uint16
	Attribute byte
	EntryType byte
	Checksum  byte
	Second    [6]uint16
	Zero      [2]byte
	Third     [2]uint16
}

type Sector

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

Directories

Path Synopsis
cmd
generate command
gofat command

Jump to

Keyboard shortcuts

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