Further work on Inode

This commit is contained in:
Caleb Gardner
2020-11-12 09:50:52 -06:00
parent 8fa093763f
commit 78c35cf720
4 changed files with 154 additions and 21 deletions
+14 -14
View File
@@ -5,17 +5,17 @@ Right Now it's mostly based on [distri's squashfs library](https://github.com/di
Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important information in an easy to understand format Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important information in an easy to understand format
# Ideas I am focusing purely on unsquashing before squashing.
* Link directly to squashfs-tool using cgo
* cgo can be a butt # Working
* Would require the least amount of code for me to do
* Doing things in pure Go is definately highly superior * Reading the header
* Improve [distri's](https://github.com/distr1/distri) or [diskfs](https://github.com/diskfs/go-diskfs) squashfs library to meet my needs * (Maybe) reading gzip compressed data
* Both don't work at all ATM.
* distri's doesn't seem to support any sort of compression, which causes issues all over the place. # Not Working (Yet). Roughly in order.
* diskfs seems closer, but the squashfs code is incomplete
* Create an original squashfs library * Actually reading the compressed data
* MUCH more research needed * Reading Inodes
* Could look at [squashfs-tools'](https://github.com/plougher/squashfs-tools) code to help out * Reading the Directory structure
* Don't have to deal with other people's code :P * Implement other compression types
* Honestly a bit unnecessary based on how close distri & diskfs's code is AND how little I know about squashfs. * Squashing
+50 -6
View File
@@ -1,6 +1,12 @@
package inode package inode
type CommonHeader struct { import (
"encoding/binary"
"io"
)
//InodeCommon is the comon header for all inodes
type InodeCommon struct {
InodeType uint16 InodeType uint16
Permissions uint16 Permissions uint16
UID uint16 UID uint16
@@ -9,6 +15,7 @@ type CommonHeader struct {
Number uint32 Number uint32
} }
//BasicDirectory is self explainatory
type BasicDirectory struct { type BasicDirectory struct {
DirectoryIndex uint32 DirectoryIndex uint32
HardLinks uint32 HardLinks uint32
@@ -17,6 +24,7 @@ type BasicDirectory struct {
ParentInodeNumber uint32 ParentInodeNumber uint32
} }
//ExtendedDirectoryInit is the information that can be directoy decoded
type ExtendedDirectoryInit struct { type ExtendedDirectoryInit struct {
HardLinks uint32 HardLinks uint32
DirectorySize uint32 DirectorySize uint32
@@ -27,19 +35,31 @@ type ExtendedDirectoryInit struct {
XattrIndex uint32 XattrIndex uint32
} }
//ExtendedDirectory is a directory with extra info
type ExtendedDirectory struct { type ExtendedDirectory struct {
ExtendedDirectoryInit Init ExtendedDirectoryInit
//TODO indexes []DirectoryIndex //TODO: indexes []DirectoryIndex
} }
//NewExtendedDirectory creates a new ExtendedDirectory
func NewExtendedDirectory(rdr *io.Reader) (*ExtendedDirectory, error) {
var inode ExtendedDirectory
err := binary.Read(*rdr, binary.LittleEndian, inode.Init)
//TODO: Read directory indexes
return &inode, err
}
//BasicFile is self explainatory
type BasicFile struct { type BasicFile struct {
BlockStart uint32 BlockStart uint32
FragmentIndex uint32 FragmentIndex uint32
FragmentOffset uint32 FragmentOffset uint32
Size uint32 Size uint32
BlockSizes []uint32 BlockSizes []uint32
//TODO: possibly fix BlockSizes
} }
//ExtendedFile is a file with additional information
type ExtendedFile struct { type ExtendedFile struct {
BlockStart uint32 BlockStart uint32
Size uint32 Size uint32
@@ -49,6 +69,7 @@ type ExtendedFile struct {
FragmentOffset uint32 FragmentOffset uint32
XattrIndex uint32 XattrIndex uint32
BlockSizes []uint32 BlockSizes []uint32
//TODO: possibly fix BlockSizes
} }
type BasicSymlinkInit struct { type BasicSymlinkInit struct {
@@ -57,8 +78,19 @@ type BasicSymlinkInit struct {
} }
type BasicSymlink struct { type BasicSymlink struct {
BasicSymlinkInit Init BasicSymlinkInit
targetPath []byte //len is TargetPathSize targetPath []uint8 //len is TargetPathSize
}
func NewBasicSymlink(rdr *io.Reader) (*BasicSymlink, error) {
var inode BasicSymlink
err := binary.Read(*rdr, binary.LittleEndian, inode.Init)
if err != nil {
return nil, err
}
inode.targetPath = make([]uint8, inode.Init.TargetPathSize)
err = binary.Read(*rdr, binary.LittleEndian, inode.targetPath)
return &inode, err
} }
type ExtendedSymlinkInit struct { type ExtendedSymlinkInit struct {
@@ -67,10 +99,22 @@ type ExtendedSymlinkInit struct {
} }
type ExtendedSymlink struct { type ExtendedSymlink struct {
targetPath []byte Init ExtendedSymlinkInit
TargetPath []uint8
XattrIndex uint32 XattrIndex uint32
} }
func NewExtendedSymlink(rdr *io.Reader) (*ExtendedSymlink, error) {
var inode ExtendedSymlink
err := binary.Read(*rdr, binary.LittleEndian, inode.Init)
if err != nil {
return &inode, err
}
inode.TargetPath = make([]uint8, inode.Init.TargetPathSize)
err = binary.Read(*rdr, binary.LittleEndian, &inode.XattrIndex)
return &inode, err
}
type BasicDevice struct { type BasicDevice struct {
HardLinks uint32 HardLinks uint32
Device uint32 Device uint32
+89
View File
@@ -0,0 +1,89 @@
package inode
import (
"encoding/binary"
"errors"
"io"
"strconv"
)
const (
basicDirectory = iota + 1
basicFile
basicSymlink
basicBlockDevice
basicCharDevice
basicFifo
basicSocket
extendedDirectory
extendedFile
extendedSymlink
extendedBlockDevice
extendedCharDevice
extendedFifo
extendedSocket
)
func ProcessInode(rdr *io.Reader) (*InodeCommon, interface{}, error) {
var inodeHeader InodeCommon
err := binary.Read(*rdr, binary.LittleEndian, &inodeHeader)
if err != nil {
return nil, nil, err
}
switch inodeHeader.InodeType {
case basicDirectory:
var inode BasicDirectory
err = binary.Read(*rdr, binary.LittleEndian, &inode)
return &inodeHeader, inode, err
case basicFile:
var inode BasicFile
err = binary.Read(*rdr, binary.LittleEndian, &inode)
return &inodeHeader, inode, err
case basicSymlink:
inode, err := NewBasicSymlink(rdr)
return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
// case basicFile:
// var inode BasicFile
// err = binary.Read(*rdr, binary.LittleEndian, &inode)
// return &inodeHeader, inode, err
//TODO: implement ALL cases
default:
return nil, nil, errors.New("Inode type is unrecognized: " + strconv.FormatInt(int64(inodeHeader.InodeType), 2))
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ func (r *Reader) Seek(offset int64, whence int) (int64, error) {
n, err := r.Read(make([]byte, offset)) n, err := r.Read(make([]byte, offset))
return int64(n), err return int64(n), err
case io.SeekEnd: case io.SeekEnd:
return 0, errors.New("SeekEnd is NOT currently supported") return 0, errors.New("SeekEnd is NOT supported")
} }
return 0, errors.New("incorrect whence") return 0, errors.New("incorrect whence")
} }