reverse: rename readFile to clearer readBackingFile
Also refactor the header generation for nicer code.
This commit is contained in:
parent
be9dfe3a89
commit
7faa267bd4
@ -44,11 +44,11 @@ func (rf *reverseFile) GetAttr(*fuse.Attr) fuse.Status {
|
|||||||
return fuse.ENOSYS
|
return fuse.ENOSYS
|
||||||
}
|
}
|
||||||
|
|
||||||
// readFile - read from the backing plaintext file, encrypt it, return the
|
// readBackingFile: read from the backing plaintext file, encrypt it, return the
|
||||||
// ciphertext.
|
// ciphertext.
|
||||||
// "off" ... ciphertext offset (must be >= HEADER_LEN)
|
// "off" ... ciphertext offset (must be >= HEADER_LEN)
|
||||||
// "length" ... ciphertext length
|
// "length" ... ciphertext length
|
||||||
func (rf *reverseFile) readFile(off uint64, length uint64) (out []byte, err error) {
|
func (rf *reverseFile) readBackingFile(off uint64, length uint64) (out []byte, err error) {
|
||||||
blocks := rf.contentEnc.ExplodeCipherRange(off, length)
|
blocks := rf.contentEnc.ExplodeCipherRange(off, length)
|
||||||
|
|
||||||
// Read the backing plaintext in one go
|
// Read the backing plaintext in one go
|
||||||
@ -84,24 +84,27 @@ func (rf *reverseFile) Read(buf []byte, ioff int64) (resultData fuse.ReadResult,
|
|||||||
length := uint64(len(buf))
|
length := uint64(len(buf))
|
||||||
off := uint64(ioff)
|
off := uint64(ioff)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var headerPart []byte
|
var header []byte
|
||||||
|
|
||||||
// Create a virtual file header
|
// Synthesize file header
|
||||||
if off < contentenc.HEADER_LEN {
|
if off < contentenc.HEADER_LEN {
|
||||||
headerPart = zeroFileHeader.Pack()
|
header = zeroFileHeader.Pack()
|
||||||
headerPart = headerPart[off:]
|
// Truncate to requested part
|
||||||
if off+length < contentenc.HEADER_LEN {
|
end := int(off) + len(buf)
|
||||||
headerPart = headerPart[:length]
|
if end > len(header) {
|
||||||
|
end = len(header)
|
||||||
}
|
}
|
||||||
}
|
header = header[off:end]
|
||||||
out.Write(headerPart)
|
// Write into output buffer and adjust offsets
|
||||||
hLen := uint64(len(headerPart))
|
out.Write(header)
|
||||||
|
hLen := uint64(len(header))
|
||||||
off += hLen
|
off += hLen
|
||||||
length -= hLen
|
length -= hLen
|
||||||
|
}
|
||||||
|
|
||||||
// Read actual file data
|
// Read actual file data
|
||||||
if length > 0 {
|
if length > 0 {
|
||||||
fileData, err := rf.readFile(off, length)
|
fileData, err := rf.readBackingFile(off, length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fuse.ToStatus(err)
|
return nil, fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user