2015-10-04 11:39:35 +02:00
|
|
|
package pathfs_frontend
|
|
|
|
|
2015-12-19 13:21:15 +01:00
|
|
|
// Helper functions for sparse files (files with holes)
|
|
|
|
|
2015-10-04 11:39:35 +02:00
|
|
|
import (
|
|
|
|
"github.com/hanwen/go-fuse/fuse"
|
2015-10-04 15:43:46 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/cryptfs"
|
2015-10-04 11:39:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Will a write to offset "off" create a file hole?
|
2015-10-04 14:21:07 +02:00
|
|
|
func (f *file) createsHole(plainSize uint64, off int64) bool {
|
2015-11-01 12:11:36 +01:00
|
|
|
nextBlock := f.cfs.PlainOffToBlockNo(plainSize)
|
|
|
|
targetBlock := f.cfs.PlainOffToBlockNo(uint64(off))
|
2015-10-04 11:39:35 +02:00
|
|
|
if targetBlock > nextBlock {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:21:07 +02:00
|
|
|
// Zero-pad the file of size plainSize to the next block boundary
|
|
|
|
func (f *file) zeroPad(plainSize uint64) fuse.Status {
|
2015-10-04 11:39:35 +02:00
|
|
|
lastBlockLen := plainSize % f.cfs.PlainBS()
|
|
|
|
missing := f.cfs.PlainBS() - lastBlockLen
|
|
|
|
pad := make([]byte, missing)
|
2015-10-04 15:43:46 +02:00
|
|
|
cryptfs.Debug.Printf("zeroPad: Writing %d bytes\n", missing)
|
2015-10-04 11:39:35 +02:00
|
|
|
_, status := f.doWrite(pad, int64(plainSize))
|
|
|
|
return status
|
|
|
|
}
|