Some cleanup, no change in functionality
This commit is contained in:
+7
-7
@@ -63,12 +63,12 @@ func (r *Reader) newDataReaderFromInode(i *inode.Inode) (*dataReader, error) {
|
|||||||
var rdr dataReader
|
var rdr dataReader
|
||||||
rdr.r = r
|
rdr.r = r
|
||||||
switch i.Type {
|
switch i.Type {
|
||||||
case inode.BasicFileType:
|
case inode.FileType:
|
||||||
fil := i.Info.(inode.BasicFile)
|
fil := i.Info.(inode.File)
|
||||||
if fil.Init.BlockStart == 0 {
|
if fil.BlockStart == 0 {
|
||||||
return nil, errInodeOnlyFragment
|
return nil, errInodeOnlyFragment
|
||||||
}
|
}
|
||||||
rdr.offset = int64(fil.Init.BlockStart)
|
rdr.offset = int64(fil.BlockStart)
|
||||||
for _, sizes := range fil.BlockSizes {
|
for _, sizes := range fil.BlockSizes {
|
||||||
rdr.blocks = append(rdr.blocks, newDataBlock(sizes))
|
rdr.blocks = append(rdr.blocks, newDataBlock(sizes))
|
||||||
}
|
}
|
||||||
@@ -76,11 +76,11 @@ func (r *Reader) newDataReaderFromInode(i *inode.Inode) (*dataReader, error) {
|
|||||||
rdr.blocks = rdr.blocks[:len(rdr.blocks)-1]
|
rdr.blocks = rdr.blocks[:len(rdr.blocks)-1]
|
||||||
}
|
}
|
||||||
case inode.ExtFileType:
|
case inode.ExtFileType:
|
||||||
fil := i.Info.(inode.ExtendedFile)
|
fil := i.Info.(inode.ExtFile)
|
||||||
if fil.Init.BlockStart == 0 {
|
if fil.BlockStart == 0 {
|
||||||
return nil, errInodeOnlyFragment
|
return nil, errInodeOnlyFragment
|
||||||
}
|
}
|
||||||
rdr.offset = int64(fil.Init.BlockStart)
|
rdr.offset = int64(fil.BlockStart)
|
||||||
for _, sizes := range fil.BlockSizes {
|
for _, sizes := range fil.BlockSizes {
|
||||||
rdr.blocks = append(rdr.blocks, newDataBlock(sizes))
|
rdr.blocks = append(rdr.blocks, newDataBlock(sizes))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ func (f *File) Name() string {
|
|||||||
//Size is the complete size of the file. Zero if it's not a file.
|
//Size is the complete size of the file. Zero if it's not a file.
|
||||||
func (f *File) Size() int64 {
|
func (f *File) Size() int64 {
|
||||||
switch f.filType {
|
switch f.filType {
|
||||||
case inode.BasicFileType:
|
case inode.FileType:
|
||||||
return int64(f.in.Info.(inode.BasicFile).Init.Size)
|
return int64(f.in.Info.(inode.File).Size)
|
||||||
case inode.ExtFileType:
|
case inode.ExtFileType:
|
||||||
return int64(f.in.Info.(inode.ExtendedFile).Init.Size)
|
return int64(f.in.Info.(inode.ExtFile).Size)
|
||||||
default:
|
default:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -204,27 +204,27 @@ func (f *File) GetFileAtPath(dirPath string) *File {
|
|||||||
|
|
||||||
//IsDir returns if the file is a directory.
|
//IsDir returns if the file is a directory.
|
||||||
func (f *File) IsDir() bool {
|
func (f *File) IsDir() bool {
|
||||||
return f.filType == inode.BasicDirectoryType || f.filType == inode.ExtDirType
|
return f.filType == inode.DirType || f.filType == inode.ExtDirType
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsSymlink returns if the file is a symlink.
|
//IsSymlink returns if the file is a symlink.
|
||||||
func (f *File) IsSymlink() bool {
|
func (f *File) IsSymlink() bool {
|
||||||
return f.filType == inode.BasicSymlinkType || f.filType == inode.ExtSymlinkType
|
return f.filType == inode.SymType || f.filType == inode.ExtSymlinkType
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsFile returns if the file is a file.
|
//IsFile returns if the file is a file.
|
||||||
func (f *File) IsFile() bool {
|
func (f *File) IsFile() bool {
|
||||||
return f.filType == inode.BasicFileType || f.filType == inode.ExtFileType
|
return f.filType == inode.FileType || f.filType == inode.ExtFileType
|
||||||
}
|
}
|
||||||
|
|
||||||
//SymlinkPath returns the path the symlink is pointing to. If the file ISN'T a symlink, will return an empty string.
|
//SymlinkPath returns the path the symlink is pointing to. If the file ISN'T a symlink, will return an empty string.
|
||||||
//If a path begins with "/" then the symlink is pointing to an absolute path (starting from root, and not a file inside the archive)
|
//If a path begins with "/" then the symlink is pointing to an absolute path (starting from root, and not a file inside the archive)
|
||||||
func (f *File) SymlinkPath() string {
|
func (f *File) SymlinkPath() string {
|
||||||
switch f.filType {
|
switch f.filType {
|
||||||
case inode.BasicSymlinkType:
|
case inode.SymType:
|
||||||
return f.in.Info.(inode.BasicSymlink).Path
|
return f.in.Info.(inode.Sym).Path
|
||||||
case inode.ExtSymlinkType:
|
case inode.ExtSymlinkType:
|
||||||
return f.in.Info.(inode.ExtendedSymlink).Path
|
return f.in.Info.(inode.Sym).Path
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -500,14 +500,14 @@ func (r *Reader) readDirFromInode(i *inode.Inode) (*directory.Directory, error)
|
|||||||
var metaOffset uint16
|
var metaOffset uint16
|
||||||
var size uint32
|
var size uint32
|
||||||
switch i.Type {
|
switch i.Type {
|
||||||
case inode.BasicDirectoryType:
|
case inode.DirType:
|
||||||
offset = i.Info.(inode.BasicDirectory).DirectoryIndex
|
offset = i.Info.(inode.Dir).DirectoryIndex
|
||||||
metaOffset = i.Info.(inode.BasicDirectory).DirectoryOffset
|
metaOffset = i.Info.(inode.Dir).DirectoryOffset
|
||||||
size = uint32(i.Info.(inode.BasicDirectory).DirectorySize)
|
size = uint32(i.Info.(inode.Dir).DirectorySize)
|
||||||
case inode.ExtDirType:
|
case inode.ExtDirType:
|
||||||
offset = i.Info.(inode.ExtendedDirectory).Init.DirectoryIndex
|
offset = i.Info.(inode.ExtDir).DirectoryIndex
|
||||||
metaOffset = i.Info.(inode.ExtendedDirectory).Init.DirectoryOffset
|
metaOffset = i.Info.(inode.ExtDir).DirectoryOffset
|
||||||
size = i.Info.(inode.ExtendedDirectory).Init.DirectorySize
|
size = i.Info.(inode.ExtDir).DirectorySize
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Not a directory inode")
|
return nil, errors.New("Not a directory inode")
|
||||||
}
|
}
|
||||||
@@ -532,7 +532,7 @@ func (r *Reader) getInodeFromEntry(en *directory.Entry) (*inode.Inode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, err = br.Seek(int64(en.Init.Offset), io.SeekStart)
|
_, err = br.Seek(int64(en.Offset), io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -29,20 +29,20 @@ var (
|
|||||||
func (r *Reader) newFileReader(in *inode.Inode) (*fileReader, error) {
|
func (r *Reader) newFileReader(in *inode.Inode) (*fileReader, error) {
|
||||||
var rdr fileReader
|
var rdr fileReader
|
||||||
rdr.in = in
|
rdr.in = in
|
||||||
if in.Type != inode.BasicFileType && in.Type != inode.ExtFileType {
|
if in.Type != inode.FileType && in.Type != inode.ExtFileType {
|
||||||
return nil, errPathIsNotFile
|
return nil, errPathIsNotFile
|
||||||
}
|
}
|
||||||
switch in.Type {
|
switch in.Type {
|
||||||
case inode.BasicFileType:
|
case inode.FileType:
|
||||||
fil := in.Info.(inode.BasicFile)
|
fil := in.Info.(inode.File)
|
||||||
rdr.fragged = fil.Fragmented
|
rdr.fragged = fil.Fragmented
|
||||||
rdr.fragOnly = fil.Init.BlockStart == 0
|
rdr.fragOnly = fil.BlockStart == 0
|
||||||
rdr.FileSize = int(fil.Init.Size)
|
rdr.FileSize = int(fil.Size)
|
||||||
case inode.ExtFileType:
|
case inode.ExtFileType:
|
||||||
fil := in.Info.(inode.ExtendedFile)
|
fil := in.Info.(inode.ExtFile)
|
||||||
rdr.fragged = fil.Fragmented
|
rdr.fragged = fil.Fragmented
|
||||||
rdr.fragOnly = fil.Init.BlockStart == 0
|
rdr.fragOnly = fil.BlockStart == 0
|
||||||
rdr.FileSize = int(fil.Init.Size)
|
rdr.FileSize = int(fil.Size)
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if rdr.fragged {
|
if rdr.fragged {
|
||||||
|
|||||||
+11
-11
@@ -21,30 +21,30 @@ func (r *Reader) getFragmentDataFromInode(in *inode.Inode) ([]byte, error) {
|
|||||||
var size uint32
|
var size uint32
|
||||||
var fragIndex uint32
|
var fragIndex uint32
|
||||||
var fragOffset uint32
|
var fragOffset uint32
|
||||||
if in.Type == inode.BasicFileType {
|
if in.Type == inode.FileType {
|
||||||
bf := in.Info.(inode.BasicFile)
|
bf := in.Info.(inode.File)
|
||||||
if !bf.Fragmented {
|
if !bf.Fragmented {
|
||||||
return make([]byte, 0), nil
|
return make([]byte, 0), nil
|
||||||
}
|
}
|
||||||
if bf.Init.BlockStart == 0 {
|
if bf.BlockStart == 0 {
|
||||||
size = bf.Init.Size
|
size = bf.Size
|
||||||
} else {
|
} else {
|
||||||
size = bf.BlockSizes[len(bf.BlockSizes)-1]
|
size = bf.BlockSizes[len(bf.BlockSizes)-1]
|
||||||
}
|
}
|
||||||
fragIndex = bf.Init.FragmentIndex
|
fragIndex = bf.FragmentIndex
|
||||||
fragOffset = bf.Init.FragmentOffset
|
fragOffset = bf.FragmentOffset
|
||||||
} else if in.Type == inode.ExtFileType {
|
} else if in.Type == inode.ExtFileType {
|
||||||
bf := in.Info.(inode.ExtendedFile)
|
bf := in.Info.(inode.ExtFile)
|
||||||
if !bf.Fragmented {
|
if !bf.Fragmented {
|
||||||
return make([]byte, 0), nil
|
return make([]byte, 0), nil
|
||||||
}
|
}
|
||||||
if bf.Init.BlockStart == 0 {
|
if bf.BlockStart == 0 {
|
||||||
size = bf.Init.Size
|
size = bf.Size
|
||||||
} else {
|
} else {
|
||||||
size = bf.BlockSizes[len(bf.BlockSizes)-1]
|
size = bf.BlockSizes[len(bf.BlockSizes)-1]
|
||||||
}
|
}
|
||||||
fragIndex = bf.Init.FragmentIndex
|
fragIndex = bf.FragmentIndex
|
||||||
fragOffset = bf.Init.FragmentOffset
|
fragOffset = bf.FragmentOffset
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Inode type not supported")
|
return nil, errors.New("Inode type not supported")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ type Header struct {
|
|||||||
InodeNumber uint32
|
InodeNumber uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//EntryInit is the values that can be easily decoded
|
//EntryRaw is the values that can be easily decoded
|
||||||
type EntryInit struct {
|
type EntryRaw struct {
|
||||||
Offset uint16
|
Offset uint16
|
||||||
InodeOffset int16
|
InodeOffset int16
|
||||||
Type uint16
|
Type uint16
|
||||||
@@ -23,19 +23,19 @@ type EntryInit struct {
|
|||||||
|
|
||||||
//Entry is an entry in a directory.
|
//Entry is an entry in a directory.
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
Init EntryInit
|
*Header
|
||||||
Name string
|
Name string
|
||||||
Header *Header
|
EntryRaw
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewEntry creates a new directory entry
|
//NewEntry creates a new directory entry
|
||||||
func NewEntry(rdr io.Reader) (Entry, error) {
|
func NewEntry(rdr io.Reader) (Entry, error) {
|
||||||
var entry Entry
|
var entry Entry
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &entry.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &entry.EntryRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Entry{}, err
|
return Entry{}, err
|
||||||
}
|
}
|
||||||
tmp := make([]byte, entry.Init.NameSize+1)
|
tmp := make([]byte, entry.EntryRaw.NameSize+1)
|
||||||
err = binary.Read(rdr, binary.LittleEndian, &tmp)
|
err = binary.Read(rdr, binary.LittleEndian, &tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Entry{}, err
|
return Entry{}, err
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//The different types of inodes as defined by inodetype
|
||||||
const (
|
const (
|
||||||
BasicDirectoryType = iota + 1
|
DirType = iota + 1
|
||||||
BasicFileType
|
FileType
|
||||||
BasicSymlinkType
|
SymType
|
||||||
BasicBlockDeviceType
|
BlockDevType
|
||||||
BasicCharDeviceType
|
CharDevType
|
||||||
BasicFifoType
|
FifoType
|
||||||
BasicSocketType
|
SocketType
|
||||||
ExtDirType
|
ExtDirType
|
||||||
ExtFileType
|
ExtFileType
|
||||||
ExtSymlinkType
|
ExtSymlinkType
|
||||||
@@ -32,8 +33,8 @@ type Header struct {
|
|||||||
Number uint32
|
Number uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicDirectory is self explainatory
|
//Dir is self explainatory
|
||||||
type BasicDirectory struct {
|
type Dir struct {
|
||||||
DirectoryIndex uint32
|
DirectoryIndex uint32
|
||||||
HardLinks uint32
|
HardLinks uint32
|
||||||
DirectorySize uint16
|
DirectorySize uint16
|
||||||
@@ -41,8 +42,8 @@ type BasicDirectory struct {
|
|||||||
ParentInodeNumber uint32
|
ParentInodeNumber uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedDirectoryInit is the information that can be directoy decoded
|
//ExtDirInit is the information that can be directoy decoded
|
||||||
type ExtendedDirectoryInit struct {
|
type ExtDirInit struct {
|
||||||
HardLinks uint32
|
HardLinks uint32
|
||||||
DirectorySize uint32
|
DirectorySize uint32
|
||||||
DirectoryIndex uint32
|
DirectoryIndex uint32
|
||||||
@@ -52,20 +53,20 @@ type ExtendedDirectoryInit struct {
|
|||||||
XattrIndex uint32
|
XattrIndex uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedDirectory is a directory with extra info
|
//ExtDir is a directory with extra info
|
||||||
type ExtendedDirectory struct {
|
type ExtDir struct {
|
||||||
Init ExtendedDirectoryInit
|
Indexes []DirIndex
|
||||||
Indexes []DirectoryIndex
|
ExtDirInit
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewExtendedDirectory creates a new ExtendedDirectory
|
//NewExtendedDirectory creates a new ExtendedDirectory
|
||||||
func NewExtendedDirectory(rdr io.Reader) (ExtendedDirectory, error) {
|
func NewExtendedDirectory(rdr io.Reader) (ExtDir, error) {
|
||||||
var inode ExtendedDirectory
|
var inode ExtDir
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &inode.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &inode.ExtDirInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
for i := uint16(0); i < inode.Init.IndexCount; i++ {
|
for i := uint16(0); i < inode.IndexCount; i++ {
|
||||||
tmp, err := NewDirectoryIndex(rdr)
|
tmp, err := NewDirectoryIndex(rdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
@@ -75,27 +76,27 @@ func NewExtendedDirectory(rdr io.Reader) (ExtendedDirectory, error) {
|
|||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//DirectoryIndexInit holds the values that can be easily decoded
|
//DirIndexInit holds the values that can be easily decoded
|
||||||
type DirectoryIndexInit struct {
|
type DirIndexInit struct {
|
||||||
Offset uint32
|
Offset uint32
|
||||||
DirTableOffset uint32
|
DirTableOffset uint32
|
||||||
NameSize uint32
|
NameSize uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//DirectoryIndex is a quick lookup provided by an ExtendedDirectory
|
//DirIndex is a quick lookup provided by an ExtendedDirectory
|
||||||
type DirectoryIndex struct {
|
type DirIndex struct {
|
||||||
Init DirectoryIndexInit
|
|
||||||
Name string
|
Name string
|
||||||
|
DirIndexInit
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewDirectoryIndex return a new DirectoryIndex
|
//NewDirectoryIndex return a new DirectoryIndex
|
||||||
func NewDirectoryIndex(rdr io.Reader) (DirectoryIndex, error) {
|
func NewDirectoryIndex(rdr io.Reader) (DirIndex, error) {
|
||||||
var index DirectoryIndex
|
var index DirIndex
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &index.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &index.DirIndexInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return index, err
|
return index, err
|
||||||
}
|
}
|
||||||
tmp := make([]byte, index.Init.NameSize+1, index.Init.NameSize+1)
|
tmp := make([]byte, index.NameSize+1, index.NameSize+1)
|
||||||
err = binary.Read(rdr, binary.LittleEndian, &tmp)
|
err = binary.Read(rdr, binary.LittleEndian, &tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return index, err
|
return index, err
|
||||||
@@ -104,31 +105,31 @@ func NewDirectoryIndex(rdr io.Reader) (DirectoryIndex, error) {
|
|||||||
return index, nil
|
return index, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicFileInit is the information that can be directoy decoded
|
//FileInit is the information that can be directly decoded
|
||||||
type BasicFileInit struct {
|
type FileInit struct {
|
||||||
BlockStart uint32
|
BlockStart uint32
|
||||||
FragmentIndex uint32
|
FragmentIndex uint32
|
||||||
FragmentOffset uint32
|
FragmentOffset uint32
|
||||||
Size uint32
|
Size uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicFile is self explainatory
|
//File is self explainatory
|
||||||
type BasicFile struct {
|
type File struct {
|
||||||
Init BasicFileInit
|
|
||||||
BlockSizes []uint32
|
BlockSizes []uint32
|
||||||
Fragmented bool
|
Fragmented bool
|
||||||
|
FileInit
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewBasicFile creates a new BasicFile
|
//NewFile creates a new File
|
||||||
func NewBasicFile(rdr io.Reader, blockSize uint32) (BasicFile, error) {
|
func NewFile(rdr io.Reader, blockSize uint32) (File, error) {
|
||||||
var inode BasicFile
|
var inode File
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &inode.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &inode.FileInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
inode.Fragmented = inode.Init.FragmentIndex != 0xFFFFFFFF
|
inode.Fragmented = inode.FragmentIndex != 0xFFFFFFFF
|
||||||
blocks := inode.Init.Size / blockSize
|
blocks := inode.Size / blockSize
|
||||||
if inode.Init.Size%blockSize > 0 {
|
if inode.Size%blockSize > 0 {
|
||||||
blocks++
|
blocks++
|
||||||
}
|
}
|
||||||
inode.BlockSizes = make([]uint32, blocks, blocks)
|
inode.BlockSizes = make([]uint32, blocks, blocks)
|
||||||
@@ -136,8 +137,8 @@ func NewBasicFile(rdr io.Reader, blockSize uint32) (BasicFile, error) {
|
|||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedFileInit is the information that can be directly decoded
|
//ExtFileInit is the information that can be directly decoded
|
||||||
type ExtendedFileInit struct {
|
type ExtFileInit struct {
|
||||||
BlockStart uint32
|
BlockStart uint32
|
||||||
Size uint32
|
Size uint32
|
||||||
Sparse uint64
|
Sparse uint64
|
||||||
@@ -147,23 +148,23 @@ type ExtendedFileInit struct {
|
|||||||
XattrIndex uint32
|
XattrIndex uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedFile is a file with more information
|
//ExtFile is a file with more information
|
||||||
type ExtendedFile struct {
|
type ExtFile struct {
|
||||||
Init ExtendedFileInit
|
|
||||||
BlockSizes []uint32
|
BlockSizes []uint32
|
||||||
Fragmented bool
|
Fragmented bool
|
||||||
|
ExtFileInit
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewExtendedFile creates a new ExtendedFile
|
//NewExtendedFile creates a new ExtendedFile
|
||||||
func NewExtendedFile(rdr io.Reader, blockSize uint32) (ExtendedFile, error) {
|
func NewExtendedFile(rdr io.Reader, blockSize uint32) (ExtFile, error) {
|
||||||
var inode ExtendedFile
|
var inode ExtFile
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &inode.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &inode.ExtFileInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
inode.Fragmented = inode.Init.FragmentIndex != 0xFFFFFFFF
|
inode.Fragmented = inode.FragmentIndex != 0xFFFFFFFF
|
||||||
blocks := inode.Init.Size / blockSize
|
blocks := inode.Size / blockSize
|
||||||
if inode.Init.Size%blockSize > 0 {
|
if inode.Size%blockSize > 0 {
|
||||||
blocks++
|
blocks++
|
||||||
}
|
}
|
||||||
inode.BlockSizes = make([]uint32, blocks, blocks)
|
inode.BlockSizes = make([]uint32, blocks, blocks)
|
||||||
@@ -171,27 +172,27 @@ func NewExtendedFile(rdr io.Reader, blockSize uint32) (ExtendedFile, error) {
|
|||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicSymlinkInit is all the values that can be directly decoded
|
//SymInit is all the values that can be directly decoded
|
||||||
type BasicSymlinkInit struct {
|
type SymInit struct {
|
||||||
HardLinks uint32
|
HardLinks uint32
|
||||||
TargetPathSize uint32
|
TargetPathSize uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicSymlink is a symlink
|
//Sym is a symlink
|
||||||
type BasicSymlink struct {
|
type Sym struct {
|
||||||
Init BasicSymlinkInit
|
|
||||||
targetPath []byte //len is TargetPathSize
|
|
||||||
Path string
|
Path string
|
||||||
|
targetPath []byte //len is TargetPathSize
|
||||||
|
SymInit
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewBasicSymlink creates a new BasicSymlink
|
//NewSymlink creates a new Symlink
|
||||||
func NewBasicSymlink(rdr io.Reader) (BasicSymlink, error) {
|
func NewSymlink(rdr io.Reader) (Sym, error) {
|
||||||
var inode BasicSymlink
|
var inode Sym
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &inode.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &inode.SymInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
inode.targetPath = make([]byte, inode.Init.TargetPathSize, inode.Init.TargetPathSize)
|
inode.targetPath = make([]byte, inode.TargetPathSize, inode.TargetPathSize)
|
||||||
err = binary.Read(rdr, binary.LittleEndian, &inode.targetPath)
|
err = binary.Read(rdr, binary.LittleEndian, &inode.targetPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
@@ -200,28 +201,28 @@ func NewBasicSymlink(rdr io.Reader) (BasicSymlink, error) {
|
|||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedSymlinkInit is all the values that can be directly decoded
|
//ExtSymInit is all the values that can be directly decoded
|
||||||
type ExtendedSymlinkInit struct {
|
type ExtSymInit struct {
|
||||||
HardLinks uint32
|
HardLinks uint32
|
||||||
TargetPathSize uint32
|
TargetPathSize uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedSymlink is a symlink with extra information
|
//ExtSym is a symlink with extra information
|
||||||
type ExtendedSymlink struct {
|
type ExtSym struct {
|
||||||
Init ExtendedSymlinkInit
|
|
||||||
targetPath []uint8
|
|
||||||
Path string
|
Path string
|
||||||
|
targetPath []uint8
|
||||||
|
ExtSymInit
|
||||||
XattrIndex uint32
|
XattrIndex uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewExtendedSymlink creates a new ExtendedSymlink
|
//NewExtendedSymlink creates a new ExtendedSymlink
|
||||||
func NewExtendedSymlink(rdr io.Reader) (ExtendedSymlink, error) {
|
func NewExtendedSymlink(rdr io.Reader) (ExtSym, error) {
|
||||||
var inode ExtendedSymlink
|
var inode ExtSym
|
||||||
err := binary.Read(rdr, binary.LittleEndian, &inode.Init)
|
err := binary.Read(rdr, binary.LittleEndian, &inode.ExtSymInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
inode.targetPath = make([]uint8, inode.Init.TargetPathSize, inode.Init.TargetPathSize)
|
inode.targetPath = make([]uint8, inode.TargetPathSize, inode.TargetPathSize)
|
||||||
err = binary.Read(rdr, binary.LittleEndian, &inode.targetPath)
|
err = binary.Read(rdr, binary.LittleEndian, &inode.targetPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return inode, err
|
return inode, err
|
||||||
@@ -231,25 +232,25 @@ func NewExtendedSymlink(rdr io.Reader) (ExtendedSymlink, error) {
|
|||||||
return inode, err
|
return inode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicDevice is a device
|
//Device is a device
|
||||||
type BasicDevice struct {
|
type Device struct {
|
||||||
HardLinks uint32
|
HardLinks uint32
|
||||||
Device uint32
|
Device uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedDevice is a device with more info
|
//ExtDevice is a device with more info
|
||||||
type ExtendedDevice struct {
|
type ExtDevice struct {
|
||||||
BasicDevice
|
Device
|
||||||
XattrIndex uint32
|
XattrIndex uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//BasicIPC is a Fifo or Socket device
|
//IPC is a Fifo or Socket device
|
||||||
type BasicIPC struct {
|
type IPC struct {
|
||||||
HardLink uint32
|
HardLink uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
//ExtendedIPC is a IPC device with extra info
|
//ExtIPC is a IPC device with extra info
|
||||||
type ExtendedIPC struct {
|
type ExtIPC struct {
|
||||||
BasicIPC
|
IPC
|
||||||
XattrIndex uint32
|
XattrIndex uint32
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -9,9 +9,9 @@ import (
|
|||||||
//
|
//
|
||||||
//Info holds the actual Inode. Due to each inode type being a different type, it's store as an interface{}
|
//Info holds the actual Inode. Due to each inode type being a different type, it's store as an interface{}
|
||||||
type Inode struct {
|
type Inode struct {
|
||||||
Header Header
|
Info interface{} //Info is the parsed specific data. It's type is defined by Type.
|
||||||
Type int //Type the inode type defined in the header. Here so it's easy to access
|
Type int //Type the inode type defined in the header. Here so it's easy to access
|
||||||
Info interface{} //Info is the parsed specific data. It's type is defined by Type.
|
Header
|
||||||
}
|
}
|
||||||
|
|
||||||
//ProcessInode tries to read an inode from the BlockReader
|
//ProcessInode tries to read an inode from the BlockReader
|
||||||
@@ -23,48 +23,48 @@ func ProcessInode(br io.Reader, blockSize uint32) (*Inode, error) {
|
|||||||
}
|
}
|
||||||
var info interface{}
|
var info interface{}
|
||||||
switch head.InodeType {
|
switch head.InodeType {
|
||||||
case BasicDirectoryType:
|
case DirType:
|
||||||
var inode BasicDirectory
|
var inode Dir
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicFileType:
|
case FileType:
|
||||||
inode, err := NewBasicFile(br, blockSize)
|
inode, err := NewFile(br, blockSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicSymlinkType:
|
case SymType:
|
||||||
inode, err := NewBasicSymlink(br)
|
inode, err := NewSymlink(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicBlockDeviceType:
|
case BlockDevType:
|
||||||
var inode BasicDevice
|
var inode Device
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicCharDeviceType:
|
case CharDevType:
|
||||||
var inode BasicDevice
|
var inode Device
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicFifoType:
|
case FifoType:
|
||||||
var inode BasicIPC
|
var inode IPC
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case BasicSocketType:
|
case SocketType:
|
||||||
var inode BasicIPC
|
var inode IPC
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -89,28 +89,28 @@ func ProcessInode(br io.Reader, blockSize uint32) (*Inode, error) {
|
|||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case ExtBlockDeviceType:
|
case ExtBlockDeviceType:
|
||||||
var inode ExtendedDevice
|
var inode ExtDevice
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case ExtCharDeviceType:
|
case ExtCharDeviceType:
|
||||||
var inode ExtendedDevice
|
var inode ExtDevice
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case ExtFifoType:
|
case ExtFifoType:
|
||||||
var inode ExtendedIPC
|
var inode ExtIPC
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info = inode
|
info = inode
|
||||||
case ExtSocketType:
|
case ExtSocketType:
|
||||||
var inode ExtendedIPC
|
var inode ExtIPC
|
||||||
err = binary.Read(br, binary.LittleEndian, &inode)
|
err = binary.Read(br, binary.LittleEndian, &inode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user