aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-01-20 20:55:56 +0100
committerJakob Unterwurzacher2016-01-20 20:57:00 +0100
commit17f0eb13396ad31083e786ed64aef368646c2aa6 (patch)
treeaf6ca1565ce456d41290ca956e4209d29413509c /pathfs_frontend
parentb9dd9e9a1cfabd4ecf7f4d3996b0a2c24cee75b4 (diff)
Convert logging to standard Go log.Logger
This is in preparation of logging to syslog.
Diffstat (limited to 'pathfs_frontend')
-rw-r--r--pathfs_frontend/file.go42
-rw-r--r--pathfs_frontend/fs.go28
-rw-r--r--pathfs_frontend/fs_dir.go28
3 files changed, 49 insertions, 49 deletions
diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go
index 911546d..4639157 100644
--- a/pathfs_frontend/file.go
+++ b/pathfs_frontend/file.go
@@ -144,20 +144,20 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
blocks := f.cfs.ExplodePlainRange(off, length)
alignedOffset, alignedLength := blocks[0].JointCiphertextRange(blocks)
skip := blocks[0].Skip
- cryptfs.Debug.Printf("JointCiphertextRange(%d, %d) -> %d, %d, %d\n", off, length, alignedOffset, alignedLength, skip)
+ cryptfs.Debug.Printf("JointCiphertextRange(%d, %d) -> %d, %d, %d", off, length, alignedOffset, alignedLength, skip)
ciphertext := make([]byte, int(alignedLength))
f.fdLock.Lock()
n, err := f.fd.ReadAt(ciphertext, int64(alignedOffset))
f.fdLock.Unlock()
if err != nil && err != io.EOF {
- cryptfs.Warn.Printf("read: ReadAt: %s\n", err.Error())
+ cryptfs.Warn.Printf("read: ReadAt: %s", err.Error())
return nil, fuse.ToStatus(err)
}
// Truncate ciphertext buffer down to actually read bytes
ciphertext = ciphertext[0:n]
firstBlockNo := blocks[0].BlockNo
- cryptfs.Debug.Printf("ReadAt offset=%d bytes (%d blocks), want=%d, got=%d\n", alignedOffset, firstBlockNo, alignedLength, n)
+ cryptfs.Debug.Printf("ReadAt offset=%d bytes (%d blocks), want=%d, got=%d", alignedOffset, firstBlockNo, alignedLength, n)
// Decrypt it
plaintext, err := f.cfs.DecryptBlocks(ciphertext, firstBlockNo, f.header.Id)
@@ -165,7 +165,7 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
curruptBlockNo := firstBlockNo + f.cfs.PlainOffToBlockNo(uint64(len(plaintext)))
cipherOff := f.cfs.BlockNoToCipherOff(curruptBlockNo)
plainOff := f.cfs.BlockNoToPlainOff(curruptBlockNo)
- cryptfs.Warn.Printf("ino%d: doRead: corrupt block #%d (plainOff=%d, cipherOff=%d)\n",
+ cryptfs.Warn.Printf("ino%d: doRead: corrupt block #%d (plainOff=%d, cipherOff=%d)",
f.ino, curruptBlockNo, plainOff, cipherOff)
return nil, fuse.EIO
}
@@ -187,23 +187,23 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
// Read - FUSE call
func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fuse.Status) {
- cryptfs.Debug.Printf("ino%d: FUSE Read: offset=%d length=%d\n", f.ino, len(buf), off)
+ cryptfs.Debug.Printf("ino%d: FUSE Read: offset=%d length=%d", f.ino, len(buf), off)
if f.writeOnly {
- cryptfs.Warn.Printf("ino%d: Tried to read from write-only file\n", f.ino)
+ cryptfs.Warn.Printf("ino%d: Tried to read from write-only file", f.ino)
return nil, fuse.EBADF
}
out, status := f.doRead(uint64(off), uint64(len(buf)))
if status == fuse.EIO {
- cryptfs.Warn.Printf("ino%d: Read failed with EIO, offset=%d, length=%d\n", f.ino, len(buf), off)
+ cryptfs.Warn.Printf("ino%d: Read failed with EIO, offset=%d, length=%d", f.ino, len(buf), off)
}
if status != fuse.OK {
return nil, status
}
- cryptfs.Debug.Printf("ino%d: Read: status %v, returning %d bytes\n", f.ino, status, len(out))
+ cryptfs.Debug.Printf("ino%d: Read: status %v, returning %d bytes", f.ino, status, len(out))
return fuse.ReadResultData(out), status
}
@@ -244,25 +244,25 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
o, _ := b.PlaintextRange()
oldData, status := f.doRead(o, f.cfs.PlainBS())
if status != fuse.OK {
- cryptfs.Warn.Printf("RMW read failed: %s\n", status.String())
+ cryptfs.Warn.Printf("RMW read failed: %s", status.String())
return written, status
}
// Modify
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", len(oldData), len(blockData))
}
blockOffset, blockLen := b.CiphertextRange()
blockData = f.cfs.EncryptBlock(blockData, b.BlockNo, f.header.Id)
- cryptfs.Debug.Printf("ino%d: Writing %d bytes to block #%d, md5=%s\n",
- f.ino, uint64(len(blockData))-f.cfs.BlockOverhead(), b.BlockNo, cryptfs.Debug.Md5sum(blockData))
+ cryptfs.Debug.Printf("ino%d: Writing %d bytes to block #%d",
+ f.ino, uint64(len(blockData))-f.cfs.BlockOverhead(), b.BlockNo)
// Prevent partially written (=corrupt) blocks by preallocating the space beforehand
f.fdLock.Lock()
err := prealloc(int(f.fd.Fd()), int64(blockOffset), int64(blockLen))
f.fdLock.Unlock()
if err != nil {
- cryptfs.Warn.Printf("doWrite: fallocateRetry failed: %s\n", err.Error())
+ cryptfs.Warn.Printf("doWrite: fallocateRetry failed: %s", err.Error())
status = fuse.ToStatus(err)
break
}
@@ -272,7 +272,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
_, err = f.fd.WriteAt(blockData, int64(blockOffset))
f.fdLock.Unlock()
if err != nil {
- cryptfs.Warn.Printf("doWrite: Write failed: %s\n", err.Error())
+ cryptfs.Warn.Printf("doWrite: Write failed: %s", err.Error())
status = fuse.ToStatus(err)
break
}
@@ -283,18 +283,18 @@ 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: offset=%d length=%d\n", f.ino, off, len(data))
+ cryptfs.Debug.Printf("ino%d: FUSE Write: offset=%d length=%d", f.ino, off, len(data))
fi, err := f.fd.Stat()
if err != nil {
- cryptfs.Warn.Printf("Write: Fstat failed: %v\n", err)
+ cryptfs.Warn.Printf("Write: Fstat failed: %v", err)
return 0, fuse.ToStatus(err)
}
plainSize := f.cfs.CipherSizeToPlainSize(uint64(fi.Size()))
if f.createsHole(plainSize, off) {
status := f.zeroPad(plainSize)
if status != fuse.OK {
- cryptfs.Warn.Printf("zeroPad returned error %v\n", status)
+ cryptfs.Warn.Printf("zeroPad returned error %v", status)
return 0, status
}
}
@@ -352,14 +352,14 @@ func (f *file) Truncate(newSize uint64) fuse.Status {
// the file
fi, err := f.fd.Stat()
if err != nil {
- cryptfs.Warn.Printf("Truncate: Fstat failed: %v\n", err)
+ cryptfs.Warn.Printf("Truncate: Fstat failed: %v", err)
return fuse.ToStatus(err)
}
oldSize := f.cfs.CipherSizeToPlainSize(uint64(fi.Size()))
{
oldB := float32(oldSize) / float32(f.cfs.PlainBS())
newB := float32(newSize) / float32(f.cfs.PlainBS())
- cryptfs.Debug.Printf("ino%d: FUSE Truncate from %.2f to %.2f blocks (%d to %d bytes)\n", f.ino, oldB, newB, oldSize, newSize)
+ cryptfs.Debug.Printf("ino%d: FUSE Truncate from %.2f to %.2f blocks (%d to %d bytes)", f.ino, oldB, newB, oldSize, newSize)
}
// File grows
@@ -444,7 +444,7 @@ func (f *file) Chown(uid uint32, gid uint32) fuse.Status {
}
func (f *file) GetAttr(a *fuse.Attr) fuse.Status {
- cryptfs.Debug.Printf("file.GetAttr()\n")
+ cryptfs.Debug.Printf("file.GetAttr()")
st := syscall.Stat_t{}
f.fdLock.Lock()
err := syscall.Fstat(int(f.fd.Fd()), &st)
@@ -460,7 +460,7 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status {
// Allocate - FUSE call, fallocate(2)
func (f *file) Allocate(off uint64, sz uint64, mode uint32) fuse.Status {
- cryptfs.Warn.Printf("Fallocate is not supported, returning ENOSYS - see https://github.com/rfjakob/gocryptfs/issues/1\n")
+ cryptfs.Warn.Printf("Fallocate is not supported, returning ENOSYS - see https://github.com/rfjakob/gocryptfs/issues/1")
return fuse.ENOSYS
}
diff --git a/pathfs_frontend/fs.go b/pathfs_frontend/fs.go
index 324020d..c7dfc82 100644
--- a/pathfs_frontend/fs.go
+++ b/pathfs_frontend/fs.go
@@ -43,12 +43,12 @@ func (fs *FS) getBackingPath(relPath string) (string, error) {
return "", err
}
cAbsPath := filepath.Join(fs.args.Cipherdir, cPath)
- cryptfs.Debug.Printf("getBackingPath: %s + %s -> %s\n", fs.args.Cipherdir, relPath, cAbsPath)
+ cryptfs.Debug.Printf("getBackingPath: %s + %s -> %s", fs.args.Cipherdir, relPath, cAbsPath)
return cAbsPath, nil
}
func (fs *FS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
- cryptfs.Debug.Printf("FS.GetAttr('%s')\n", name)
+ cryptfs.Debug.Printf("FS.GetAttr('%s')", name)
if fs.isFiltered(name) {
return nil, fuse.EPERM
}
@@ -58,7 +58,7 @@ func (fs *FS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Stat
}
a, status := fs.FileSystem.GetAttr(cName, context)
if a == nil {
- cryptfs.Debug.Printf("FS.GetAttr failed: %s\n", status.String())
+ cryptfs.Debug.Printf("FS.GetAttr failed: %s", status.String())
return a, status
}
if a.IsRegular() {
@@ -71,7 +71,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)
+ cryptfs.Debug.Printf("OpenDir(%s)", dirName)
cDirName, err := fs.encryptPath(dirName)
if err != nil {
return nil, fuse.ToStatus(err)
@@ -107,7 +107,7 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
if !fs.args.PlaintextNames {
name, err = fs.CryptFS.DecryptName(cName, cachedIV, fs.args.EMENames)
if err != nil {
- cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s\n", cName, dirName, err)
+ cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s", cName, dirName, err)
continue
}
}
@@ -137,10 +137,10 @@ func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile n
iflags, writeOnly := fs.mangleOpenFlags(flags)
cPath, err := fs.getBackingPath(path)
if err != nil {
- cryptfs.Debug.Printf("Open: getBackingPath: %v\n", err)
+ cryptfs.Debug.Printf("Open: getBackingPath: %v", err)
return nil, fuse.ToStatus(err)
}
- cryptfs.Debug.Printf("Open: %s\n", cPath)
+ cryptfs.Debug.Printf("Open: %s", cPath)
f, err := os.OpenFile(cPath, iflags, 0666)
if err != nil {
return nil, fuse.ToStatus(err)
@@ -199,7 +199,7 @@ func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context)
}
func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code fuse.Status) {
- cryptfs.Warn.Printf("Truncate of a closed file is not supported, returning ENOSYS\n")
+ cryptfs.Warn.Printf("Truncate of a closed file is not supported, returning ENOSYS")
return fuse.ENOSYS
}
@@ -235,12 +235,12 @@ func (fs *FS) Readlink(path string, context *fuse.Context) (out string, status f
// Since gocryptfs v0.5 symlinks are encrypted like file contents (GCM)
cBinTarget, err := base64.URLEncoding.DecodeString(cTarget)
if err != nil {
- cryptfs.Warn.Printf("Readlink: %v\n", err)
+ cryptfs.Warn.Printf("Readlink: %v", err)
return "", fuse.EIO
}
target, err := fs.CryptFS.DecryptBlock([]byte(cBinTarget), 0, nil)
if err != nil {
- cryptfs.Warn.Printf("Readlink: %v\n", err)
+ cryptfs.Warn.Printf("Readlink: %v", err)
return "", fuse.EIO
}
return string(target), fuse.OK
@@ -258,7 +258,7 @@ func (fs *FS) Unlink(path string, context *fuse.Context) (code fuse.Status) {
}
func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (code fuse.Status) {
- cryptfs.Debug.Printf("Symlink(\"%s\", \"%s\")\n", target, linkName)
+ cryptfs.Debug.Printf("Symlink(\"%s\", \"%s\")", target, linkName)
if fs.isFiltered(linkName) {
return fuse.EPERM
}
@@ -270,7 +270,7 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co
if !fs.args.DirIV {
cTarget, err := fs.encryptPath(target)
if err != nil {
- cryptfs.Warn.Printf("Symlink: BUG: we should not get an error here: %v\n", err)
+ cryptfs.Warn.Printf("Symlink: BUG: we should not get an error here: %v", err)
return fuse.ToStatus(err)
}
err = os.Symlink(cTarget, cPath)
@@ -281,7 +281,7 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co
cTarget := base64.URLEncoding.EncodeToString(cBinTarget)
err = os.Symlink(cTarget, cPath)
- cryptfs.Debug.Printf("Symlink: os.Symlink(%s, %s) = %v\n", cTarget, cPath, err)
+ cryptfs.Debug.Printf("Symlink: os.Symlink(%s, %s) = %v", cTarget, cPath, err)
return fuse.ToStatus(err)
}
@@ -307,7 +307,7 @@ func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (cod
// If an empty directory is overwritten we will always get
// ENOTEMPTY as the "empty" directory will still contain gocryptfs.diriv.
// Handle that case by removing the target directory and trying again.
- cryptfs.Debug.Printf("Rename: Handling ENOTEMPTY\n")
+ cryptfs.Debug.Printf("Rename: Handling ENOTEMPTY")
if fs.Rmdir(newPath, context) == fuse.OK {
err = os.Rename(cOldPath, cNewPath)
}
diff --git a/pathfs_frontend/fs_dir.go b/pathfs_frontend/fs_dir.go
index 0f255d9..9d2d2c9 100644
--- a/pathfs_frontend/fs_dir.go
+++ b/pathfs_frontend/fs_dir.go
@@ -41,10 +41,10 @@ func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fu
err = cryptfs.WriteDirIV(encPath)
if err != nil {
// This should not happen
- cryptfs.Warn.Printf("Mkdir: WriteDirIV failed: %v\n", err)
+ cryptfs.Warn.Printf("Mkdir: WriteDirIV failed: %v", err)
err2 := syscall.Rmdir(encPath)
if err2 != nil {
- cryptfs.Warn.Printf("Mkdir: Rmdir rollback failed: %v\n", err2)
+ cryptfs.Warn.Printf("Mkdir: Rmdir rollback failed: %v", err2)
}
return fuse.ToStatus(err)
}
@@ -53,7 +53,7 @@ func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fu
if origMode != mode {
err = os.Chmod(encPath, os.FileMode(origMode))
if err != nil {
- cryptfs.Warn.Printf("Mkdir: Chmod failed: %v\n", err)
+ cryptfs.Warn.Printf("Mkdir: Chmod failed: %v", err)
}
}
@@ -74,17 +74,17 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
fd, err := os.Open(encPath)
if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.EACCES {
// We need permission to read and modify the directory
- cryptfs.Debug.Printf("Rmdir: handling EACCESS\n")
+ cryptfs.Debug.Printf("Rmdir: handling EACCESS")
fi, err2 := os.Stat(encPath)
if err2 != nil {
- cryptfs.Debug.Printf("Rmdir: Stat: %v\n", err2)
+ cryptfs.Debug.Printf("Rmdir: Stat: %v", err2)
return fuse.ToStatus(err2)
}
origMode := fi.Mode()
newMode := origMode | 0700
err2 = os.Chmod(encPath, newMode)
if err2 != nil {
- cryptfs.Debug.Printf("Rmdir: Chmod failed: %v\n", err2)
+ cryptfs.Debug.Printf("Rmdir: Chmod failed: %v", err2)
return fuse.ToStatus(err)
}
defer func() {
@@ -92,7 +92,7 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
// Undo the chmod if removing the directory failed
err3 := os.Chmod(encPath, origMode)
if err3 != nil {
- cryptfs.Warn.Printf("Rmdir: Chmod rollback failed: %v\n", err2)
+ cryptfs.Warn.Printf("Rmdir: Chmod rollback failed: %v", err2)
}
}
}()
@@ -100,19 +100,19 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
fd, err = os.Open(encPath)
}
if err != nil {
- cryptfs.Debug.Printf("Rmdir: Open: %v\n", err)
+ cryptfs.Debug.Printf("Rmdir: Open: %v", err)
return fuse.ToStatus(err)
}
list, err := fd.Readdirnames(10)
fd.Close()
if err != nil {
- cryptfs.Debug.Printf("Rmdir: Readdirnames: %v\n", err)
+ cryptfs.Debug.Printf("Rmdir: Readdirnames: %v", err)
return fuse.ToStatus(err)
}
if len(list) > 1 {
return fuse.ToStatus(syscall.ENOTEMPTY)
} else if len(list) == 0 {
- cryptfs.Warn.Printf("Rmdir: gocryptfs.diriv missing, allowing deletion\n")
+ cryptfs.Warn.Printf("Rmdir: gocryptfs.diriv missing, allowing deletion")
return fuse.ToStatus(syscall.Rmdir(encPath))
}
@@ -121,14 +121,14 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
parentDir := filepath.Dir(encPath)
tmpName := fmt.Sprintf("gocryptfs.diriv.rmdir.%d", cryptfs.RandUint64())
tmpDirivPath := filepath.Join(parentDir, tmpName)
- cryptfs.Debug.Printf("Rmdir: Renaming %s to %s\n", cryptfs.DIRIV_FILENAME, tmpDirivPath)
+ cryptfs.Debug.Printf("Rmdir: Renaming %s to %s", cryptfs.DIRIV_FILENAME, tmpDirivPath)
// The directory is in an inconsistent state between rename and rmdir. Protect against
// concurrent readers.
fs.dirIVLock.Lock()
defer fs.dirIVLock.Unlock()
err = os.Rename(dirivPath, tmpDirivPath)
if err != nil {
- cryptfs.Warn.Printf("Rmdir: Renaming %s to %s failed: %v\n", cryptfs.DIRIV_FILENAME, tmpDirivPath, err)
+ cryptfs.Warn.Printf("Rmdir: Renaming %s to %s failed: %v", cryptfs.DIRIV_FILENAME, tmpDirivPath, err)
return fuse.ToStatus(err)
}
// Actual Rmdir
@@ -138,14 +138,14 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
// meantime, undo the rename
err2 := os.Rename(tmpDirivPath, dirivPath)
if err2 != nil {
- cryptfs.Warn.Printf("Rmdir: Rename rollback failed: %v\n", err2)
+ cryptfs.Warn.Printf("Rmdir: Rename rollback failed: %v", err2)
}
return fuse.ToStatus(err)
}
// Delete "gocryptfs.diriv.rmdir.INODENUMBER"
err = syscall.Unlink(tmpDirivPath)
if err != nil {
- cryptfs.Warn.Printf("Rmdir: Could not clean up %s: %v\n", tmpName, err)
+ cryptfs.Warn.Printf("Rmdir: Could not clean up %s: %v", tmpName, err)
}
// The now-deleted directory may have been in the DirIV cache. Clear it.
fs.CryptFS.DirIVCacheEnc.Clear()