| 1 |
package fat |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/mitchellh/go-fs" |
| 5 |
) |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
type FileSystem struct { |
| 10 |
bs *BootSectorCommon |
| 11 |
device fs.BlockDevice |
| 12 |
fat *FAT |
| 13 |
rootDir *DirectoryCluster |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
func New(device fs.BlockDevice) (*FileSystem, error) { |
| 19 |
bs, err := DecodeBootSector(device) |
| 20 |
if err != nil { |
| 21 |
return nil, err |
| 22 |
} |
| 23 |
|
| 24 |
fat, err := DecodeFAT(device, bs, 0) |
| 25 |
if err != nil { |
| 26 |
return nil, err |
| 27 |
} |
| 28 |
|
| 29 |
var rootDir *DirectoryCluster |
| 30 |
if bs.FATType() == FAT32 { |
| 31 |
panic("FAT32 not implemented yet") |
| 32 |
} else { |
| 33 |
rootDir, err = DecodeFAT16RootDirectoryCluster(device, bs) |
| 34 |
if err != nil { |
| 35 |
return nil, err |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
result := &FileSystem{ |
| 40 |
bs: bs, |
| 41 |
device: device, |
| 42 |
fat: fat, |
| 43 |
rootDir: rootDir, |
| 44 |
} |
| 45 |
|
| 46 |
return result, nil |
| 47 |
} |
| 48 |
|
| 49 |
func (f *FileSystem) RootDir() (fs.Directory, error) { |
| 50 |
dir := &Directory{ |
| 51 |
device: f.device, |
| 52 |
dirCluster: f.rootDir, |
| 53 |
fat: f.fat, |
| 54 |
} |
| 55 |
|
| 56 |
return dir, nil |
| 57 |
} |