squashfs

package module
v0.0.0-...-7f6f44e Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 12 Imported by: 0

README

squashfs

This is a read-only implementation of squashfs that conforms to the io/fs interfaces.

Example use

package main

import (
	"os"
	"net/http"
	"gitlab.com/rackn/squashfs"
)

func main() {
	fi, _ := os.Open("file.squashfs")
	sqfs, _ := squashfs.Open(fi)
	// sqfs is a regular fs.FS

	http.Handle("/", http.FileServer(http.FS(sqfs)))
	// etc...
}

You can find more looking at the test file.

File format

Some documentation is available online on SquashFS.

TODO

  • Access to directories do not currently use indexes and can be slow for random file accesses in very large directories.
  • A block caching scheme is needed to handle high-traffic sections of the file. That could be fun.

Documentation

Index

Constants

View Source
const (
	DirType inoType = iota + 1
	FileType
	SymlinkType
	BlockDevType
	CharDevType
	FifoType
	SocketType
	XDirType
	XFileType
	XSymlinkType
	XBlockDevType
	XCharDevType
	XFifoType
	XSocketType
)

Variables

View Source
var (
	ErrInvalidFile     = errors.New("invalid file, squashfs signature not found")
	ErrInvalidSuper    = errors.New("invalid squashfs superblock")
	ErrInvalidVersion  = errors.New("invalid file version, expected squashfs 4.0")
	ErrNotDirectory    = errors.New("Not a directory")
	ErrTooManySymlinks = errors.New("Too many levels of symbolic links")
)

Functions

func RegisterDecompressor

func RegisterDecompressor(method Compression, dcomp Decompressor)

RegisterDecompressor can be used to register a Decompressor for squashfs. GZip and ZSTD are supported by default. You can register additional decompressor types before opening squashfs archives that use them. Once registered, decompressors cannot be deregistered, only replaced.

Types

type Compression

type Compression uint16

Compression tracks what type of compression a squashfs is using. Out of the box, we support GZip and ZSTD using github.com/klauspost/compress. Additional types may be suported by default later, and you can always register your own.

const (
	GZip Compression = iota + 1
	LZMA
	LZO
	XZ
	LZ4
	ZSTD
)

func (Compression) String

func (s Compression) String() string

type Decompressor

type Decompressor func([]byte, []byte) ([]byte, error)

Decompressor takes an input buffer and a destination buffer and returns the destination buffer filled with data and an error It matches the function signature of github.com/klauspost/compress/zstd Reader.DecodeAll. The library internals will eventually leverage it to optimize buffer reuse and caching.

func MakeDecompressor

func MakeDecompressor(dec func(r io.Reader) io.ReadCloser) Decompressor

MakeDecompressor allows using a decompressor made for archive/zip with SquashFs. It has some overhead as instead of simply dealing with buffer this uses the reader/writer API, but should allow to easily handle some formats.

Example use: * squashfs.RegisterDecompressor(squashfs.ZSTD, squashfs.MakeDecompressor(zstd.ZipDecompressor())) * squashfs.RegisterDecompressor(squashfs.LZ4, squashfs.MakeDecompressor(lz4.NewReader)))

func MakeDecompressorErr

func MakeDecompressorErr(dec func(r io.Reader) (io.ReadCloser, error)) Decompressor

MakeDecompressorErr is similar to MakeDecompressor but the factory method also returns an error.

Example use: * squashfs.RegisterDecompressor(squashfs.LZMA, squashfs.MakeDecompressorErr(lzma.NewReader)) * squashfs.RegisterDecompressor(squashfs.XZ, squashfs.MakeDecompressorErr(xz.NewReader))

type Dir

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

Dir is an fs.File that supports fs.ReadDirFile

func (*Dir) Close

func (d *Dir) Close() error

func (Dir) IsDir

func (ni Dir) IsDir() bool

func (Dir) ModTime

func (ni Dir) ModTime() time.Time

ModTime returns the file's latest modified time. Note that squashfs stores this as a int32, which means it'll stop working after 2038.

func (Dir) Mode

func (ni Dir) Mode() fs.FileMode

func (Dir) Name

func (ni Dir) Name() string

Name returns the file's base name

func (*Dir) Read

func (d *Dir) Read([]byte) (int, error)

func (*Dir) ReadDir

func (d *Dir) ReadDir(n int) ([]fs.DirEntry, error)
func (ni Dir) ReadLink() (string, error)

func (Dir) Size

func (ni Dir) Size() int64

Size returns the file's size

func (Dir) Stat

func (ni Dir) Stat() (fs.FileInfo, error)

func (Dir) Sys

func (ni Dir) Sys() any

Sys returns an object containing lower level stat information. Most of it is a quasi useful lie.

type FS

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

FS implements squashfs support.

func Open

func Open(fs io.ReaderAt) (*FS, error)

Open returns a new instance of FS for a given io.ReaderAt that can be used to access files inside squashfs.

func (*FS) Lstat

func (sq *FS) Lstat(name string) (fs.FileInfo, error)

Lstat will return stats for a given path inside the squashfs archive. If the target is a symbolic link, data on the link itself will be returned.

func (*FS) Open

func (sq *FS) Open(name string) (fs.File, error)

Open returns a fs.File for a given path.

func (*FS) ReadDir

func (sq *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir implements fs.ReadDirFS and allows listing any directory inside the archive

func (sq *FS) ReadLink(name string) (string, error)

ReadLink allows reading the value of a symbolic link inside the archive.

func (*FS) Stat

func (sq *FS) Stat(name string) (fs.FileInfo, error)

Stat will return stats for a given path inside the squashfs archive

func (*FS) UnmarshalBinary

func (sq *FS) UnmarshalBinary(data []byte) error

UnmarshalBinary reads a binary header values into FS

type File

type File struct {
	*io.SectionReader
	// contains filtered or unexported fields
}

File is an fs.File + io.ReaderAt and friends.

func (File) Close

func (ni File) Close() error

func (File) IsDir

func (ni File) IsDir() bool

func (File) ModTime

func (ni File) ModTime() time.Time

ModTime returns the file's latest modified time. Note that squashfs stores this as a int32, which means it'll stop working after 2038.

func (File) Mode

func (ni File) Mode() fs.FileMode

func (File) Name

func (ni File) Name() string

Name returns the file's base name

func (ni File) ReadLink() (string, error)

func (File) Size

func (ni File) Size() int64

Size returns the file's size

func (File) Stat

func (ni File) Stat() (fs.FileInfo, error)

func (File) Sys

func (ni File) Sys() any

Sys returns an object containing lower level stat information. Most of it is a quasi useful lie.

type Flags

type Flags uint16
const (
	UNCOMPRESSED_INODES Flags = 1 << iota
	UNCOMPRESSED_DATA
	CHECK
	UNCOMPRESSED_FRAGMENTS
	NO_FRAGMENTS
	ALWAYS_FRAGMENTS
	DUPLICATES
	EXPORTABLE
	UNCOMPRESSED_XATTRS
	NO_XATTRS
	COMPRESSOR_OPTIONS
	UNCOMPRESSED_IDS
)

func (Flags) Has

func (f Flags) Has(what Flags) bool

func (Flags) String

func (f Flags) String() string

type SysStat

type SysStat struct {
	Mode    fs.FileMode
	Nlink   uint32
	Ino     uint32
	Mtime   time.Time
	Size    int64
	Blocks  int64
	Blksize int64
}

type Unhandled

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

Unhandled is an fs.File for file types supported by squashfs that this library does not handle. Think devices, FIFOs, and the like.

func (Unhandled) Close

func (ni Unhandled) Close() error

func (Unhandled) IsDir

func (ni Unhandled) IsDir() bool

func (Unhandled) ModTime

func (ni Unhandled) ModTime() time.Time

ModTime returns the file's latest modified time. Note that squashfs stores this as a int32, which means it'll stop working after 2038.

func (Unhandled) Mode

func (ni Unhandled) Mode() fs.FileMode

func (Unhandled) Name

func (ni Unhandled) Name() string

Name returns the file's base name

func (Unhandled) Read

func (s Unhandled) Read([]byte) (int, error)
func (ni Unhandled) ReadLink() (string, error)

func (Unhandled) Size

func (ni Unhandled) Size() int64

Size returns the file's size

func (Unhandled) Stat

func (ni Unhandled) Stat() (fs.FileInfo, error)

func (Unhandled) Sys

func (ni Unhandled) Sys() any

Sys returns an object containing lower level stat information. Most of it is a quasi useful lie.

Jump to

Keyboard shortcuts

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