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
import (
"crypto/md5"
"encoding/gob"
"encoding/hex"
"errors"
"fmt"
"runtime"
"time"
"crypto/md5"
"encoding/hex"
"os"
"strings"
"encoding/gob"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/paleotronic/diskm8/disk"
"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...)
}
// 1st: check we have sufficient space...
tsBlocks, dataBlocks, err := dsk.AppleDOSGetFreeSectors(len(data))
if err != nil {
return err
}
// try get catalog entry - delete existing if match found
fd, err := dsk.AppleDOSNamedCatalogEntry(name)
//fmt.Println("FD=", fd)
if err == nil {
if kind != fd.Type() {
return errors.New("File type mismatch")
} else {
// 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 {
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
sectorCount := len(dataBlocks)
@ -1058,6 +1063,8 @@ func (d *DSKWrapper) AppleDOSRemoveFile(fd *FileDescriptor) error {
vtoc.SetTSFree(pair[0], pair[1], true)
}
vtoc.Publish(d)
fd.Data[0x00] = 0xff
fd.SetName("")
return fd.Publish(d)

16
main.go
View File

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