fat

package
v0.0.0-...-d29c615 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package fat implements writing FAT16B file system images, which is useful when generating images for embedded devices such as the Raspberry Pi. With regards to reading, getting file offsets and lengths is implemented.

The resulting images use a cluster size of 4 sectors and a sector size of 512 bytes, i.e. their size is limited to about 127 MB.

Filenames are restricted to 8 characters + 3 characters for the file extension.

Example
package main

import (
	"io/ioutil"
	"log"
	"time"

	"github.com/gokrazy/internal/fat"
)

func main() {
	tmp, err := ioutil.TempFile("", "example")
	if err != nil {
		log.Fatal(err)
	}

	fw, err := fat.NewWriter(tmp)
	if err != nil {
		log.Fatal(err)
	}

	w, err := fw.File("etc/resolv.conf", time.Now())
	if err != nil {
		log.Fatal(err)
	}
	if _, err := w.Write([]byte("nameserver 8.8.8.8")); err != nil {
		log.Fatal(err)
	}

	if err := fw.Flush(); err != nil {
		log.Fatal(err)
	}

	if err := tmp.Close(); err != nil {
		log.Fatal(err)
	}

	log.Printf("mount -o loop %s /mnt/loop", tmp.Name())
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader is a minimalistic FAT16B reader, which only aims to be compatible with file systems created by Writer.

func NewReader

func NewReader(r io.ReadSeeker) (*Reader, error)

NewReader creates a new FAT16B Reader by reading file system metadata.

func (*Reader) Extents

func (r *Reader) Extents(path string) (offset int64, length int64, err error)

Extents returns the offset and length of the file identified by path.

This function is useful only on FAT file systems where all files are stored un-fragmented, such as file systems generated by Writer.

func (*Reader) ModTime

func (r *Reader) ModTime(path string) (time.Time, error)

ModTime returns the modification time of the file identified by path.

TODO: implement support for subdirectories

type Writer

type Writer struct {
	TotalSectors int // populated after Flush
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer) (*Writer, error)

NewWriter returns a Writer which will write a FAT16B file system image to w once Flush is called.

Because the position of the data area in the resulting image depends on the size of the file allocation table and number of root directory entries, a temporary file is used to store data until Flush is called.

func (*Writer) File

func (fw *Writer) File(path string, modTime time.Time) (io.Writer, error)

File creates a file with the specified path and modTime. The returned io.Writer stays valid until the next call to File, Flush or Mkdir.

func (*Writer) Flush

func (fw *Writer) Flush() error

Flush writes the image. The Writer must not be used after calling Flush.

func (*Writer) Mkdir

func (fw *Writer) Mkdir(path string, modTime time.Time) error

Mkdir creates an empty directory with the given full path, e.g. Mkdir("usr/share/lib").

Jump to

Keyboard shortcuts

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