fix dos write

This commit is contained in:
April Ayres-Griffiths 2019-01-06 09:19:01 +11:00
parent a6d47bbafa
commit 16c8a2100d
3 changed files with 26 additions and 30 deletions

17
data.go
View File

@ -1,21 +1,16 @@
package main package main
import ( import (
"crypto/md5"
"encoding/gob"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"runtime"
"time"
"crypto/md5"
"encoding/hex"
"os" "os"
"strings"
"encoding/gob"
"path/filepath" "path/filepath"
"runtime"
"strings"
"time"
"github.com/paleotronic/diskm8/disk" "github.com/paleotronic/diskm8/disk"
"github.com/paleotronic/diskm8/loggy" "github.com/paleotronic/diskm8/loggy"

View File

@ -917,20 +917,19 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
data = append(header, data...) data = append(header, data...)
} }
// 1st: check we have sufficient space... // try get catalog entry - delete existing if match found
tsBlocks, dataBlocks, err := dsk.AppleDOSGetFreeSectors(len(data))
if err != nil {
return err
}
fd, err := dsk.AppleDOSNamedCatalogEntry(name) fd, err := dsk.AppleDOSNamedCatalogEntry(name)
//fmt.Println("FD=", fd)
if err == nil { if err == nil {
if kind != fd.Type() { if kind != fd.Type() {
return errors.New("File type mismatch") return errors.New("File type mismatch")
} else { } else {
// need to delete this file... // need to delete this file...
err = dsk.AppleDOSDeleteFile(name) err = dsk.AppleDOSRemoveFile(fd)
if err != nil {
return err
}
// reread vtoc here
vtoc, err = dsk.AppleDOSGetVTOC()
if err != nil { if err != nil {
return err return err
} }
@ -942,6 +941,12 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
} }
} }
// 1st: check we have sufficient space...
tsBlocks, dataBlocks, err := dsk.AppleDOSGetFreeSectors(len(data))
if err != nil {
return err
}
// 2nd: check we can get a free catalog entry // 2nd: check we can get a free catalog entry
sectorCount := len(dataBlocks) sectorCount := len(dataBlocks)
@ -1058,6 +1063,8 @@ func (d *DSKWrapper) AppleDOSRemoveFile(fd *FileDescriptor) error {
vtoc.SetTSFree(pair[0], pair[1], true) vtoc.SetTSFree(pair[0], pair[1], true)
} }
vtoc.Publish(d)
fd.Data[0x00] = 0xff fd.Data[0x00] = 0xff
fd.SetName("") fd.SetName("")
return fd.Publish(d) return fd.Publish(d)

16
main.go
View File

@ -13,25 +13,19 @@ through as time goes by.
*/ */
import ( import (
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path" "path"
"path/filepath" "path/filepath"
"runtime"
"runtime/debug" "runtime/debug"
"strings"
"flag" "time"
"os"
"github.com/paleotronic/diskm8/disk" "github.com/paleotronic/diskm8/disk"
"github.com/paleotronic/diskm8/loggy" "github.com/paleotronic/diskm8/loggy"
"runtime"
"strings"
"time"
"github.com/paleotronic/diskm8/panic" "github.com/paleotronic/diskm8/panic"
) )