You can lookup an inode via a string path now
Removed DecompressCopy (as I wasn't using it) Started work on fragments
This commit is contained in:
+38
-17
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/CalebQ42/GoSquashfs/internal/directory"
|
||||
"github.com/CalebQ42/GoSquashfs/internal/inode"
|
||||
@@ -14,6 +15,17 @@ const (
|
||||
magic = 0x73717368
|
||||
)
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
//Reader processes and reads a squashfs archive.
|
||||
//TODO: Give a way to actually read files :P
|
||||
type Reader struct {
|
||||
r io.ReaderAt
|
||||
super Superblock
|
||||
@@ -22,6 +34,7 @@ type Reader struct {
|
||||
dirs []*directory.Directory
|
||||
}
|
||||
|
||||
//NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt
|
||||
func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
||||
var rdr Reader
|
||||
rdr.r = r
|
||||
@@ -30,25 +43,43 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
||||
return nil, err
|
||||
}
|
||||
if rdr.super.Magic != magic {
|
||||
return nil, errors.New("doesn't have magic number, probably isn't a squashfs")
|
||||
return nil, ErrNoMagic
|
||||
}
|
||||
rdr.flags = rdr.super.GetFlags()
|
||||
switch rdr.super.CompressionType {
|
||||
case gzipCompression:
|
||||
rdr.decompressor = &ZlibDecompressor{}
|
||||
default:
|
||||
return nil, errors.New("Unsupported compression type")
|
||||
return nil, ErrIncompatibleCompression
|
||||
}
|
||||
if rdr.flags.CompressorOptions {
|
||||
//TODO: parse compressor options
|
||||
fmt.Println("Compressor options is NOT currently supported")
|
||||
return nil, errors.New("Has compressor options")
|
||||
return nil, ErrCompressorOptions
|
||||
}
|
||||
return &rdr, nil
|
||||
}
|
||||
|
||||
//GetFilesList returns a list of ALL files in the squashfs, going down every folder.
|
||||
//Paths that terminate in a folder end with /
|
||||
func (r *Reader) GetFilesList() ([]string, error) {
|
||||
inoderdr, err := r.NewBlockReaderFromInodeRef(r.super.RootInodeRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i, err := inode.ProcessInode(inoderdr, r.super.BlockSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paths, err := r.readDir(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return paths, nil
|
||||
}
|
||||
|
||||
//readDir returns a list of all decendents of a given inode. Inode given MUST be a directory type.
|
||||
func (r *Reader) readDir(i *inode.Inode) (paths []string, err error) {
|
||||
dir, err := r.ReadDirFromInode(*i)
|
||||
dir, err := r.ReadDirFromInode(i)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -77,20 +108,10 @@ func (r *Reader) readDir(i *inode.Inode) (paths []string, err error) {
|
||||
}
|
||||
|
||||
func (r *Reader) readDirTable() error {
|
||||
inoderdr, err := r.NewBlockReaderFromInodeRef(r.super.RootInodeRef)
|
||||
paths, err := r.GetFilesList()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i, err := inode.ProcessInode(inoderdr, r.super.BlockSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
paths, err := r.readDir(&i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, path := range paths {
|
||||
fmt.Println(path)
|
||||
}
|
||||
fmt.Println(strings.Join(paths, "\n"))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user