fusefrontend: Allow to create sparse file of size 4096.
When the old size is zero, there are no existing blocks to merge the new data with. Directly use Ftruncate if the size is block-aligned. Fixes https://github.com/rfjakob/gocryptfs/issues/305
This commit is contained in:
parent
ab169443fd
commit
acf7e52022
@ -181,11 +181,9 @@ func (f *File) truncateGrowFile(oldPlainSz uint64, newPlainSz uint64) fuse.Statu
|
||||
if newPlainSz <= oldPlainSz {
|
||||
log.Panicf("BUG: newSize=%d <= oldSize=%d", newPlainSz, oldPlainSz)
|
||||
}
|
||||
var n1 uint64
|
||||
if oldPlainSz > 0 {
|
||||
n1 = f.contentEnc.PlainOffToBlockNo(oldPlainSz - 1)
|
||||
}
|
||||
newEOFOffset := newPlainSz - 1
|
||||
if oldPlainSz > 0 {
|
||||
n1 := f.contentEnc.PlainOffToBlockNo(oldPlainSz - 1)
|
||||
n2 := f.contentEnc.PlainOffToBlockNo(newEOFOffset)
|
||||
// The file is grown within one block, no need to pad anything.
|
||||
// Write a single zero to the last byte and let doWrite figure out the RMW.
|
||||
@ -194,6 +192,7 @@ func (f *File) truncateGrowFile(oldPlainSz uint64, newPlainSz uint64) fuse.Statu
|
||||
_, status := f.doWrite(buf, int64(newEOFOffset))
|
||||
return status
|
||||
}
|
||||
}
|
||||
// The truncate creates at least one new block.
|
||||
//
|
||||
// Make sure the old last block is padded to the block boundary. This call
|
||||
|
Loading…
Reference in New Issue
Block a user