diff options
author | Jakob Unterwurzacher | 2018-07-01 19:10:57 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-07-01 20:56:22 +0200 |
commit | a2af1fb5da90ec12d05e1c3ece9c44507a5b44c8 (patch) | |
tree | 6d3dab34ea12ca3e716b40a204ce1336ca31b6f8 /internal/fusefrontend/file.go | |
parent | 4a736377829f9b72a538d9f1e75ccc4defddc69a (diff) |
fusefrontend: export "File" type
"gocryptfs -fsck" will need access to helper functions,
and to get that, it will need to cast a gofuse.File to a
fusefrontend.File. Make fusefrontend.File exported to make
this work.
Diffstat (limited to 'internal/fusefrontend/file.go')
-rw-r--r-- | internal/fusefrontend/file.go | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 2041154..bcf4b83 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -23,10 +23,10 @@ import ( "github.com/rfjakob/gocryptfs/internal/tlog" ) -var _ nodefs.File = &file{} // Verify that interface is implemented. +var _ nodefs.File = &File{} // Verify that interface is implemented. // File - based on loopbackFile in go-fuse/fuse/nodefs/files.go -type file struct { +type File struct { fd *os.File // Has Release() already been called on this file? This also means that the // wlock entry has been freed, so let's not crash trying to access it. @@ -60,7 +60,7 @@ type file struct { } // NewFile returns a new go-fuse File instance. -func NewFile(fd *os.File, fs *FS) (nodefs.File, fuse.Status) { +func NewFile(fd *os.File, fs *FS) (*File, fuse.Status) { var st syscall.Stat_t err := syscall.Fstat(int(fd.Fd()), &st) if err != nil { @@ -70,7 +70,7 @@ func NewFile(fd *os.File, fs *FS) (nodefs.File, fuse.Status) { qi := openfiletable.QInoFromStat(&st) e := openfiletable.Register(qi) - return &file{ + return &File{ fd: fd, contentEnc: fs.contentEnc, qIno: qi, @@ -83,13 +83,13 @@ func NewFile(fd *os.File, fs *FS) (nodefs.File, fuse.Status) { // intFd - return the backing file descriptor as an integer. Used for debug // messages. -func (f *file) intFd() int { +func (f *File) intFd() int { return int(f.fd.Fd()) } // readFileID loads the file header from disk and extracts the file ID. // Returns io.EOF if the file is empty. -func (f *file) readFileID() ([]byte, error) { +func (f *File) readFileID() ([]byte, error) { // We read +1 byte to determine if the file has actual content // and not only the header. A header-only file will be considered empty. // This makes File ID poisoning more difficult. @@ -115,7 +115,7 @@ func (f *file) readFileID() ([]byte, error) { // createHeader creates a new random header and writes it to disk. // Returns the new file ID. // The caller must hold fileIDLock.Lock(). -func (f *file) createHeader() (fileID []byte, err error) { +func (f *File) createHeader() (fileID []byte, err error) { h := contentenc.RandomHeader() buf := h.Pack() // Prevent partially written (=corrupt) header by preallocating the space beforehand @@ -143,7 +143,7 @@ func (f *file) createHeader() (fileID []byte, err error) { // // Called by Read() for normal reading, // by Write() and Truncate() for Read-Modify-Write -func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Status) { +func (f *File) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Status) { // Make sure we have the file ID. f.fileTableEntry.HeaderLock.RLock() if f.fileTableEntry.ID == nil { @@ -230,7 +230,7 @@ func (f *file) doRead(dst []byte, off uint64, length uint64) ([]byte, fuse.Statu } // Read - FUSE call -func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fuse.Status) { +func (f *File) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fuse.Status) { if len(buf) > fuse.MAX_KERNEL_WRITE { // This would crash us due to our fixed-size buffer pool tlog.Warn.Printf("Read: rejecting oversized request with EMSGSIZE, len=%d", len(buf)) @@ -263,7 +263,7 @@ func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fus // and by Truncate() to rewrite the last file block. // // Empty writes do nothing and are allowed. -func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { +func (f *File) doWrite(data []byte, off int64) (uint32, fuse.Status) { // Read header from disk, create a new one if the file is empty f.fileTableEntry.HeaderLock.RLock() if f.fileTableEntry.ID == nil { @@ -337,7 +337,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { // This is an optimisation for streaming writes on NFS where a // Stat() call is very expensive. // The caller must "wlock.lock(f.devIno.ino)" otherwise this check would be racy. -func (f *file) isConsecutiveWrite(off int64) bool { +func (f *File) isConsecutiveWrite(off int64) bool { opCount := openfiletable.WriteOpCount() return opCount == f.lastOpCount+1 && off == f.lastWrittenOffset+1 } @@ -345,7 +345,7 @@ func (f *file) isConsecutiveWrite(off int64) bool { // Write - FUSE call // // If the write creates a hole, pads the file to the next block boundary. -func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { +func (f *File) Write(data []byte, off int64) (uint32, fuse.Status) { if len(data) > fuse.MAX_KERNEL_WRITE { // This would crash us due to our fixed-size buffer pool tlog.Warn.Printf("Write: rejecting oversized request with EMSGSIZE, len=%d", len(data)) @@ -381,7 +381,7 @@ func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { } // Release - FUSE call, close file -func (f *file) Release() { +func (f *File) Release() { f.fdLock.Lock() if f.released { log.Panicf("ino%d fh%d: double release", f.qIno.Ino, f.intFd()) @@ -394,7 +394,7 @@ func (f *file) Release() { } // Flush - FUSE call -func (f *file) Flush() fuse.Status { +func (f *File) Flush() fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() @@ -410,14 +410,14 @@ func (f *file) Flush() fuse.Status { return fuse.ToStatus(err) } -func (f *file) Fsync(flags int) (code fuse.Status) { +func (f *File) Fsync(flags int) (code fuse.Status) { f.fdLock.RLock() defer f.fdLock.RUnlock() return fuse.ToStatus(syscall.Fsync(int(f.fd.Fd()))) } -func (f *file) Chmod(mode uint32) fuse.Status { +func (f *File) Chmod(mode uint32) fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() @@ -427,14 +427,14 @@ func (f *file) Chmod(mode uint32) fuse.Status { return fuse.ToStatus(err) } -func (f *file) Chown(uid uint32, gid uint32) fuse.Status { +func (f *File) Chown(uid uint32, gid uint32) fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() return fuse.ToStatus(f.fd.Chown(int(uid), int(gid))) } -func (f *file) GetAttr(a *fuse.Attr) fuse.Status { +func (f *File) GetAttr(a *fuse.Attr) fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() @@ -453,7 +453,7 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status { return fuse.OK } -func (f *file) Utimens(a *time.Time, m *time.Time) fuse.Status { +func (f *File) Utimens(a *time.Time, m *time.Time) fuse.Status { f.fdLock.RLock() defer f.fdLock.RUnlock() return f.loopbackFile.Utimens(a, m) |