mirror of
https://github.com/paleotronic/diskm8.git
synced 2024-09-07 21:54:28 +00:00
fix (appledos): detect unused FD entries, and assign correct total sectors
This commit is contained in:
parent
a00aeed763
commit
f649cebd0e
@ -100,7 +100,7 @@ func (fd *FileDescriptor) Publish(dsk *DSKWrapper) error {
|
||||
}
|
||||
|
||||
func (fd *FileDescriptor) IsUnused() bool {
|
||||
return fd.Data[0] == 0xff || fd.Type().String() == "Unknown" || fd.TotalSectors() == 0
|
||||
return fd.Data[0] == 0xff || fd.Data[0] == 0x00 || fd.Type().String() == "Unknown" || fd.TotalSectors() == 0
|
||||
}
|
||||
|
||||
func (fd *FileDescriptor) GetTrackSectorListStart() (int, int) {
|
||||
@ -817,6 +817,7 @@ func (d *DSKWrapper) AppleDOSNextFreeCatalogEntry(name string) (*FileDescriptor,
|
||||
data := d.Read()
|
||||
|
||||
for e == nil && count < 105 {
|
||||
fmt.Printf("AppleDOSNextFreeCatalogEntry: checking entry %d\n", count)
|
||||
slot := count % 7
|
||||
pos := 0x0b + 35*slot
|
||||
|
||||
@ -824,8 +825,10 @@ func (d *DSKWrapper) AppleDOSNextFreeCatalogEntry(name string) (*FileDescriptor,
|
||||
fd.SetData(data[pos:pos+35], ct, cs, pos)
|
||||
|
||||
if fd.IsUnused() {
|
||||
fmt.Printf("Is unused\n")
|
||||
return &fd, nil
|
||||
} else if name != "" && strings.ToLower(fd.NameUnadorned()) == strings.ToLower(name) {
|
||||
fmt.Printf("Name match found\n")
|
||||
return &fd, nil
|
||||
}
|
||||
count++
|
||||
@ -909,14 +912,14 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
|
||||
fmt.Printf("Writing file with type %s\n", kind.Ext())
|
||||
|
||||
if kind == FileTypeBIN {
|
||||
if kind & FileTypeBIN != 0 {
|
||||
l := len(data)
|
||||
fmt.Printf("Length is %d\n", l)
|
||||
header := []byte{byte(l % 256), byte(l / 256)}
|
||||
data = append(header, data...)
|
||||
}
|
||||
|
||||
if kind != FileTypeTXT {
|
||||
if kind & FileTypeTXT == 0 {
|
||||
header := []byte{byte(loadAddr % 256), byte(loadAddr / 256)}
|
||||
data = append(header, data...)
|
||||
}
|
||||
@ -952,8 +955,8 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
}
|
||||
|
||||
// 2nd: check we can get a free catalog entry
|
||||
sectorCount := len(dataBlocks)
|
||||
|
||||
sectorCount := len(dataBlocks) + len(tsBlocks)
|
||||
|
||||
// 3rd: Write the datablocks
|
||||
var block int = 0
|
||||
for len(data) > 0 {
|
||||
@ -1034,6 +1037,8 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
fd.SetTotalSectors(sectorCount)
|
||||
fd.Publish(dsk)
|
||||
|
||||
fmt.Printf("Added file %s (kind %d)\n", name, kind)
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
5
go.mod
5
go.mod
@ -4,4 +4,7 @@ go 1.22.3
|
||||
|
||||
require github.com/chzyer/readline v1.5.1
|
||||
|
||||
require golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
require (
|
||||
github.com/gorilla/mux v1.8.1 // indirect
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -4,5 +4,7 @@ github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI
|
||||
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
|
||||
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
|
||||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
8
main.go
8
main.go
@ -95,6 +95,10 @@ var fileDelete = flag.String("file-delete", "", "File to delete (-with-disk)")
|
||||
var fileMkdir = flag.String("dir-create", "", "Directory to create (-with-disk)")
|
||||
var fileCatalog = flag.Bool("catalog", false, "List disk contents (-with-disk)")
|
||||
var quarantine = flag.Bool("quarantine", false, "Run -as-dupes and -whole-disk in quarantine mode")
|
||||
var serve = flag.String("serve", "", "host:port to run diskm8 server on")
|
||||
var tlsCert = flag.String("tls-cert", "", "TLS certificate to use for -serve")
|
||||
var tlsKey = flag.String("tls-key", "", "TLS key to use for -serve")
|
||||
var acceptOrigin = flag.String("accept-origin", "*", "Control origin -serve allows accepting from")
|
||||
|
||||
func main() {
|
||||
|
||||
@ -106,6 +110,10 @@ func main() {
|
||||
banner()
|
||||
}
|
||||
|
||||
if *serve != "" {
|
||||
StartService(*serve, *tlsCert, *tlsKey)
|
||||
}
|
||||
|
||||
var filterpath []string
|
||||
|
||||
if *filterPath || *shell {
|
||||
|
2
shell.go
2
shell.go
@ -864,7 +864,7 @@ func shellCat(args []string) int {
|
||||
if f.Locked {
|
||||
locked = "Y"
|
||||
}
|
||||
fmt.Printf("%-33s %6d %2s %-23s %s\n", f.Filename, (f.Size/bs)+1, locked, f.Type, add)
|
||||
fmt.Printf("%-33s %6d %2s %-23s %.2x %s\n", f.Filename, (f.Size/bs)+1, locked, f.Type, f.Type, add)
|
||||
}
|
||||
|
||||
free := 0
|
||||
|
Loading…
Reference in New Issue
Block a user