aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend
diff options
context:
space:
mode:
Diffstat (limited to 'pathfs_frontend')
-rw-r--r--pathfs_frontend/file.go22
-rw-r--r--pathfs_frontend/fs.go17
2 files changed, 19 insertions, 20 deletions
diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go
index cc8de17..43114b2 100644
--- a/pathfs_frontend/file.go
+++ b/pathfs_frontend/file.go
@@ -1,9 +1,9 @@
package pathfs_frontend
import (
- "io"
"bytes"
"fmt"
+ "io"
"os"
"sync"
"syscall"
@@ -40,10 +40,10 @@ func NewFile(fd *os.File, writeOnly bool, cfs *cryptfs.CryptFS) nodefs.File {
syscall.Fstat(int(fd.Fd()), &st)
return &file{
- fd: fd,
+ fd: fd,
writeOnly: writeOnly,
- cfs: cfs,
- ino: st.Ino,
+ cfs: cfs,
+ ino: st.Ino,
}
}
@@ -101,7 +101,7 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
lenHave := len(plaintext)
lenWant := skip + int(length)
if lenHave > lenWant {
- out = plaintext[skip:skip + int(length)]
+ out = plaintext[skip : skip+int(length)]
} else if lenHave > skip {
out = plaintext[skip:lenHave]
} else {
@@ -139,7 +139,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
status := fuse.OK
dataBuf := bytes.NewBuffer(data)
blocks := f.cfs.SplitRange(uint64(off), uint64(len(data)))
- for _, b := range(blocks) {
+ for _, b := range blocks {
blockData := dataBuf.Next(int(b.Length))
@@ -180,7 +180,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
// Write - FUSE call
func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) {
- cryptfs.Debug.Printf("ino%d: FUSE Write %s: offset=%d length=%d\n", f.ino, off, len(data))
+ cryptfs.Debug.Printf("ino%d: FUSE Write: offset=%d length=%d\n", f.ino, off, len(data))
fi, err := f.fd.Stat()
if err != nil {
@@ -248,8 +248,8 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
// File grows
if newSize > oldSize {
- blocks := f.cfs.SplitRange(oldSize, newSize - oldSize)
- for _, b := range(blocks) {
+ blocks := f.cfs.SplitRange(oldSize, newSize-oldSize)
+ for _, b := range blocks {
// First and last block may be partial
if b.IsPartial() {
off, _ := b.PlaintextRange()
@@ -261,7 +261,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
} else {
off, length := b.CiphertextRange()
f.lock.Lock()
- err := syscall.Ftruncate(int(f.fd.Fd()), int64(off + length))
+ err := syscall.Ftruncate(int(f.fd.Fd()), int64(off+length))
f.lock.Unlock()
if err != nil {
cryptfs.Warn.Printf("grow Ftruncate returned error: %v", err)
@@ -270,7 +270,7 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
}
}
return fuse.OK
- // File shrinks
+ // File shrinks
} else {
blockNo := f.cfs.BlockNoPlainOff(newSize)
lastBlockOff := blockNo * f.cfs.PlainBS()
diff --git a/pathfs_frontend/fs.go b/pathfs_frontend/fs.go
index 247b69e..ba46309 100644
--- a/pathfs_frontend/fs.go
+++ b/pathfs_frontend/fs.go
@@ -1,10 +1,10 @@
package pathfs_frontend
import (
+ "fmt"
"os"
"path/filepath"
"time"
- "fmt"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
@@ -14,17 +14,16 @@ import (
type FS struct {
*cryptfs.CryptFS
- pathfs.FileSystem // loopbackFileSystem
- backing string // Backing directory
+ pathfs.FileSystem // loopbackFileSystem
+ backing string // Backing directory
}
// Encrypted FUSE overlay filesystem
func NewFS(key []byte, backing string, useOpenssl bool) *FS {
return &FS{
- CryptFS: cryptfs.NewCryptFS(key, useOpenssl),
- FileSystem: pathfs.NewLoopbackFileSystem(backing),
- backing: backing,
-
+ CryptFS: cryptfs.NewCryptFS(key, useOpenssl),
+ FileSystem: pathfs.NewLoopbackFileSystem(backing),
+ backing: backing,
}
}
@@ -52,7 +51,7 @@ func (fs *FS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Stat
func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
cryptfs.Debug.Printf("OpenDir(%s)\n", dirName)
- cipherEntries, status := fs.FileSystem.OpenDir(fs.EncryptPath(dirName), context);
+ cipherEntries, status := fs.FileSystem.OpenDir(fs.EncryptPath(dirName), context)
var plain []fuse.DirEntry
if cipherEntries != nil {
for i := range cipherEntries {
@@ -76,7 +75,7 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
// We always need read access to do read-modify-write cycles
func (fs *FS) mangleOpenFlags(flags uint32) (newFlags int, writeOnly bool) {
newFlags = int(flags)
- if newFlags & os.O_WRONLY > 0 {
+ if newFlags&os.O_WRONLY > 0 {
writeOnly = true
newFlags = newFlags ^ os.O_WRONLY | os.O_RDWR
}