truncate: Fix bug that caused xfstests generic/030 to fail
The bug was caused by using cipherOff where plainOff should have been used. Renamed the symbols for less confusion.
This commit is contained in:
parent
aa6fa7f3cf
commit
90bd978283
@ -127,22 +127,22 @@ func TestTruncate(t *testing.T) {
|
||||
// Grow to two blocks
|
||||
file.Truncate(7000)
|
||||
if md5fn(fn) != "95d4ec7038e3e4fdbd5f15c34c3f0b34" {
|
||||
t.Fail()
|
||||
t.Errorf("Fail 7000")
|
||||
}
|
||||
// Shrink - needs RMW
|
||||
file.Truncate(6999)
|
||||
if md5fn(fn) != "35fd15873ec6c35380064a41b9b9683b" {
|
||||
t.Fail()
|
||||
t.Errorf("Fail 6999")
|
||||
}
|
||||
// Shrink to one partial block
|
||||
file.Truncate(465)
|
||||
if md5fn(fn) != "a1534d6e98a6b21386456a8f66c55260" {
|
||||
t.Fail()
|
||||
t.Errorf("Fail 465")
|
||||
}
|
||||
// Grow to exactly one block
|
||||
file.Truncate(4096)
|
||||
if md5fn(fn) != "620f0b67a91f7f74151bc5be745b7110" {
|
||||
t.Fail()
|
||||
t.Errorf("Fail 4096")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,29 +270,30 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
||||
}
|
||||
}
|
||||
return fuse.OK
|
||||
// File shrinks
|
||||
} else {
|
||||
// File shrinks
|
||||
blockNo := f.cfs.BlockNoPlainOff(newSize)
|
||||
lastBlockOff := blockNo * f.cfs.CipherBS()
|
||||
lastBlockLen := newSize - blockNo * f.cfs.PlainBS()
|
||||
cipherOff := blockNo * f.cfs.CipherBS()
|
||||
plainOff := blockNo * f.cfs.PlainBS()
|
||||
lastBlockLen := newSize - plainOff
|
||||
var data []byte
|
||||
if lastBlockLen > 0 {
|
||||
var status fuse.Status
|
||||
data, status = f.doRead(lastBlockOff, lastBlockLen)
|
||||
data, status = f.doRead(plainOff, lastBlockLen)
|
||||
if status != fuse.OK {
|
||||
cryptfs.Warn.Printf("shrink doRead returned error: %v", err)
|
||||
return status
|
||||
}
|
||||
}
|
||||
f.lock.Lock()
|
||||
err = syscall.Ftruncate(int(f.fd.Fd()), int64(lastBlockOff))
|
||||
err = syscall.Ftruncate(int(f.fd.Fd()), int64(cipherOff))
|
||||
f.lock.Unlock()
|
||||
if err != nil {
|
||||
cryptfs.Warn.Printf("shrink Ftruncate returned error: %v", err)
|
||||
return fuse.ToStatus(err)
|
||||
}
|
||||
if lastBlockLen > 0 {
|
||||
_, status := f.doWrite(data, int64(lastBlockOff))
|
||||
_, status := f.doWrite(data, int64(plainOff))
|
||||
return status
|
||||
}
|
||||
return fuse.OK
|
||||
|
Loading…
x
Reference in New Issue
Block a user