intraBlock: Rename Offset to Skip
"Offset" is unclear whether it is an offset from the start of file or start of block. "Skip" seems much better.
This commit is contained in:
parent
775676ecb8
commit
c859f0b2dc
@ -116,8 +116,8 @@ func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.Wri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
copy(blockData, readResp.Data)
|
copy(blockData, readResp.Data)
|
||||||
copy(blockData[ib.Offset:ib.Offset+ib.Length], req.Data)
|
copy(blockData[ib.Skip:ib.Skip+ib.Length], req.Data)
|
||||||
blockLen := max(len(readResp.Data), int(ib.Offset+ib.Length))
|
blockLen := max(len(readResp.Data), int(ib.Skip+ib.Length))
|
||||||
blockData = blockData[0:blockLen]
|
blockData = blockData[0:blockLen]
|
||||||
} else {
|
} else {
|
||||||
blockData = req.Data[0:f.crfs.PlainBS()]
|
blockData = req.Data[0:f.crfs.PlainBS()]
|
||||||
|
@ -25,8 +25,8 @@ func TestSplitRange(t *testing.T) {
|
|||||||
for _, r := range(ranges) {
|
for _, r := range(ranges) {
|
||||||
parts := f.SplitRange(r.offset, r.length)
|
parts := f.SplitRange(r.offset, r.length)
|
||||||
for _, p := range(parts) {
|
for _, p := range(parts) {
|
||||||
if p.Length > DEFAULT_PLAINBS || p.Offset >= DEFAULT_PLAINBS {
|
if p.Length > DEFAULT_PLAINBS || p.Skip >= DEFAULT_PLAINBS {
|
||||||
fmt.Printf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Offset)
|
fmt.Printf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,8 @@ func (be *CryptFS) SplitRange(offset uint64, length uint64) []intraBlock {
|
|||||||
|
|
||||||
for length > 0 {
|
for length > 0 {
|
||||||
b.BlockNo = offset / be.plainBS
|
b.BlockNo = offset / be.plainBS
|
||||||
b.Offset = offset % be.plainBS
|
b.Skip = offset % be.plainBS
|
||||||
b.Length = be.minu64(length, be.plainBS - b.Offset)
|
b.Length = be.minu64(length, be.plainBS - b.Skip)
|
||||||
parts = append(parts, b)
|
parts = append(parts, b)
|
||||||
offset += b.Length
|
offset += b.Length
|
||||||
length -= b.Length
|
length -= b.Length
|
||||||
@ -187,7 +187,7 @@ func (be *CryptFS) JoinCiphertextRange(blocks []intraBlock) (uint64, uint64) {
|
|||||||
// Crop plaintext that correspons to complete cipher blocks down to what is
|
// Crop plaintext that correspons to complete cipher blocks down to what is
|
||||||
// requested according to "iblocks"
|
// requested according to "iblocks"
|
||||||
func (be *CryptFS) CropPlaintext(plaintext []byte, blocks []intraBlock) []byte {
|
func (be *CryptFS) CropPlaintext(plaintext []byte, blocks []intraBlock) []byte {
|
||||||
offset := blocks[0].Offset
|
offset := blocks[0].Skip
|
||||||
last := blocks[len(blocks)-1]
|
last := blocks[len(blocks)-1]
|
||||||
length := (last.BlockNo - blocks[0].BlockNo + 1) * be.plainBS
|
length := (last.BlockNo - blocks[0].BlockNo + 1) * be.plainBS
|
||||||
var cropped []byte
|
var cropped []byte
|
||||||
|
@ -3,14 +3,14 @@ package cryptfs
|
|||||||
// intraBlock identifies a part of a file block
|
// intraBlock identifies a part of a file block
|
||||||
type intraBlock struct {
|
type intraBlock struct {
|
||||||
BlockNo uint64 // Block number in file
|
BlockNo uint64 // Block number in file
|
||||||
Offset uint64 // Offset into block plaintext
|
Skip uint64 // Offset into block plaintext
|
||||||
Length uint64 // Length of data from this block
|
Length uint64 // Length of data from this block
|
||||||
fs *CryptFS
|
fs *CryptFS
|
||||||
}
|
}
|
||||||
|
|
||||||
// isPartial - is the block partial? This means we have to do read-modify-write.
|
// isPartial - is the block partial? This means we have to do read-modify-write.
|
||||||
func (ib *intraBlock) IsPartial() bool {
|
func (ib *intraBlock) IsPartial() bool {
|
||||||
if ib.Offset > 0 || ib.Length < ib.fs.plainBS {
|
if ib.Skip > 0 || ib.Length < ib.fs.plainBS {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -31,9 +31,9 @@ func (ib *intraBlock) PlaintextRange() (offset uint64, length uint64) {
|
|||||||
// CropBlock - crop a potentially larger plaintext block down to the relevant part
|
// CropBlock - crop a potentially larger plaintext block down to the relevant part
|
||||||
func (ib *intraBlock) CropBlock(d []byte) []byte{
|
func (ib *intraBlock) CropBlock(d []byte) []byte{
|
||||||
lenHave := len(d)
|
lenHave := len(d)
|
||||||
lenWant := int(ib.Offset+ib.Length)
|
lenWant := int(ib.Skip+ib.Length)
|
||||||
if lenHave < lenWant {
|
if lenHave < lenWant {
|
||||||
return d[ib.Offset:lenHave]
|
return d[ib.Skip:lenHave]
|
||||||
}
|
}
|
||||||
return d[ib.Offset:lenWant]
|
return d[ib.Skip:lenWant]
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
|
|||||||
return written, status
|
return written, status
|
||||||
}
|
}
|
||||||
// Modify
|
// Modify
|
||||||
blockData = f.cfs.MergeBlocks(oldData, blockData, int(b.Offset))
|
blockData = f.cfs.MergeBlocks(oldData, blockData, int(b.Skip))
|
||||||
cryptfs.Debug.Printf("len(oldData)=%d len(blockData)=%d\n", len(oldData), len(blockData))
|
cryptfs.Debug.Printf("len(oldData)=%d len(blockData)=%d\n", len(oldData), len(blockData))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
|
|||||||
// First and last block may be partial
|
// First and last block may be partial
|
||||||
if b.IsPartial() {
|
if b.IsPartial() {
|
||||||
off, _ := b.PlaintextRange()
|
off, _ := b.PlaintextRange()
|
||||||
off += b.Offset
|
off += b.Skip
|
||||||
_, status := f.doWrite(make([]byte, b.Length), int64(off))
|
_, status := f.doWrite(make([]byte, b.Length), int64(off))
|
||||||
if status != fuse.OK {
|
if status != fuse.OK {
|
||||||
return status
|
return status
|
||||||
|
Loading…
Reference in New Issue
Block a user