-
Notifications
You must be signed in to change notification settings - Fork 2
/
disk.go
37 lines (32 loc) · 916 Bytes
/
disk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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"
"golang.org/x/xerrors"
)
func NewDriver(sr *io.SectionReader, checkFsFuncs ...fs.CheckFsFunc) (types.Driver, error) {
m, err := mbr.NewMasterBootRecord(sr)
if err != nil {
if xerrors.Is(mbr.InvalidSignature, err) {
ok, err := fs.CheckFileSystems(sr, checkFsFuncs)
if err != nil {
return nil, xerrors.Errorf("failed to check filesystem: %w", err)
}
if ok {
return fs.NewDirectFileSystem(sr)
}
}
return nil, xerrors.Errorf("failed to new MBR: %w", err)
}
g, err := gpt.NewGUIDPartitionTable(sr)
if err != nil {
if m.UniqueMBRDiskSignature != [4]byte{0x00, 0x00, 0x00, 0x00} {
return m, nil
}
return nil, xerrors.Errorf("failed to parse GUID partition table: %w", err)
}
return g, nil
}