aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend/file_holes.go
blob: f906aa60e8d345d384b857c9a3ee6ed60a37f6b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package pathfs_frontend

import (
	"github.com/hanwen/go-fuse/fuse"
	"github.com/rfjakob/gocryptfs/cryptfs"
)

// Will a write to offset "off" create a file hole?
func (f *file) createsHole(plainSize uint64, off int64) bool {
	nextBlock := f.cfs.BlockNoPlainOff(plainSize)
	targetBlock := f.cfs.BlockNoPlainOff(uint64(off))
	if targetBlock > nextBlock {
		return true
	}
	return false
}

// Zero-pad the file of size plainSize to the next block boundary
func (f *file) zeroPad(plainSize uint64) fuse.Status {
	lastBlockLen := plainSize % f.cfs.PlainBS()
	missing := f.cfs.PlainBS() - lastBlockLen
	pad := make([]byte, missing)
	cryptfs.Debug.Printf("zeroPad: Writing %d bytes\n", missing)
	_, status := f.doWrite(pad, int64(plainSize))
	return status
}