squashfs

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package squashfs provides support for reading and creating squashfs filesystems references:

https://www.kernel.org/doc/Documentation/filesystems/squashfs.txt
https://dr-emann.github.io/squashfs/
https://elinux.org/images/3/32/Squashfs-elce.pdf

Index

Constants

View Source
const (
	GzipDefault          GzipStrategy = 0x1
	GzipFiltered                      = 0x2
	GzipHuffman                       = 0x4
	GzipRunLengthEncoded              = 0x8
	GzipFixed                         = 0x10
)

gzip strategy options

View Source
const (
	XzFilterX86      XzFilter = 0x1
	XzFilterPowerPC           = 0x2
	XzFilterIA64              = 0x4
	XzFilterArm               = 0x8
	XzFilterArmThumb          = 0x10
	XzFilterSparc             = 0x20
)

xz filter options

View Source
const (
	// KB represents one KB
	KB int64 = 1024
	// MB represents one MB
	MB int64 = 1024 * KB
	// GB represents one GB
	GB int64 = 1024 * MB
	// TB represents one TB
	TB int64 = 1024 * GB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Compressor

type Compressor interface {
	// contains filtered or unexported methods
}

Compressor defines a compressor. Fulfilled by various implementations in this package

type CompressorGzip

type CompressorGzip struct {
	CompressionLevel uint32
	WindowSize       uint16
	Strategies       map[GzipStrategy]bool
}

CompressorGzip gzip compression

type CompressorLz4

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

CompressorLz4 lz4 compression

type CompressorLzma

type CompressorLzma struct {
}

CompressorLzma lzma compression

type CompressorXz

type CompressorXz struct {
	DictionarySize    uint32
	ExecutableFilters map[XzFilter]bool
}

CompressorXz xz compression

type CompressorZstd

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

CompressorZstd zstd compression

type File

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

File represents a single file in a squashfs filesystem

it is NOT used when working in a workspace, where we just use the underlying OS
note that the inode for a file can be the basicFile or extendedFile. We just use extendedFile to
include all of the data

func (*File) Close

func (fl *File) Close() error

Close close the file

func (*File) Read

func (fl *File) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF reads from the last known offset in the file from last read or write use Seek() to set at a particular point

func (*File) Seek

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

Seek set the offset to a particular point in the file

func (*File) Write

func (fl *File) Write(p []byte) (int, error)

Write writes len(b) bytes to the File.

you cannot write to a finished squashfs, so this returns an error

type FileStat

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

FileStat is the extended data underlying a single file, similar to https://golang.org/pkg/syscall/#Stat_t

func (*FileStat) GID

func (f *FileStat) GID() uint32

GID get gid of file

func (*FileStat) UID

func (f *FileStat) UID() uint32

UID get uid of file

func (*FileStat) Xattrs

func (f *FileStat) Xattrs() map[string]string

Xattrs get extended attributes of file

type FileSystem

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

FileSystem implements the FileSystem interface

func Create

func Create(f util.File, size int64, start int64, blocksize int64) (*FileSystem, error)

Create creates a squashfs filesystem in a given directory

requires the util.File where to create the filesystem, size is the size of the filesystem in bytes, start is how far in bytes from the beginning of the util.File to create the filesystem, and blocksize is is the logical blocksize to use for creating the filesystem

note that you are *not* required to create the filesystem on the entire disk. You could have a disk of size 20GB, and create a small filesystem of size 50MB that begins 2GB into the disk. This is extremely useful for creating filesystems on disk partitions.

Note, however, that it is much easier to do this using the higher-level APIs at github.com/cusspvz/go-diskfs which allow you to work directly with partitions, rather than having to calculate (and hopefully not make any errors) where a partition starts and ends.

If the provided blocksize is 0, it will use the default of 128 KB.

func Read

func Read(file util.File, size int64, start int64, blocksize int64) (*FileSystem, error)

Read reads a filesystem from a given disk.

requires the util.File where to read the filesystem, size is the size of the filesystem in bytes, start is how far in bytes from the beginning of the util.File the filesystem is expected to begin, and blocksize is is the logical blocksize to use for creating the filesystem

note that you are *not* required to read a filesystem on the entire disk. You could have a disk of size 20GB, and a small filesystem of size 50MB that begins 2GB into the disk. This is extremely useful for working with filesystems on disk partitions.

Note, however, that it is much easier to do this using the higher-level APIs at github.com/cusspvz/go-diskfs which allow you to work directly with partitions, rather than having to calculate (and hopefully not make any errors) where a partition starts and ends.

If the provided blocksize is 0, it will use the default of 2K bytes

func (*FileSystem) Equal

func (fs *FileSystem) Equal(a *FileSystem) bool

Equal compare if two filesystems are equal

func (*FileSystem) Finalize

func (fs *FileSystem) Finalize(options FinalizeOptions) error

Finalize finalize a read-only filesystem by writing it out to a read-only format

func (*FileSystem) Label

func (fs *FileSystem) Label() string

Label return the filesystem label

func (*FileSystem) Mkdir

func (fs *FileSystem) Mkdir(p string) error

Mkdir make a directory at the given path. It is equivalent to `mkdir -p`, i.e. idempotent, in that:

* It will make the entire tree path if it does not exist * It will not return an error if the path already exists

if readonly and not in workspace, will return an error

func (*FileSystem) OpenFile

func (fs *FileSystem) OpenFile(p string, flag int) (filesystem.File, error)

OpenFile returns an io.ReadWriter from which you can read the contents of a file or write contents to the file

accepts normal os.OpenFile flags

returns an error if the file does not exist

func (*FileSystem) ReadDir

func (fs *FileSystem) ReadDir(p string) ([]os.FileInfo, error)

ReadDir return the contents of a given directory in a given filesystem.

Returns a slice of os.FileInfo with all of the entries in the directory.

Will return an error if the directory does not exist or is a regular file and not a directory

func (*FileSystem) Type

func (fs *FileSystem) Type() filesystem.Type

Type returns the type code for the filesystem. Always returns filesystem.TypeFat32

func (*FileSystem) Workspace

func (fs *FileSystem) Workspace() string

Workspace get the workspace path

type FinalizeOptions

type FinalizeOptions struct {
	// Compressor which compressor to use, including, where relevant, options. Defaults ot CompressorGzip
	Compression Compressor
	// NonExportable prevent making filesystem NFS exportable. Defaults to false, i.e. make it exportable
	NonExportable bool
	// NonSparse prevent detecting sparse files. Defaults to false, i.e. detect sparse files
	NonSparse bool
	// Xattrs whether or not to store extended attributes. Defaults to false
	Xattrs bool
	// NoCompressInodes whether or not to compress inodes. Defaults to false, i.e. compress inodes
	NoCompressInodes bool
	// NoCompressData whether or not to compress data blocks. Defaults to false, i.e. compress data
	NoCompressData bool
	// NoCompressFragments whether or not to compress fragments. Defaults to false, i.e. compress fragments
	NoCompressFragments bool
	// NoCompressXattrs whether or not to compress extended attrbutes. Defaults to false, i.e. compress xattrs
	NoCompressXattrs bool
	// NoFragments do not use fragments, but rather dedicated data blocks for all files. Defaults to false, i.e. use fragments
	NoFragments bool
	// NoPad do not pad filesystem so it is a multiple of 4K. Defaults to false, i.e. pad it
	NoPad bool
	// FileUID set all files to be owned by the UID provided, default is to leave as in filesystem
	FileUID *uint32
	// FileGID set all files to be owned by the GID provided, default is to leave as in filesystem
	FileGID *uint32
}

FinalizeOptions options to pass to finalize

type GzipStrategy

type GzipStrategy uint16

type XzFilter

type XzFilter uint32

XzFilter filter for xz compression

Jump to

Keyboard shortcuts

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