fusefrontend: better comments for Truncate
This commit is contained in:
parent
e994ffa27d
commit
ae77d18527
@ -396,7 +396,6 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
|||||||
|
|
||||||
// File grows
|
// File grows
|
||||||
if newSize > oldSize {
|
if newSize > oldSize {
|
||||||
|
|
||||||
// File was empty, create new header
|
// File was empty, create new header
|
||||||
if oldSize == 0 {
|
if oldSize == 0 {
|
||||||
err = f.createHeader()
|
err = f.createHeader()
|
||||||
@ -404,10 +403,10 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
|||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// New blocks to add
|
||||||
blocks := f.contentEnc.ExplodePlainRange(oldSize, newSize-oldSize)
|
addBlocks := f.contentEnc.ExplodePlainRange(oldSize, newSize-oldSize)
|
||||||
for _, b := range blocks {
|
for _, b := range addBlocks {
|
||||||
// First and last block may be partial
|
// First and last block may be partial and must be actually written
|
||||||
if b.IsPartial() {
|
if b.IsPartial() {
|
||||||
off, _ := b.PlaintextRange()
|
off, _ := b.PlaintextRange()
|
||||||
off += b.Skip
|
off += b.Skip
|
||||||
@ -416,6 +415,11 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Complete all-zero blocks can stay all-zero because we do file
|
||||||
|
// hole passthrough.
|
||||||
|
// TODO We are growing the file block-by-block which is pretty
|
||||||
|
// inefficient. We could coalesce all the grows into a single
|
||||||
|
// Ftruncate.
|
||||||
off, length := b.CiphertextRange()
|
off, length := b.CiphertextRange()
|
||||||
err = syscall.Ftruncate(int(f.fd.Fd()), int64(off+length))
|
err = syscall.Ftruncate(int(f.fd.Fd()), int64(off+length))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -440,7 +444,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Truncate down to last complete block
|
// Truncate down to the last complete block
|
||||||
err = syscall.Ftruncate(int(f.fd.Fd()), int64(cipherOff))
|
err = syscall.Ftruncate(int(f.fd.Fd()), int64(cipherOff))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tlog.Warn.Printf("shrink Ftruncate returned error: %v", err)
|
tlog.Warn.Printf("shrink Ftruncate returned error: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user