squashfs

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 9 Imported by: 4

README

GoSquashfs

PkgGoDev

A PURE Go library to read and write squashfs.

Currently, you can read a squashfs and extract files (only files at the moment). Many things are public that shouldn't be, but you can use it by using NewSquashfsReader and subsequent ReadFile.

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).

Working

  • Extracting files from string paths
  • Reading the header
  • Reading metadata blocks (whether encrypted or not)
  • Reading inodes
  • Reading directories
  • Basic gzip compression (Shouldn't be too hard to implement other, but for right now, this works)
  • Listing all files via a string slice

Not Working (Yet). Not necessarily in order.

  • Provide an easy interface to find and list files and their properties
    • Maybe squashfs.File
  • Make device, socket, symlink, and all extended types of inode work properly. (I need to find an archive that uses it first.)
  • Extracting files
    • from inodes.
    • from file info.
  • Give a list of files
    • In io.FileStat (?) form
  • Reading the UID, GUID, Xatt, Compression Options, and Export tables.
  • Implement other compression types (Should be relatively easy)
  • Squashing
  • Threading processes to speed them up
  • Reasonable tests

TODO

  • Go over all documentation again (especially for exported structs and functions) to make sure it's easy to understand.

Where I'm at

  • Working on the File interface that should make it easier to deal with squashfs files. I'm also trying to make them capable for when I get squashing working.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrNotDirectory is returned when you're trying to do directory things with a non-directory
	ErrNotDirectory = errors.New("File is not a directory")
	//ErrNotFile is returned when you're trying to do file things with a directory
	ErrNotFile = errors.New("File is not a file")
	//ErrNotReading is returned when running functions that are only meant to be used when reading a squashfs
	ErrNotReading = errors.New("Function only supported when reading a squashfs")
)
View Source
var (
	//ErrNoMagic is returned if the magic number in the superblock isn't correct.
	ErrNoMagic = errors.New("Magic number doesn't match. Either isn't a squashfs or corrupted")
	//ErrIncompatibleCompression is returned if the compression type in the superblock doesn't work.
	ErrIncompatibleCompression = errors.New("Compression type unsupported")
	//ErrCompressorOptions is returned if compressor options is present. It's not currently supported.
	ErrCompressorOptions = errors.New("Compressor options is not currently supported")
)
View Source
var (
	//ErrNotFound means that the given path is NOT present in the archive
	ErrNotFound = errors.New("Path not found")
)
View Source
var (
	//ErrPathIsNotFile returns when trying to read from a file, but the given path is NOT a file.
	ErrPathIsNotFile = errors.New("The given path is not a file")
)

Functions

This section is empty.

Types

type File added in v0.2.0

type File struct {
	Name   string    //The name of the file or folder. Root folder will not have a name ("")
	Parent *File     //The parent directory. If it's the root directory, will be nil
	Reader io.Reader //Underlying reader. When writing, will probably be an os.File. When reading this is kept nil UNTIL reading to save memory.
	Path   string    //The path to the folder the File is located in.
	// contains filtered or unexported fields
}

File is the main way to interact with files within squashfs, or when putting files into a squashfs. File can be either a file or folder. When reading from a squashfs, it reads from the datablocks. When writing, this holds the information on WHERE the file will be placed inside the archive.

func (*File) Close added in v0.2.0

func (f *File) Close() error

Close frees up the memory held up by the underlying reader. Should NOT be called when writing. When reading, Close is safe to use, but any subsequent Read calls resets to the beginning of the file.

func (*File) GetChildren added in v0.2.0

func (f *File) GetChildren() (children []*File, err error)

GetChildren returns a *squashfs.File slice of every direct child of the directory. If the File is not a directory, will return ErrNotDirectory

func (*File) GetChildrenRecursively added in v0.2.0

func (f *File) GetChildrenRecursively() (children []*File, err error)

GetChildrenRecursively returns ALL children. Goes down ALL folder paths.

func (*File) IsDir added in v0.2.0

func (f *File) IsDir() bool

IsDir returns if the file is a directory.

func (*File) Read added in v0.2.0

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

Read from the file. Doesn't do anything fancy, just pases it to the underlying io.Reader. If a directory, return io.EOF.

type Reader

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

Reader processes and reads a squashfs archive. TODO: Give a way to actually read files :P

func NewSquashfsReader

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

NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt

func (*Reader) FindAll added in v0.2.0

func (r *Reader) FindAll(query func(*File) bool) (all []*File)

FindAll returns all files where the given function returns true.

func (*Reader) FindFile added in v0.2.0

func (r *Reader) FindFile(query func(*File) bool) *File

FindFile returns the first file (in the same order as Reader.GetAllFiles) that the given function returns true for. Returns nil if nothing is found.

func (*Reader) GetAllFiles added in v0.2.0

func (r *Reader) GetAllFiles() (fils []*File, err error)

GetAllFiles returns a slice of ALL files and folders contained in the squashfs.

func (*Reader) GetFileAtPath added in v0.2.0

func (r *Reader) GetFileAtPath(path string) *File

GetFileAtPath will return the file at the given path. If the file cannot be found, will return nil.

func (*Reader) GetRootFolder added in v0.2.0

func (r *Reader) GetRootFolder() (root *File, err error)

GetRootFolder returns a squashfs.File that references the root directory of the squashfs archive.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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