Finished io/FS interface

This commit is contained in:
Caleb Gardner
2021-01-30 06:30:00 -06:00
parent 3f1b2a8d1e
commit d89153c3e2
9 changed files with 849 additions and 830 deletions
+2 -2
View File
@@ -25,7 +25,7 @@ type EntryRaw struct {
type Entry struct {
Name string
InodeOffset uint32
InodeBlockOffset int16
InodeBlockOffset uint16
Type uint16
}
@@ -42,7 +42,7 @@ func NewEntry(rdr io.Reader) (*Entry, error) {
return nil, err
}
return &Entry{
InodeBlockOffset: raw.InodeOffset,
InodeBlockOffset: raw.Offset,
Type: raw.Type,
Name: string(tmp),
}, nil
+1 -1
View File
@@ -25,7 +25,7 @@ const (
//Header is the common header for all inodes
type Header struct {
InodeType uint16
Type uint16
Permissions uint16
UID uint16
GID uint16
+22 -24
View File
@@ -2,7 +2,9 @@ package inode
import (
"encoding/binary"
"errors"
"io"
"strconv"
)
//Inode holds an inode. Header is the header that's common for all inodes.
@@ -10,121 +12,117 @@ import (
//Info holds the actual Inode. Due to each inode type being a different type, it's store as an interface{}
type Inode struct {
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
Header
}
//ProcessInode tries to read an inode from the BlockReader
func ProcessInode(br io.Reader, blockSize uint32) (*Inode, error) {
var head Header
err := binary.Read(br, binary.LittleEndian, &head)
var in Inode
err := binary.Read(br, binary.LittleEndian, &in.Header)
if err != nil {
return nil, err
}
var info interface{}
switch head.InodeType {
switch in.Type {
case DirType:
var inode Dir
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case FileType:
var inode File
inode, err = NewFile(br, blockSize)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case SymType:
var inode Sym
inode, err = NewSymlink(br)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case BlockDevType:
var inode Device
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case CharDevType:
var inode Device
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case FifoType:
var inode IPC
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case SocketType:
var inode IPC
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtDirType:
var inode ExtDir
inode, err = NewExtendedDirectory(br)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtFileType:
var inode ExtFile
inode, err = NewExtendedFile(br, blockSize)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtSymType:
var inode ExtSym
inode, err = NewExtendedSymlink(br)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtBlockDeviceType:
var inode ExtDevice
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtCharDeviceType:
var inode ExtDevice
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtFifoType:
var inode ExtIPC
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
case ExtSocketType:
var inode ExtIPC
err = binary.Read(br, binary.LittleEndian, &inode)
if err != nil {
return nil, err
}
info = inode
in.Info = inode
default:
return nil, errors.New("Unsupported inode type: " + strconv.Itoa(int(in.Type)))
}
return &Inode{
Type: int(head.InodeType),
Header: head,
Info: info,
}, nil
return &in, nil
}