Skip to content

Commit 2d2b921

Browse files
committed
fix bug in create_chain
1 parent dd3bfd5 commit 2d2b921

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

Diff for: fat.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -1981,8 +1981,7 @@ func (obj *objid) create_chain(clst uint32) uint32 {
19811981
if cs < 2 {
19821982
fsys.logerror("create_chain:insanity")
19831983
return 1
1984-
}
1985-
if cs == maxu32 || cs < fsys.n_fatent {
1984+
} else if cs == maxu32 || cs < fsys.n_fatent {
19861985
// Disk error or it is already followed by next cluster.
19871986
return cs
19881987
}
@@ -2018,21 +2017,19 @@ func (obj *objid) create_chain(clst uint32) uint32 {
20182017
for {
20192018
ncl++
20202019
if ncl >= fsys.n_fatent {
2021-
{
2022-
ncl = 2
2023-
if ncl > scl {
2024-
return 0 // No free cluster.
2025-
}
2026-
}
2027-
cs = obj.clusterstat(ncl)
2028-
if cs == 0 {
2029-
break
2030-
} else if cs == 1 || cs == maxu32 {
2031-
return cs // Return error as is.
2032-
} else if ncl == scl {
2020+
ncl = 2
2021+
if ncl > scl {
20332022
return 0 // No free cluster.
20342023
}
20352024
}
2025+
cs = obj.clusterstat(ncl)
2026+
if cs == 0 {
2027+
break
2028+
} else if cs == 1 || cs == maxu32 {
2029+
return cs // Return error as is.
2030+
} else if ncl == scl {
2031+
return 0 // No free cluster.
2032+
}
20362033
}
20372034
}
20382035
// Make new cluster EOC.

Diff for: fat_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ func ExampleRead() {
2424
return
2525
}
2626
var fp File
27-
27+
// var root dir
28+
// fr = fs.f_opendir(&root, "rootdir")
29+
// if fr != frOK {
30+
// log.Error("open dir failed:" + fr.Error())
31+
// return
32+
// }
33+
// fmt.Println("ok")
34+
// return
2835
fr = fs.f_open(&fp, filename, faRead|faWrite|faCreateNew)
2936
if fr != frOK {
3037
log.Error("open for write failed:" + fr.Error())
@@ -70,6 +77,7 @@ func ExampleRead() {
7077
return
7178
}
7279
fmt.Println("wrote and read back file OK!")
80+
// Output: aa
7381
}
7482

7583
func DefaultFATByteBlocks(numBlocks int) *BytesBlocks {

0 commit comments

Comments
 (0)