Skip to content

Commit

Permalink
Revert FileSystemBase interface and add fuse3 methods to new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
James Fantin committed Dec 3, 2024
1 parent 0e76d5a commit 6e7a97a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/hellofs/hellofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (self *Hellofs) Read(path string, buff []byte, ofst int64, fh uint64) (n in

func (self *Hellofs) Readdir(path string,
fill func(name string, stat *fuse.Stat_t, ofst int64) bool,
ofst int64, fh uint64, flags uint32) (errc int) {
ofst int64, fh uint64) (errc int) {
fill(".", nil, 0)
fill("..", nil, 0)
fill(filename, nil, 0)
Expand Down
10 changes: 5 additions & 5 deletions examples/memfs/memfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (self *Memfs) Readlink(path string) (errc int, target string) {
return 0, string(node.data)
}

func (self *Memfs) Rename(oldpath string, newpath string, flags uint32) (errc int) {
func (self *Memfs) Rename(oldpath string, newpath string) (errc int) {
defer trace(oldpath, newpath)(&errc)
defer self.synchronize()()
oldprnt, oldname, oldnode := self.lookupNode(oldpath, nil)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (self *Memfs) Rename(oldpath string, newpath string, flags uint32) (errc in
return 0
}

func (self *Memfs) Chmod(path string, mode uint32, fh uint64) (errc int) {
func (self *Memfs) Chmod(path string, mode uint32) (errc int) {
defer trace(path, mode)(&errc)
defer self.synchronize()()
_, _, node := self.lookupNode(path, nil)
Expand All @@ -206,7 +206,7 @@ func (self *Memfs) Chmod(path string, mode uint32, fh uint64) (errc int) {
return 0
}

func (self *Memfs) Chown(path string, uid uint32, gid uint32, fh uint64) (errc int) {
func (self *Memfs) Chown(path string, uid uint32, gid uint32) (errc int) {
defer trace(path, uid, gid)(&errc)
defer self.synchronize()()
_, _, node := self.lookupNode(path, nil)
Expand All @@ -223,7 +223,7 @@ func (self *Memfs) Chown(path string, uid uint32, gid uint32, fh uint64) (errc i
return 0
}

func (self *Memfs) Utimens(path string, tmsp []fuse.Timespec, fh uint64) (errc int) {
func (self *Memfs) Utimens(path string, tmsp []fuse.Timespec) (errc int) {
defer trace(path, tmsp)(&errc)
defer self.synchronize()()
_, _, node := self.lookupNode(path, nil)
Expand Down Expand Up @@ -326,7 +326,7 @@ func (self *Memfs) Opendir(path string) (errc int, fh uint64) {
func (self *Memfs) Readdir(path string,
fill func(name string, stat *fuse.Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) (errc int) {
fh uint64) (errc int) {
defer trace(path, fill, ofst, fh)(&errc)
defer self.synchronize()()
node := self.openmap[fh]
Expand Down
2 changes: 1 addition & 1 deletion examples/notifyfs/notifyfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (self *Notifyfs) Read(path string, buff []byte, ofst int64, fh uint64) (n i
func (self *Notifyfs) Readdir(path string,
fill func(name string, stat *fuse.Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) (errc int) {
fh uint64) (errc int) {
fill(".", nil, 0)
fill("..", nil, 0)
count := self.count()
Expand Down
10 changes: 5 additions & 5 deletions examples/passthrough/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,27 @@ func (self *Ptfs) Readlink(path string) (errc int, target string) {
return 0, string(buff[:n])
}

func (self *Ptfs) Rename(oldpath string, newpath string, flags uint32) (errc int) {
func (self *Ptfs) Rename(oldpath string, newpath string) (errc int) {
defer trace(oldpath, newpath)(&errc)
defer setuidgid()()
oldpath = filepath.Join(self.root, oldpath)
newpath = filepath.Join(self.root, newpath)
return errno(syscall.Rename(oldpath, newpath))
}

func (self *Ptfs) Chmod(path string, mode uint32, fh uint64) (errc int) {
func (self *Ptfs) Chmod(path string, mode uint32) (errc int) {
defer trace(path, mode)(&errc)
path = filepath.Join(self.root, path)
return errno(syscall.Chmod(path, mode))
}

func (self *Ptfs) Chown(path string, uid uint32, gid uint32, fh uint64) (errc int) {
func (self *Ptfs) Chown(path string, uid uint32, gid uint32) (errc int) {
defer trace(path, uid, gid)(&errc)
path = filepath.Join(self.root, path)
return errno(syscall.Lchown(path, int(uid), int(gid)))
}

func (self *Ptfs) Utimens(path string, tmsp1 []fuse.Timespec, fh uint64) (errc int) {
func (self *Ptfs) Utimens(path string, tmsp1 []fuse.Timespec) (errc int) {
defer trace(path, tmsp1)(&errc)
path = filepath.Join(self.root, path)
tmsp := [2]syscall.Timespec{}
Expand Down Expand Up @@ -230,7 +230,7 @@ func (self *Ptfs) Opendir(path string) (errc int, fh uint64) {
func (self *Ptfs) Readdir(path string,
fill func(name string, stat *fuse.Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) (errc int) {
fh uint64) (errc int) {
defer trace(path, fill, ofst, fh)(&errc)
path = filepath.Join(self.root, path)
file, e := os.Open(path)
Expand Down
39 changes: 29 additions & 10 deletions fuse/fsop.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ type FileSystemInterface interface {
Readlink(path string) (int, string)

// Rename renames a file.
Rename(oldpath string, newpath string, flags uint32) int
Rename(oldpath string, newpath string) int

// Chmod changes the permission bits of a file.
Chmod(path string, mode uint32, fh uint64) int
Chmod(path string, mode uint32) int

// Chown changes the owner and group of a file.
Chown(path string, uid uint32, gid uint32, fh uint64) int
Chown(path string, uid uint32, gid uint32) int

// Utimens changes the access and modification times of a file.
Utimens(path string, tmsp []Timespec, fh uint64) int
Utimens(path string, tmsp []Timespec) int

// Access checks file access permissions.
Access(path string, mask uint32) int
Expand Down Expand Up @@ -292,7 +292,7 @@ type FileSystemInterface interface {
Readdir(path string,
fill func(name string, stat *Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) int
fh uint64) int

// Releasedir closes an open directory.
Releasedir(path string, fh uint64) int
Expand All @@ -313,6 +313,25 @@ type FileSystemInterface interface {
Listxattr(path string, fill func(name string) bool) int
}

// FileSystemFuse3 is the interface that wraps the fuse3 equivalent methods.
//
// ChmodFuse3, ChownFuse3, and UtimensFuse3 each similar to Chmod, Chown, and
// Utimens except they include a file handle that could be null and only work
// on with Fuse3.
//
// RenameFuse3 and ReaddirFuse3 are similar to Rename and Readir except that they
// include additional flags.
type FileSystemFuse3 interface {
ChmodFuse3(path string, mode uint32, fh uint64) int
ChownFuse3(path string, uid uint32, gid uint32, fh uint64) int
UtimensFuse3(path string, tmsp []Timespec, fh uint64) int
RenameFuse3(oldpath string, newpath string, flags uint32) int
ReaddirFuse3(path string,
fill func(name string, stat *Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) int
}

// FileSystemOpenEx is the interface that wraps the OpenEx and CreateEx methods.
//
// OpenEx and CreateEx are similar to Open and Create except that they allow
Expand Down Expand Up @@ -454,25 +473,25 @@ func (*FileSystemBase) Readlink(path string) (int, string) {

// Rename renames a file.
// The FileSystemBase implementation returns -ENOSYS.
func (*FileSystemBase) Rename(oldpath string, newpath string, flags uint32) int {
func (*FileSystemBase) Rename(oldpath string, newpath string) int {
return -ENOSYS
}

// Chmod changes the permission bits of a file.
// The FileSystemBase implementation returns -ENOSYS.
func (*FileSystemBase) Chmod(path string, mode uint32, fh uint64) int {
func (*FileSystemBase) Chmod(path string, mode uint32) int {
return -ENOSYS
}

// Chown changes the owner and group of a file.
// The FileSystemBase implementation returns -ENOSYS.
func (*FileSystemBase) Chown(path string, uid uint32, gid uint32, fh uint64) int {
func (*FileSystemBase) Chown(path string, uid uint32, gid uint32) int {
return -ENOSYS
}

// Utimens changes the access and modification times of a file.
// The FileSystemBase implementation returns -ENOSYS.
func (*FileSystemBase) Utimens(path string, tmsp []Timespec, fh uint64) int {
func (*FileSystemBase) Utimens(path string, tmsp []Timespec) int {
return -ENOSYS
}

Expand Down Expand Up @@ -557,7 +576,7 @@ func (*FileSystemBase) Opendir(path string) (int, uint64) {
func (*FileSystemBase) Readdir(path string,
fill func(name string, stat *Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) int {
fh uint64) int {
return -ENOSYS
}

Expand Down
94 changes: 66 additions & 28 deletions fuse/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ func hostRename(oldpath0 *c_char, newpath0 *c_char, flags c_uint32_t) (errc0 c_i
defer recoverAsErrno(&errc0)
fsop := hostHandleGet(c_fuse_get_context().private_data).fsop
oldpath, newpath := c_GoString(oldpath0), c_GoString(newpath0)
errc := fsop.Rename(oldpath, newpath, uint32(flags))
return c_int(errc)
intf, ok := fsop.(FileSystemFuse3)
if ok {
errc := intf.RenameFuse3(oldpath, newpath, uint32(flags))
return c_int(errc)
} else {
errc := fsop.Rename(oldpath, newpath)
return c_int(errc)
}
}

func hostLink(oldpath0 *c_char, newpath0 *c_char) (errc0 c_int) {
Expand All @@ -201,24 +207,36 @@ func hostChmod(path0 *c_char, mode0 c_fuse_mode_t, fi0 *c_struct_fuse_file_info)
defer recoverAsErrno(&errc0)
fsop := hostHandleGet(c_fuse_get_context().private_data).fsop
path := c_GoString(path0)
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
intf, ok := fsop.(FileSystemFuse3)
if ok {
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
}
errc := intf.ChmodFuse3(path, uint32(mode0), fifh)
return c_int(errc)
} else {
errc := fsop.Chmod(path, uint32(mode0))
return c_int(errc)
}
errc := fsop.Chmod(path, uint32(mode0), fifh)
return c_int(errc)
}

func hostChown(path0 *c_char, uid0 c_fuse_uid_t, gid0 c_fuse_gid_t, fi0 *c_struct_fuse_file_info) (errc0 c_int) {
defer recoverAsErrno(&errc0)
fsop := hostHandleGet(c_fuse_get_context().private_data).fsop
path := c_GoString(path0)
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
intf, ok := fsop.(FileSystemFuse3)
if ok {
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
}
errc := intf.ChownFuse3(path, uint32(uid0), uint32(gid0), fifh)
return c_int(errc)
} else {
errc := fsop.Chown(path, uint32(uid0), uint32(gid0))
return c_int(errc)
}
errc := fsop.Chown(path, uint32(uid0), uint32(gid0), fifh)
return c_int(errc)
}

func hostTruncate(path0 *c_char, size0 c_fuse_off_t, fi0 *c_struct_fuse_file_info) (errc0 c_int) {
Expand Down Expand Up @@ -397,7 +415,6 @@ func hostReaddir(path0 *c_char, buff0 unsafe.Pointer, fill0 c_fuse_fill_dir_t, o
defer recoverAsErrno(&errc0)
fsop := hostHandleGet(c_fuse_get_context().private_data).fsop
path := c_GoString(path0)
flag := uint32(flags)
fill := func(name1 string, stat1 *Stat_t, off1 int64) bool {
name := c_CString(name1)
defer c_free(unsafe.Pointer(name))
Expand All @@ -410,8 +427,14 @@ func hostReaddir(path0 *c_char, buff0 unsafe.Pointer, fill0 c_fuse_fill_dir_t, o
return 0 == c_hostFilldir(fill0, buff0, name, stat, c_fuse_off_t(off1))
}
}
errc := fsop.Readdir(path, fill, int64(ofst0), uint64(fi0.fh), flag)
return c_int(errc)
intf, ok := fsop.(FileSystemFuse3)
if ok {
errc := intf.ReaddirFuse3(path, fill, int64(ofst0), uint64(fi0.fh), uint32(flags))
return c_int(errc)
} else {
errc := fsop.Readdir(path, fill, int64(ofst0), uint64(fi0.fh))
return c_int(errc)
}
}

func hostReleasedir(path0 *c_char, fi0 *c_struct_fuse_file_info) (errc0 c_int) {
Expand Down Expand Up @@ -534,20 +557,35 @@ func hostUtimens(path0 *c_char, tmsp0 *c_fuse_timespec_t, fi0 *c_struct_fuse_fil
defer recoverAsErrno(&errc0)
fsop := hostHandleGet(c_fuse_get_context().private_data).fsop
path := c_GoString(path0)
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
}
if tmsp0 == nil {
errc := fsop.Utimens(path, nil, fifh)
return c_int(errc)
intf, ok := fsop.(FileSystemFuse3)
if ok {
fifh := ^uint64(0)
if nil != fi0 {
fifh = uint64(fi0.fh)
}
if tmsp0 == nil {
errc := intf.UtimensFuse3(path, nil, fifh)
return c_int(errc)
} else {
tmsp := [2]Timespec{}
tmsa := (*[2]c_fuse_timespec_t)(unsafe.Pointer(tmsp0))
copyFusetimespecFromCtimespec(&tmsp[0], &tmsa[0])
copyFusetimespecFromCtimespec(&tmsp[1], &tmsa[1])
errc := intf.UtimensFuse3(path, tmsp[:], fifh)
return c_int(errc)
}
} else {
tmsp := [2]Timespec{}
tmsa := (*[2]c_fuse_timespec_t)(unsafe.Pointer(tmsp0))
copyFusetimespecFromCtimespec(&tmsp[0], &tmsa[0])
copyFusetimespecFromCtimespec(&tmsp[1], &tmsa[1])
errc := fsop.Utimens(path, tmsp[:], fifh)
return c_int(errc)
if tmsp0 == nil {
errc := fsop.Utimens(path, nil)
return c_int(errc)
} else {
tmsp := [2]Timespec{}
tmsa := (*[2]c_fuse_timespec_t)(unsafe.Pointer(tmsp0))
copyFusetimespecFromCtimespec(&tmsp[0], &tmsa[0])
copyFusetimespecFromCtimespec(&tmsp[1], &tmsa[1])
errc := fsop.Utimens(path, tmsp[:])
return c_int(errc)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion fuse/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (self *testfs) Getattr(path string, stat *Stat_t, fh uint64) (errc int) {
func (self *testfs) Readdir(path string,
fill func(name string, stat *Stat_t, ofst int64) bool,
ofst int64,
fh uint64, flags uint32) (errc int) {
fh uint64) (errc int) {
fill(".", nil, 0)
fill("..", nil, 0)
return 0
Expand Down

0 comments on commit 6e7a97a

Please sign in to comment.