summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/file.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-03-21 09:31:05 +0100
committerJakob Unterwurzacher2021-03-21 09:31:05 +0100
commit3b9a1b628b11a9deb03a8fe7e6022e75b16ded49 (patch)
treecaac22d00043bc9ffaf568fdd1f0388df7eb8cf7 /internal/fusefrontend/file.go
parent47a4d33f24509ac9db6b924f84a7102cbe0f98c3 (diff)
fusefronted: move Create() and Open() to new file
And deduplicate the code a little.
Diffstat (limited to 'internal/fusefrontend/file.go')
-rw-r--r--internal/fusefrontend/file.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go
index 98e5802..33a3cbe 100644
--- a/internal/fusefrontend/file.go
+++ b/internal/fusefrontend/file.go
@@ -53,18 +53,31 @@ type File struct {
rootNode *RootNode
}
-// NewFile returns a new go-fuse File instance.
-func NewFile(fd *os.File, rn *RootNode, st *syscall.Stat_t) *File {
+// NewFile returns a new go-fuse File instance based on an already-open file
+// descriptor. NewFile internally calls Fstat() on the fd. The resulting Stat_t
+// is returned because node.Create() needs it.
+//
+// `cName` is only used for error logging and may be left blank.
+func NewFile(fd int, cName string, rn *RootNode) (f *File, st *syscall.Stat_t, errno syscall.Errno) {
+ // Need device number and inode number for openfiletable locking
+ st = &syscall.Stat_t{}
+ if err := syscall.Fstat(fd, st); err != nil {
+ errno = fs.ToErrno(err)
+ return
+ }
qi := inomap.QInoFromStat(st)
e := openfiletable.Register(qi)
- return &File{
- fd: fd,
+ osFile := os.NewFile(uintptr(fd), cName)
+
+ f = &File{
+ fd: osFile,
contentEnc: rn.contentEnc,
qIno: qi,
fileTableEntry: e,
rootNode: rn,
}
+ return f, st, 0
}
// intFd - return the backing file descriptor as an integer.