Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterDecompressor(method Compression, dcomp Decompressor)
- type Compression
- type Decompressor
- type DirIndexEntry
- type File
- type FileDir
- type Flags
- type Inode
- func (i *Inode) AddRef(count uint64) uint64
- func (i *Inode) DelRef(count uint64) uint64
- func (i *Inode) GetGid() uint32
- func (i *Inode) GetUid() uint32
- func (i *Inode) IsDir() bool
- func (i *Inode) Mode() fs.FileMode
- func (ino *Inode) OpenFile(name string) fs.File
- func (i *Inode) ReadAt(p []byte, off int64) (int, error)
- func (i *Inode) Readlink() ([]byte, error)
- type Option
- type Superblock
- func (sb *Superblock) Close() error
- func (s *Superblock) FindInode(name string, followSymlinks bool) (*Inode, error)
- func (s *Superblock) FindInodeUnder(cur *Inode, name string, followSymlinks bool) (*Inode, error)
- func (sb *Superblock) GetInode(ino uint64) (*Inode, error)
- func (sb *Superblock) GetInodeRef(inor inodeRef) (*Inode, error)
- func (sb *Superblock) Lstat(name string) (fs.FileInfo, error)
- func (sb *Superblock) Open(name string) (fs.File, error)
- func (sb *Superblock) ReadDir(name string) ([]fs.DirEntry, error)
- func (sb *Superblock) Readlink(name string) (string, error)
- func (s *Superblock) SetInodeOffset(offt uint64)
- func (sb *Superblock) Stat(name string) (fs.FileInfo, error)
- func (s *Superblock) UnmarshalBinary(data []byte) error
- type Type
Constants ¶
const SuperblockSize = 96
Variables ¶
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") ErrInodeNotExported = errors.New("unknown squashfs inode and no NFS export table") 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. By default GZip is supported. The method shall take a buffer and return a decompressed buffer.
Types ¶
type Compression ¶ added in v0.1.4
type Compression uint16
const ( GZip Compression = iota + 1 LZMA LZO XZ LZ4 ZSTD )
func (Compression) String ¶ added in v0.1.4
func (s Compression) String() string
type Decompressor ¶
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 ¶ added in v0.1.4
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 DirIndexEntry ¶ added in v1.1.0
type File ¶
type File struct { *io.SectionReader // contains filtered or unexported fields }
File is a convience object allowing using an inode as if it was a regular file
type FileDir ¶
type FileDir struct {
// contains filtered or unexported fields
}
FileDir is a convenience object allowing using a dir inode as if it was a regular file
type Inode ¶
type Inode struct { Type Type Perm uint16 UidIdx uint16 GidIdx uint16 ModTime int32 Ino uint32 // inode number StartBlock uint64 NLink uint32 Size uint64 // Careful, actual on disk size varies depending on type Offset uint32 // uint16 for directories ParentIno uint32 // for directories SymTarget []byte // The target path this symlink points to IdxCount uint16 // index count for advanced directories XattrIdx uint32 // xattr table index (if relevant) Sparse uint64 // fragment FragBlock uint32 FragOfft uint32 // file blocks (some have value 0x1001000) Blocks []uint32 BlocksOfft []uint64 DirIndex []*DirIndexEntry // contains filtered or unexported fields }
func (*Inode) AddRef ¶
AddRef atomatically increments the inode's refcount and returns the new value. This is mainly useful when using fuse and can be safely ignored.
func (*Inode) DelRef ¶
DelRef atomatically decrements the inode's refcount and returns the new value. This is mainly useful when using fuse and can be safely ignored.
func (*Inode) GetUid ¶ added in v0.1.5
GetUid returns inode's owner uid, or zero if an error happens
type Option ¶ added in v0.1.5
type Option func(sb *Superblock) error
func InodeOffset ¶ added in v0.1.5
type Superblock ¶
type Superblock struct { Magic uint32 // magic identifier InodeCnt uint32 // number of inodes in filesystem ModTime int32 // creation unix time as int32 (will stop working in 2038) BlockSize uint32 // size of a single data block, must match 1<<BlockLog FragCount uint32 Comp Compression // Compression used, usually GZip BlockLog uint16 Flags Flags // squashfs flags IdCount uint16 VMajor uint16 VMinor uint16 RootInode inodeRef // inode number/reference of root BytesUsed uint64 IdTableStart uint64 XattrIdTableStart uint64 InodeTableStart uint64 DirTableStart uint64 FragTableStart uint64 ExportTableStart uint64 // contains filtered or unexported fields }
Superblock is the main object representing a squashfs image, and exposes various information about the file. You can ignore most of these and use the object directly to access files/etc, or inspect various elements of the squashfs image.
func New ¶
func New(fs io.ReaderAt, options ...Option) (*Superblock, error)
New returns a new instance of superblock for a given io.ReaderAt that can be used to access files inside squashfs.
func Open ¶ added in v0.1.5
func Open(file string, options ...Option) (*Superblock, error)
Open returns a new instance of superblock for a given file that can be used to access files inside squashfs. The file will be closed by the garbage collector or when Close() is called on the superblock.
func (*Superblock) Close ¶ added in v0.1.5
func (sb *Superblock) Close() error
Close will close the underlying file when a filesystem was open with Open()
func (*Superblock) FindInode ¶ added in v0.1.5
func (s *Superblock) FindInode(name string, followSymlinks bool) (*Inode, error)
FindInode returns the inode for a given path. If followSymlink is false and a symlink is found in the path, it will be followed anyway. If however the target file is a symlink, then its inode will be returned.
func (*Superblock) FindInodeUnder ¶ added in v1.0.0
FindInodeUnder returns an inode for a path starting at a given different inode
Note that it is not possible to access directories outside the given path, including using symlinks, as this effectively acts as a chroot. This can be useful to implement fs.Sub
func (*Superblock) GetInodeRef ¶
func (sb *Superblock) GetInodeRef(inor inodeRef) (*Inode, error)
func (*Superblock) Lstat ¶ added in v0.1.5
func (sb *Superblock) Lstat(name string) (fs.FileInfo, error)
Lstat will return stats for a given path inside the sqhashfs archive. If the target is a symbolic link, data on the link itself will be returned.
func (*Superblock) Open ¶
func (sb *Superblock) Open(name string) (fs.File, error)
Open returns a fs.File for a given path, which can be a different object depending if the file is a regular file or a directory.
func (*Superblock) ReadDir ¶
func (sb *Superblock) ReadDir(name string) ([]fs.DirEntry, error)
ReadDir implements fs.ReadDirFS and allows listing any directory inside the archive
func (*Superblock) Readlink ¶
func (sb *Superblock) Readlink(name string) (string, error)
Readlink allows reading the value of a symbolic link inside the archive.
func (*Superblock) SetInodeOffset ¶
func (s *Superblock) SetInodeOffset(offt uint64)
SetInodeOffset allows setting the inode offset used for interacting with fuse. This can be safely ignored if not using fuse or when mounting only a single squashfs via fuse.
func (*Superblock) Stat ¶
func (sb *Superblock) Stat(name string) (fs.FileInfo, error)
Stat will return stats for a given path inside the squashfs archive
func (*Superblock) UnmarshalBinary ¶
func (s *Superblock) UnmarshalBinary(data []byte) error
UnmarshalBinary reads a binary header values into Superblock