-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
4,523 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/satori/go.uuid" | ||
version = "1.2.0" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "golang.org/x/sys" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package iso9660 | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const ( | ||
ISO9660File = "./testdata/file.iso" | ||
ISO9660Size = 11018240 | ||
) | ||
|
||
func GetTestFile(t *testing.T) (*File, string) { | ||
// we use the entry for FILENA01.;1 , which should have the content "filename_01" (without the quotes) | ||
// see ./testdata/README.md | ||
// | ||
// entry: | ||
// {recordSize:0x7a, extAttrSize:0x0, location:0x1422, size:0xb, creation:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}, isHidden:false, isSubdirectory:false, isAssociated:false, hasExtendedAttrs:false, hasOwnerGroupPermissions:false, hasMoreEntries:false, volumeSequence:0x0, filename:"FILENA01.;1"}, | ||
// FileSystem implements the FileSystem interface | ||
file, err := os.Open(ISO9660File) | ||
if err != nil { | ||
t.Errorf("Could not read ISO9660 test file %s: %v", ISO9660File, err) | ||
} | ||
fs := &FileSystem{ | ||
workspace: "", | ||
size: ISO9660Size, | ||
start: 0, | ||
file: file, | ||
blocksize: 2048, | ||
} | ||
de := &directoryEntry{ | ||
extAttrSize: 0, | ||
location: 0x1422, | ||
size: 0xb, | ||
creation: time.Now(), | ||
filesystem: fs, | ||
filename: "FILENA01.;1", | ||
} | ||
return &File{ | ||
directoryEntry: de, | ||
isReadWrite: false, | ||
isAppend: false, | ||
offset: 0, | ||
}, "filename_1\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package iso9660 | ||
|
||
// Directory represents a single directory in a FAT32 filesystem | ||
type Directory struct { | ||
directoryEntry | ||
entries []*directoryEntry | ||
} | ||
|
||
// dirEntriesFromBytes loads the directory entries from the raw bytes | ||
func (d *Directory) entriesFromBytes(b []byte, f *FileSystem) error { | ||
entries, err := parseDirEntries(b, f) | ||
if err != nil { | ||
return err | ||
} | ||
d.entries = entries | ||
return nil | ||
} | ||
|
||
// entriesToBytes convert our entries to raw bytes | ||
func (d *Directory) entriesToBytes() ([]byte, error) { | ||
b := make([]byte, 0) | ||
blocksize := int(d.filesystem.blocksize) | ||
for _, de := range d.entries { | ||
b2, err := de.toBytes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
// a directory entry cannot cross a block boundary | ||
// so if adding this puts us past it, then pad it | ||
// but only if we are not already exactly at the boundary | ||
newlength := len(b) + len(b2) | ||
left := blocksize - len(b)%blocksize | ||
if left != 0 && newlength/blocksize > len(b)/blocksize { | ||
b = append(b, make([]byte, left)...) | ||
} | ||
b = append(b, b2...) | ||
} | ||
// in the end, must pad to exact blocks | ||
left := blocksize - len(b)%blocksize | ||
if left > 0 { | ||
b = append(b, make([]byte, left)...) | ||
} | ||
return b, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package iso9660 | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// TestDirectoryEntriesFromBytes largely a duplicate of TestdirectoryEntryParseDirEntries | ||
// it just loads it into the Directory structure | ||
func TestDirectoryEntriesFromBytes(t *testing.T) { | ||
fs := &FileSystem{blocksize: 2048} | ||
validDe, _, _, b, err := getValidDirectoryEntries(fs) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
d := &Directory{} | ||
err = d.entriesFromBytes(b, fs) | ||
switch { | ||
case err != nil: | ||
t.Errorf("Unexpected non-nil error: %v", err) | ||
case d.entries == nil: | ||
t.Errorf("unexpected nil entries") | ||
case len(d.entries) != len(validDe): | ||
t.Errorf("mismatched entries length actual %d vs expected %d", len(d.entries), len(validDe)) | ||
default: | ||
// run through them and see that they match | ||
for i, de := range d.entries { | ||
if !compareDirectoryEntriesIgnoreDates(de, validDe[i]) { | ||
t.Errorf("%d: directoryEntry mismatch, actual then valid:", i) | ||
t.Logf("%#v\n", de) | ||
t.Logf("%#v\n", validDe[i]) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
func TestDirectoryEntriesToBytes(t *testing.T) { | ||
blocksize := 2048 | ||
validDe, _, _, b, err := getValidDirectoryEntries(nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
d := &Directory{ | ||
entries: validDe, | ||
directoryEntry: directoryEntry{ | ||
filesystem: &FileSystem{ | ||
blocksize: int64(blocksize), | ||
}, | ||
}, | ||
} | ||
output, err := d.entriesToBytes() | ||
// null the date bytes out | ||
if err != nil { | ||
t.Fatalf("unexpected non-nil error: %v", err) | ||
} | ||
// cannot directly compare the bytes as of yet, since the original contains all sorts of system area stuff | ||
output = clearDatesDirectoryBytes(output, blocksize) | ||
output = clearSuspDirectoryBytes(output, blocksize) | ||
b = clearDatesDirectoryBytes(b, blocksize) | ||
b = clearSuspDirectoryBytes(b, blocksize) | ||
switch { | ||
case output == nil: | ||
t.Errorf("unexpected nil bytes") | ||
case len(output) == 0: | ||
t.Errorf("unexpected 0 length byte slice") | ||
case len(output) != len(b): | ||
t.Errorf("mismatched byte slice length actual %d, expected %d", len(output), len(b)) | ||
case len(output)%blocksize != 0: | ||
t.Errorf("output size was %d which is not a perfect multiple of %d", len(output), blocksize) | ||
} | ||
} | ||
|
||
func clearDatesDirectoryBytes(b []byte, blocksize int) []byte { | ||
if b == nil { | ||
return b | ||
} | ||
nullBytes := make([]byte, 7, 7) | ||
for i := 0; i < len(b); { | ||
// get the length of the current record | ||
dirlen := int(b[i]) | ||
if dirlen == 0 { | ||
i += blocksize - blocksize%i | ||
continue | ||
} | ||
copy(b[i+18:i+18+7], nullBytes) | ||
i += dirlen | ||
} | ||
return b | ||
} | ||
func clearSuspDirectoryBytes(b []byte, blocksize int) []byte { | ||
if b == nil { | ||
return b | ||
} | ||
for i := 0; i < len(b); { | ||
// get the length of the current record | ||
dirlen := int(b[i+0]) | ||
namelen := int(b[i+32]) | ||
if dirlen == 0 { | ||
i += blocksize - blocksize%i | ||
continue | ||
} | ||
if namelen%2 == 0 { | ||
namelen++ | ||
} | ||
nullByteStart := 33 + namelen | ||
nullByteLen := dirlen - nullByteStart | ||
nullBytes := make([]byte, nullByteLen, nullByteLen) | ||
copy(b[i+nullByteStart:i+nullByteStart+nullByteLen], nullBytes) | ||
i += dirlen | ||
} | ||
return b | ||
} |
Oops, something went wrong.