Skip to content

Commit

Permalink
fix bug in create_chain
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Jan 24, 2024
1 parent dd3bfd5 commit 2d2b921
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
25 changes: 11 additions & 14 deletions fat.go
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,7 @@ func (obj *objid) create_chain(clst uint32) uint32 {
if cs < 2 {
fsys.logerror("create_chain:insanity")
return 1
}
if cs == maxu32 || cs < fsys.n_fatent {
} else if cs == maxu32 || cs < fsys.n_fatent {
// Disk error or it is already followed by next cluster.
return cs
}
Expand Down Expand Up @@ -2018,21 +2017,19 @@ func (obj *objid) create_chain(clst uint32) uint32 {
for {
ncl++
if ncl >= fsys.n_fatent {
{
ncl = 2
if ncl > scl {
return 0 // No free cluster.
}
}
cs = obj.clusterstat(ncl)
if cs == 0 {
break
} else if cs == 1 || cs == maxu32 {
return cs // Return error as is.
} else if ncl == scl {
ncl = 2
if ncl > scl {
return 0 // No free cluster.
}
}
cs = obj.clusterstat(ncl)
if cs == 0 {
break
} else if cs == 1 || cs == maxu32 {
return cs // Return error as is.
} else if ncl == scl {
return 0 // No free cluster.
}
}
}
// Make new cluster EOC.
Expand Down
10 changes: 9 additions & 1 deletion fat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ func ExampleRead() {
return
}
var fp File

// var root dir
// fr = fs.f_opendir(&root, "rootdir")
// if fr != frOK {
// log.Error("open dir failed:" + fr.Error())
// return
// }
// fmt.Println("ok")
// return
fr = fs.f_open(&fp, filename, faRead|faWrite|faCreateNew)
if fr != frOK {
log.Error("open for write failed:" + fr.Error())
Expand Down Expand Up @@ -70,6 +77,7 @@ func ExampleRead() {
return
}
fmt.Println("wrote and read back file OK!")
// Output: aa
}

func DefaultFATByteBlocks(numBlocks int) *BytesBlocks {
Expand Down

0 comments on commit 2d2b921

Please sign in to comment.