Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions fat/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func DecodeDirectoryEntry(d *Directory, entries []*DirectoryClusterEntry) (*Dire
// We have a long entry, so we have to traverse to the point where
// we're done. Also, calculate out the name and such.
if entries[0].IsLong() {
lfnEntries := make([]*DirectoryClusterEntry, 0, 3)
lfnEntries = make([]*DirectoryClusterEntry, 0, 3)
for entries[0].IsLong() {
lfnEntries = append(lfnEntries, entries[0])
entries = entries[1:]
}

var nameBytes []rune
nameBytes = make([]rune, 13*len(lfnEntries))
nameBytes = make([]rune, 0, 13*len(lfnEntries))
for i := len(lfnEntries) - 1; i >= 0; i-- {
for _, char := range lfnEntries[i].longName {
nameBytes = append(nameBytes, char)
Expand Down
16 changes: 14 additions & 2 deletions fat/directory_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ func DecodeDirectoryCluster(startCluster uint32, device fs.BlockDevice, fat *FAT
return result, nil
}

// DecodeFAT32RootDirectory decodes the FAT32 root directory structure
// from the device.
func DecodeFAT32RootDirectoryCluster(device fs.BlockDevice, fat *FAT) (*DirectoryCluster, error) {
// 2 is typcially the root dir for fat32
// FIXME: read from BootSectorCommon and BPB_RootClus there
return DecodeDirectoryCluster(2, device, fat)

}

// DecodeFAT16RootDirectory decodes the FAT16 root directory structure
// from the device.
func DecodeFAT16RootDirectoryCluster(device fs.BlockDevice, bs *BootSectorCommon) (*DirectoryCluster, error) {
Expand Down Expand Up @@ -304,7 +313,7 @@ func (d *DirectoryClusterEntry) IsLong() bool {
}

func (d *DirectoryClusterEntry) IsVolumeId() bool {
return (d.attr & AttrVolumeId) == AttrVolumeId
return d.attr == AttrVolumeId
}

// DecodeDirectoryClusterEntry decodes a single directory entry in the
Expand Down Expand Up @@ -332,8 +341,11 @@ func DecodeDirectoryClusterEntry(data []byte) (*DirectoryClusterEntry, error) {
offset := 28 + (i * 2)
chars[i+11] = binary.LittleEndian.Uint16(data[offset : offset+2])
}

result.longName = string(utf16.Decode(chars))
idx := strings.IndexByte(result.longName, 0)
if idx > 0 {
result.longName = result.longName[:idx]
}
result.longChecksum = data[13]
} else {
result.deleted = data[0] == 0xE5
Expand Down
3 changes: 2 additions & 1 deletion fat/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func New(device fs.BlockDevice) (*FileSystem, error) {

var rootDir *DirectoryCluster
if bs.FATType() == FAT32 {
panic("FAT32 not implemented yet")
// WARNING: very experimental and incomplete
rootDir, err = DecodeFAT32RootDirectoryCluster(device, fat)
} else {
rootDir, err = DecodeFAT16RootDirectoryCluster(device, bs)
if err != nil {
Expand Down