squashfs

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

README

golang library for reading squashfs filesystems.

This is a golang library that provides access to squashfs filesystems.

It uses the the libsquashfs C library from squashfs-tools-ng.

It will build against 1.0.0, but the Read operations require a fix for squashfs-tools-ng/#58.

There is really good doc of squashfs format at doc/format.adoc

Build setup

Most of this is handled by setup program. But if you want to do it on your own, the following is a summary of what setup will do.

I'm assuming you have 'git'. Get that with apt or yum.

  • get squashfs-tools-ng

     $ git clone https://github.com/AgentD/squashfs-tools-ng.git
    
  • get go-squashfs

     $ git clone https://github.com/anuvu/squashfs go-squashfs
    
  • Get build deps

    • Ubuntu

       $ sudo apt-get install --no-install-recommends  --assume-yes \
           autoconf automake make autogen autoconf libtool binutils \
           git squashfs-tools
      
       $ sudo apt-get install --no-install-recommends --assume-yes \
          libzstd-dev zlib1g-dev liblz4-dev libc6-dev liblzma-dev
      
    • Centos 7

       # we need epel for libzstd
       $ sudo yum install --assumeyes https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
      
       $ sudo yum install --assumeyes \
           git make autogen automake autoconf \
           libtool binutils squashfs-tools
      
       $ sudo yum install --assumeyes \
          libzstd-devel libzstd-static \
          zlib-devel zlib-static \
          lz4-devel lz4-static \
          glibc-devel glibc-static \
          xz xz-devel
      
  • Get golang. You can/should figure this out yourself, but here is one way:

     $ ver=1.14.4
     $ majmin=${ver%.*}
     $ curl https://dl.google.com/go/go${ver}.linux-amd64.tar.gz > go.tar.gz
    
     # this creates /usr/lib/go-1.14
     $ sudo tar -C /usr/lib -xvf go.tar.gz --show-transformed-names --transform "s/^go/go-$majmin/"
     $ sudo ln -sf ../lib/go-$majmin/bin/go /usr/bin/go
    
  • install into mylocal="$HOME/lib"

     $ mylocal="$HOME/mylocal"
     $ export LD_LIBRARY_PATH=$mylocal/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
     $ export PKG_CONFIG_PATH=$mylocal/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
    
  • build and install squashfs-tools-ng

     $ cd squashfs-tools-ng
     $ ./autogen.sh
     $ ./configure --prefix=$mylocal
     $ make
     $ make install
    
  • build go-squashfs

     $ cd go-squashfs
     $ make
    

Documentation

Index

Constants

View Source
const DefaultDirPerm = 0755

DefaultDirPerm - Directories created with this perm

View Source
const DefaultFilePerm = 0644

DefaultFilePerm - files will be created with this perm by default.

View Source
const OpenDirPerm = 0777

OpenDirPerm - Perm that current uid can write to

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented - not implemented

View Source
var SkipDir = filepath.SkipDir

SkipDir - Just re-used from filepath

Functions

func PathExists

func PathExists(d string) bool

Types

type Extractor

type Extractor struct {
	Dir       string
	SquashFs  SquashFs
	Path      string
	WhiteOuts bool
	Owners    bool
	Perms     bool
	Devs      bool
	Sockets   bool
	Logger    Logger
	Ops       FsOps
	// contains filtered or unexported fields
}

func (*Extractor) Extract

func (e *Extractor) Extract() error

Extract - extract the

type FakerootOps

type FakerootOps struct{}

Golang's os.Chown, os.Chmod, syscall.Mknod, make syscalls which are missed by fakeroot's LD_PRELOAD of those filesystem operations. In order to work with fakeroot, we execute the programs 'chown', 'chmod', 'mknod' which are expected to work with fakeroot.

func (FakerootOps) Chmod

func (f FakerootOps) Chmod(name string, mode os.FileMode) error

func (FakerootOps) Chown

func (f FakerootOps) Chown(name string, uid, gid int) error

func (FakerootOps) Mknod

func (f FakerootOps) Mknod(path string, info FileInfo) error

type File

type File struct {
	Filename string
	SquashFs *SquashFs
	Pos      int64
	// contains filtered or unexported fields
}

File - a os.File for squash

func Open

func Open(name string, squash *SquashFs) (*File, error)

Open - os.File.Open

func (*File) Close

func (f *File) Close() error

Close - os.File.Close

func (*File) Fd

func (f *File) Fd() uintptr

Fd - os.File.Fd

func (*File) Lstat

func (f *File) Lstat() (FileInfo, error)

Lstat - os.File.Lstat - if file is a symlink info is about the link not the target.

func (*File) Name

func (f *File) Name() string

Name - os.File.Name

func (*File) Read

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

Read - os.File.Read

func (*File) Readdir

func (f *File) Readdir(n int) ([]os.FileInfo, error)

Readdir - os.File.Readdir

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

Readdirnames - os.File.Readdirnames

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (ret int64, err error)

Seek - os.File.Seek

func (*File) Size

func (f *File) Size() int64

Size - mostly just a convienence, used by Seek.

func (*File) Stat

func (f *File) Stat() (FileInfo, error)

Stat - os.File.Stat - If file is a symlink, tell about the target.

func (*File) Sync

func (f *File) Sync() error

Sync - os.File.Sync

type FileInfo

type FileInfo struct {
	Filename      string
	FSize         int64
	FMode         os.FileMode
	FModTime      time.Time
	File          *File
	SymlinkTarget string
}

FileInfo - Implements a os.FileInfo interface for squash file.

func (FileInfo) IsDir

func (f FileInfo) IsDir() bool

IsDir - os.FileInfo.IsDir abbreviation for Mode().IsDir()

func (FileInfo) ModTime

func (f FileInfo) ModTime() time.Time

ModTime - os.FileInfo.ModTime modification time

func (FileInfo) Mode

func (f FileInfo) Mode() os.FileMode

Mode - os.FileInfo.Mode file mode bits

func (FileInfo) Name

func (f FileInfo) Name() string

Name - os.FileInfo.Name base name of the file

func (FileInfo) Size

func (f FileInfo) Size() int64

Size - os.FileInfo.Size length in bytes for regular files; system-dependent for others

func (FileInfo) String

func (f FileInfo) String() string

String - convert to string (as in ls -l)

func (FileInfo) Sys

func (f FileInfo) Sys() interface{}

Sys - os.FileInfo.Sys underlying data source (can return nil)

returns a syscall.Stat_t

type FsOps

type FsOps interface {
	Chmod(string, os.FileMode) error
	Chown(string, int, int) error
	Mknod(string, FileInfo) error
}

type GoFsOps

type GoFsOps struct{}

func (GoFsOps) Chmod

func (g GoFsOps) Chmod(name string, mode os.FileMode) error

func (GoFsOps) Chown

func (g GoFsOps) Chown(name string, uid, gid int) error

func (GoFsOps) Mknod

func (g GoFsOps) Mknod(path string, info FileInfo) error

type Logger

type Logger interface {
	Info(string, ...interface{})
	Verbose(string, ...interface{})
	Debug(string, ...interface{})
}

Logger - basic logging interface

type PrintfLogger

type PrintfLogger struct {
	Verbosity int
}

PrintfLogger - logger that calls Fprintf(os.Stderr, ...)

func (PrintfLogger) Debug

func (p PrintfLogger) Debug(fmt string, a ...interface{})

func (PrintfLogger) Info

func (p PrintfLogger) Info(fmt string, a ...interface{})

func (PrintfLogger) Verbose

func (p PrintfLogger) Verbose(fmt string, a ...interface{})

type SquashFs

type SquashFs struct {
	Filename string
	// contains filtered or unexported fields
}

func OpenSquashfs

func OpenSquashfs(fname string) (SquashFs, error)

OpenSquashfs - return a SquashFs struct for fname.

func (*SquashFs) BytesUsed

func (s *SquashFs) BytesUsed() uint64

func (*SquashFs) Close

func (s *SquashFs) Close()

func (*SquashFs) Free

func (s *SquashFs) Free()

func (*SquashFs) Lstat

func (s *SquashFs) Lstat(name string) (FileInfo, error)

Lstat - os.File.Lstat

func (*SquashFs) OpenFile

func (s *SquashFs) OpenFile(name string) (*File, error)

func (*SquashFs) Stat

func (s *SquashFs) Stat(name string) (FileInfo, error)

Stat - os.File.Stat

func (*SquashFs) Walk

func (s *SquashFs) Walk(root string, walkFn WalkFunc) error

Walk - mimics filepath.Walk

type WalkFunc

type WalkFunc func(string, FileInfo, error) error

WalkFunc - same as filepath.WalkFunc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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