squashfs

package module
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 26 Imported by: 4

README

squashfs

PkgGoDev Go Report Card

A PURE Go library to read squashfs. There is currently no plans to add archive creation support as it will almost always be better to just call mksquashfs. I could see some possible use cases, but probably won't spend time on it unless it's requested (open a discussion fi you want this feature).

Currently has support for reading squashfs files and extracting files and folders.

Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important information in an easy to understand format. Thanks also to distri's squashfs library as I referenced it to figure some things out (and double check others).

TODO

Limitations

  • No Xattr parsing. This is simply because I haven't done any research on it and how to apply these in a pure go way.

Performance

Testing on a zstd compressed file, my library is anywhere from 5x ~ 7x slower then unsquashfs

Documentation

Index

Constants

View Source
const (
	GZipCompression = uint16(iota + 1)
	LZMACompression
	LZOCompression
	XZCompression
	LZ4Compression
	ZSTDCompression
)

The types of compression supported by squashfs

Variables

View Source
var (
	ErrorMagic   = errors.New("magic incorrect. probably not reading squashfs archive")
	ErrorLog     = errors.New("block log is incorrect. possible corrupted archive")
	ErrorVersion = errors.New("squashfs version of archive is not 4.0")
)
View Source
var ENODATA = fuse.ENODATA
View Source
var (
	ErrReadNotFile = errors.New("read called on non-file")
)

Functions

This section is empty.

Types

type ExtractionOptions added in v0.4.0

type ExtractionOptions struct {
	LogOutput          io.Writer   //Where error log should write. If nil, uses os.Stdout. Has no effect if verbose is false.
	DereferenceSymlink bool        //Replace symlinks with the target file.
	UnbreakSymlink     bool        //Try to make sure symlinks remain unbroken when extracted, without changing the symlink.
	Verbose            bool        //Prints extra info to log on an error.
	IgnorePerm         bool        //ignore the file's permission and instead use FolderPerm.
	FolderPerm         fs.FileMode //The permissions used when creating the extraction folder. Defaults to 0755.
}

ExtractionOptions are available options on how to extract.

func DefaultOptions added in v0.4.0

func DefaultOptions() ExtractionOptions

DefaultOptions is the default ExtractionOptions.

type FS added in v0.4.0

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

FS is a fs.FS representation of a squashfs directory. Implements fs.GlobFS, fs.ReadDirFS, fs.ReadFileFS, fs.StatFS, and fs.SubFS

func (FS) Glob added in v0.4.0

func (f FS) Glob(pattern string) (out []string, err error)

Glob returns the name of the files at the given pattern. All paths are relative to the FS. Uses filepath.Match to compare names.

func (FS) Open added in v0.4.0

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

Opens the file at name. Returns a io/fs.File.

func (FS) OpenFile added in v0.7.0

func (f FS) OpenFile(name string) (*File, error)

Opens the file at name. Returns a squashfs.File.

func (FS) ReadDir added in v0.4.0

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

ReadDir returns all the DirEntry returns all DirEntry's for the directory at name. If name is not a directory, returns an error.

func (FS) ReadFile added in v0.4.0

func (f FS) ReadFile(name string) ([]byte, error)

ReadFile returns the data (in []byte) for the file at name.

func (FS) Stat added in v0.4.0

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

Stat returns the fs.FileInfo for the file at name.

func (FS) Sub added in v0.4.0

func (f FS) Sub(dir string) (fs.FS, error)

Sub returns the FS at dir

type File added in v0.2.0

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

File represents a file inside a squashfs archive.

func (*File) Close added in v0.2.0

func (f *File) Close() error

Close simply nils the underlying reader.

func (f File) ExtractSymlink(folder string) error

ExtractSymlink extracts the File to the folder with the DereferenceSymlink option. If the File is a directory, it instead extracts the directory's contents to the folder.

func (File) ExtractTo added in v0.3.0

func (f File) ExtractTo(folder string) error

ExtractTo extracts the File to the given folder with the default options. If the File is a directory, it instead extracts the directory's contents to the folder.

func (File) ExtractWithOptions added in v0.3.0

func (f File) ExtractWithOptions(folder string, op ExtractionOptions) error

ExtractWithOptions extracts the File to the given folder with the given ExtrationOptions. If the File is a directory, it instead extracts the directory's contents to the folder.

func (*File) FS added in v0.4.0

func (f *File) FS() (*FS, error)

FS returns the File as a FS.

func (File) GetSymlinkFile added in v0.2.1

func (f File) GetSymlinkFile() *File

GetSymlinkFile returns the File the symlink is pointing to. If not a symlink, or the target is unobtainable (such as it being outside the archive or it's absolute) returns nil

func (File) IsDir added in v0.2.0

func (f File) IsDir() bool

IsDir Yep.

func (File) IsRegular added in v0.4.0

func (f File) IsRegular() bool

IsRegular yep.

func (f File) IsSymlink() bool

IsSymlink yep.

func (File) Mode added in v0.3.4

func (f File) Mode() fs.FileMode

Mode returns the file's fs.FileMode

func (File) Read added in v0.2.0

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

Read reads the data from the file. Only works if file is a normal file.

func (File) ReadAt added in v0.7.0

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

func (*File) ReadDir added in v0.4.0

func (f *File) ReadDir(n int) (out []fs.DirEntry, err error)

ReadDir returns n fs.DirEntry's that's contained in the File (if it's a directory). If n <= 0 all fs.DirEntry's are returned.

func (File) Stat added in v0.4.0

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

Stat returns the File's fs.FileInfo

func (File) SymlinkPath added in v0.2.1

func (f File) SymlinkPath() string

SymlinkPath returns the symlink's target path. Is the File isn't a symlink, returns an empty string.

func (File) WriteTo added in v0.4.0

func (f File) WriteTo(w io.Writer) (int64, error)

WriteTo writes all data from the file to the writer. This is multi-threaded. The underlying reader is seperate from the one used with Read and can be reused.

type Reader

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

func NewReader added in v0.6.0

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

Creates a new squashfs.Reader from the given io.ReaderAt.

func NewReaderAtOffset added in v0.7.2

func NewReaderAtOffset(r io.ReaderAt, off int64) (*Reader, error)

func NewReaderFromReader added in v0.6.0

func NewReaderFromReader(r io.Reader) (*Reader, error)

Creates a new squashfs.Reader from the given io.Reader. NOTE: All data from the io.Reader will be read and stored in memory.

func (Reader) ModTime added in v0.3.4

func (r Reader) ModTime() time.Time

Returns the last time the archive was modified.

func (*Reader) Mount added in v0.7.0

func (r *Reader) Mount(mountpoint string) (err error)

Mounts the archive to the given mountpoint using fuse3. Non-blocking. If Unmount does not get called, the mount point must be unmounted using umount before the directory can be used again.

func (*Reader) MountFuse2 added in v0.7.7

func (r *Reader) MountFuse2(mountpoint string) (err error)

Mounts the archive to the given mountpoint using fuse2. Non-blocking. If Unmount does not get called, the mount point must be unmounted using umount before the directory can be used again.

func (*Reader) MountWait added in v0.7.3

func (r *Reader) MountWait()

Blocks until the mount ends.

func (*Reader) MountWaitFuse2 added in v0.7.7

func (r *Reader) MountWaitFuse2()

Blocks until the mount ends. Fuse2 version.

func (*Reader) Unmount added in v0.7.3

func (r *Reader) Unmount() error

Unmounts the archive.

func (*Reader) UnmountFuse2 added in v0.7.7

func (r *Reader) UnmountFuse2() error

Unmounts the archive. Fuse2 version.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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