56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package zfs
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"bazil.org/fuse"
|
|
"bazil.org/fuse/fs"
|
|
"github.com/debridmediamanager.com/zurg/internal/config"
|
|
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
|
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func Mount(mountpoint string, c config.ConfigInterface, t *torrent.TorrentManager) error {
|
|
rlog := logutil.NewLogger()
|
|
log := rlog.Named("zfs")
|
|
|
|
options := []fuse.MountOption{
|
|
fuse.AllowOther(),
|
|
fuse.AllowNonEmptyMount(),
|
|
fuse.MaxReadahead(uint32(128 << 10)),
|
|
fuse.DefaultPermissions(),
|
|
fuse.FSName("zurgfs"),
|
|
}
|
|
conn, err := fuse.Mount(mountpoint, options...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer conn.Close()
|
|
|
|
srv := fs.New(conn, nil)
|
|
|
|
filesys := &FS{
|
|
uid: uint32(unix.Geteuid()),
|
|
gid: uint32(unix.Getegid()),
|
|
umask: os.FileMode(0),
|
|
c: c,
|
|
t: t,
|
|
log: log,
|
|
initTime: time.Now(),
|
|
}
|
|
|
|
if err := srv.Serve(filesys); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Unmount(mountpoint string) error {
|
|
fuse.Unmount(mountpoint)
|
|
return nil
|
|
}
|