diff options
author | Sebastian Lackner | 2019-01-03 22:00:36 +0100 |
---|---|---|
committer | rfjakob | 2019-01-04 01:38:47 +0100 |
commit | acf7e52022fcf67a9db58bda59efc2e932e8892d (patch) | |
tree | 7d3c56be7978a2b2c82f43f265fee5554b712681 /internal/fusefrontend | |
parent | ab169443fde9c6697b5b9dc010691cbc61cd5206 (diff) |
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
Diffstat (limited to 'internal/fusefrontend')
-rw-r--r-- | internal/fusefrontend/file_allocate_truncate.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/internal/fusefrontend/file_allocate_truncate.go b/internal/fusefrontend/file_allocate_truncate.go index e735d79..b64e19b 100644 --- a/internal/fusefrontend/file_allocate_truncate.go +++ b/internal/fusefrontend/file_allocate_truncate.go @@ -181,18 +181,17 @@ 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 - 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. - if n1 == n2 { - buf := make([]byte, 1) - _, status := f.doWrite(buf, int64(newEOFOffset)) - return status + 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. + if n1 == n2 { + buf := make([]byte, 1) + _, status := f.doWrite(buf, int64(newEOFOffset)) + return status + } } // The truncate creates at least one new block. // |