Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support direct filesystem #2

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package disk
import (
"io"

"github.com/masahiro331/go-disk/fs"
"github.com/masahiro331/go-disk/gpt"
"github.com/masahiro331/go-disk/mbr"
"github.com/masahiro331/go-disk/types"
Expand All @@ -16,6 +17,9 @@ type Driver interface {
func NewDriver(sr *io.SectionReader) (Driver, error) {
m, err := mbr.NewMasterBootRecord(sr)
if err != nil {
if xerrors.Is(mbr.InvalidSignature, err) {
masahiro331 marked this conversation as resolved.
Show resolved Hide resolved
return fs.NewDirectFileSystem(sr), nil
}
return nil, xerrors.Errorf("failed to new MBR: %w", err)
}

Expand All @@ -28,4 +32,4 @@ func NewDriver(sr *io.SectionReader) (Driver, error) {
}

return g, nil
}
}
65 changes: 65 additions & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package fs
masahiro331 marked this conversation as resolved.
Show resolved Hide resolved

import (
"io"

"github.com/masahiro331/go-disk/types"
)

type DirectFileSystem struct {
Partition *DirectFileSystemPartition
}

func (d *DirectFileSystem) Next() (types.Partition, error) {
if d.Partition == nil {
return nil, io.EOF
}
partition := d.Partition
d.Partition = nil

return partition, nil
}

type DirectFileSystemPartition struct {
sectionReader *io.SectionReader
}

func (p DirectFileSystemPartition) Index() int {
return 0
}

func (p DirectFileSystemPartition) Name() string {
return "0"
}

func (p DirectFileSystemPartition) GetType() []byte {
return []byte{}
}

func (p DirectFileSystemPartition) GetStartSector() uint64 {
return uint64(0)
}

func (p DirectFileSystemPartition) Bootable() bool {
return false
}

func (p DirectFileSystemPartition) GetSize() uint64 {
return uint64(p.sectionReader.Size())
}

func (p DirectFileSystemPartition) GetSectionReader() io.SectionReader {
return *p.sectionReader
}

func (p DirectFileSystemPartition) IsSupported() bool {
return true
}

func NewDirectFileSystem(sr *io.SectionReader) *DirectFileSystem {
return &DirectFileSystem{
Partition: &DirectFileSystemPartition{
sectionReader: sr,
},
}
}