本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/nodefs.NewFileSystemConnector函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFileSystemConnector函數的具體用法?Golang NewFileSystemConnector怎麽用?Golang NewFileSystemConnector使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFileSystemConnector函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mountServer
func mountServer(token, mountpoint string) (*fuse.Server, error) {
if err := os.MkdirAll(filepath.Dir(mountpoint), 0755); err != nil {
return nil, err
}
client, err := vault.Client(token)
if err != nil {
return nil, err
}
kwfs, root := fs.NewFs(client)
mountOptions := &fuse.MountOptions{
AllowOther: true,
Name: kwfs.String(),
Options: []string{"default_permissions"},
}
// Empty Options struct avoids setting a global uid/gid override.
conn := nodefs.NewFileSystemConnector(root, &nodefs.Options{})
server, err := fuse.NewServer(conn.RawFS(), mountpoint, mountOptions)
if err != nil {
log.Printf("Mount fail: %v\n", err)
return nil, err
}
go server.Serve()
return server, nil
}
示例2: main
// this function was borrowed from https://raw.githubusercontent.com/hanwen/go-fuse/master/example/memfs/main.go
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
flag.Parse()
if flag.NArg() < 3 {
fmt.Println("usage: appendfs <mountpoint> <datafile> <metadatafile>")
os.Exit(2)
}
mountPoint := flag.Arg(0)
fs, err := appendfs.NewAppendFS(flag.Arg(1), flag.Arg(2))
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
}
options := nodefs.NewOptions()
options.Owner = nil
conn := nodefs.NewFileSystemConnector(fs.Root(), options)
server, err := fuse.NewServer(conn.RawFS(), mountPoint, nil)
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
}
server.SetDebug(*debug)
fmt.Println("Mounted!")
server.Serve()
fmt.Println("Closing filesystem")
err = fs.Close()
if err != nil {
fmt.Printf("Unmount fail: %v\n", err)
os.Exit(1)
}
}
示例3: newFuseFS
func newFuseFS(tmpDir string, rpcFS *RpcFs, writableRoot string) (*fuseFS, error) {
tmpDir, err := ioutil.TempDir(tmpDir, "termite-task")
if err != nil {
return nil, err
}
fs := &fuseFS{
writableRoot: strings.TrimLeft(writableRoot, "/"),
workers: map[string]*workerFS{},
rpcFS: rpcFS,
rpcNodeFS: pathfs.NewPathNodeFs(&multiRPCFS{rpcFS},
&pathfs.PathNodeFsOptions{ClientInodes: true}),
tmpDir: tmpDir,
mount: filepath.Join(tmpDir, "mnt"),
}
if err := os.Mkdir(fs.mount, 0755); err != nil {
return nil, err
}
fs.fsConnector = nodefs.NewFileSystemConnector(fs.rpcNodeFS.Root(),
nodeFSOptions())
fuseOpts := fuse.MountOptions{}
if os.Geteuid() == 0 {
fuseOpts.AllowOther = true
}
fs.server, err = fuse.NewServer(fs.fsConnector.RawFS(), fs.mount, &fuseOpts)
if err != nil {
return nil, err
}
go fs.server.Serve()
return fs, nil
}
示例4: main
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <mountpoint>\n", os.Args[0])
os.Exit(1)
}
mountOptions := &fuse.MountOptions{
AllowOther: true,
Name: "boardfs",
Options: []string{"default_permissions"},
}
mountpoint := os.Args[1]
root := boardfs.NewRootNode()
conn := nodefs.NewFileSystemConnector(root, &nodefs.Options{})
server, err := fuse.NewServer(conn.RawFS(), mountpoint, mountOptions)
if err != nil {
log.Fatalf("Mount fail: %v\n", err)
}
// shutdown fuseserver on SIGINT
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, os.Interrupt, os.Kill)
go func() {
sig := <-sigchan
fmt.Print("\nExiting on ", sig, "\n")
server.Unmount()
}()
server.Serve()
signal.Stop(sigchan)
}
示例5: pathfsFrontend
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool, openssl bool) *fuse.Server {
finalFs := pathfs_frontend.NewFS(key, cipherdir, openssl)
pathFsOpts := &pathfs.PathNodeFsOptions{ClientInodes: true}
pathFs := pathfs.NewPathNodeFs(finalFs, pathFsOpts)
fuseOpts := &nodefs.Options{
// These options are to be compatible with libfuse defaults,
// making benchmarking easier.
NegativeTimeout: time.Second,
AttrTimeout: time.Second,
EntryTimeout: time.Second,
}
conn := nodefs.NewFileSystemConnector(pathFs.Root(), fuseOpts)
var mOpts fuse.MountOptions
mOpts.AllowOther = false
// Set values shown in "df -T" and friends
// First column, "Filesystem"
mOpts.Options = append(mOpts.Options, "fsname="+cipherdir)
// Second column, "Type", will be shown as "fuse." + Name
mOpts.Name = "gocryptfs"
srv, err := fuse.NewServer(conn.RawFS(), mountpoint, &mOpts)
if err != nil {
fmt.Printf("Mount failed: %v", err)
os.Exit(ERREXIT_MOUNT)
}
srv.SetDebug(debug)
return srv
}
示例6: Start
// Start takes a path to the directory where the goinfo file system
// should be mounted. If the directory does not exist, it will be
// created. Start will return an error if the directory cannot be
// created or if the file system cannot be mounted at this location
// for any reason.
func Start(mountpoint string) error {
//already mounted there
if _, found := servers[mountpoint]; found {
return nil
}
if _, err := os.Stat(mountpoint); os.IsNotExist(err) {
if err = os.Mkdir(mountpoint, 0755); err != nil {
return err
}
}
nfs := pathfs.NewPathNodeFs(gfs, nil)
conn := nodefs.NewFileSystemConnector(nfs.Root(), nil)
server, err := fuse.NewServer(conn.RawFS(), mountpoint, &fuse.MountOptions{AllowOther: true})
if err != nil {
return errors.New("Failed to mount monitoring fs at " + mountpoint + ": " + err.Error())
}
servers[mountpoint] = server
//start handling the fs calls
go server.Serve()
return nil
}
示例7: mountServer
func (d *driver) mountServer(mountpoint string) (*fuse.Server, error) {
if err := os.MkdirAll(filepath.Dir(mountpoint), 0755); err != nil {
return nil, err
}
conf := api.DefaultConfig()
client, err := api.NewClient(conf)
if err != nil {
return nil, err
}
ownership := keywhizfs.NewOwnership("root", "root")
kwfs, root := NewFs(client, ownership)
mountOptions := &fuse.MountOptions{
AllowOther: true,
Name: kwfs.String(),
Options: []string{"default_permissions"},
}
// Empty Options struct avoids setting a global uid/gid override.
conn := nodefs.NewFileSystemConnector(root, &nodefs.Options{})
server, err := fuse.NewServer(conn.RawFS(), mountpoint, mountOptions)
if err != nil {
log.Printf("Mount fail: %v\n", err)
return nil, err
}
go server.Serve()
return server, nil
}
示例8: mount
func mount() error {
var err error
if fs != nil || server != nil {
// already mounting
return nil
}
// create mountpoint
os.Mkdir(TEST_MOUNTPOINT, 0777)
// config
config := &config.Config{
MountPoint: TEST_MOUNTPOINT,
ContainerName: TEST_CONTAINER_NAME,
CreateContainer: true,
Debug: true,
NoDaemon: true,
}
// swift
swift := openstack.NewSwift(config)
if err = swift.Auth(); err != nil {
return err
}
swift.DeleteContainer()
// mapper
mapper, err := mapper.NewObjectMapper(config)
if err != nil {
return err
}
// initialize filesystem
fs = NewObjectFileSystem(config, mapper)
path := pathfs.NewPathNodeFs(fs, nil)
con := nodefs.NewFileSystemConnector(path.Root(), &nodefs.Options{})
opts := &fuse.MountOptions{
Name: "test-filesystem",
FsName: "test-filesystem",
}
// create server and do mount with dedicated goroutine
server, err = fuse.NewServer(con.RawFS(), TEST_MOUNTPOINT, opts)
if err != nil {
return err
}
go func() {
server.Serve()
}()
server.WaitMount()
return nil
}
示例9: main
func main() {
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] url mountpoint\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 2 {
Usage()
os.Exit(1)
}
serverURL, mountpoint := flag.Args()[0], flag.Args()[1]
logConfig := klog.Config{*debug, mountpoint}
logger = klog.New("kwfs_main", logConfig)
defer logger.Close()
if *certFile == "" {
logger.Debugf("Certificate file not specified, assuming certificate also in %s", *keyFile)
certFile = keyFile
}
lockMemory()
clientTimeout := time.Duration(*timeoutSeconds) * time.Second
freshThreshold := 200 * time.Millisecond
backendDeadline := 500 * time.Millisecond
maxWait := clientTimeout + backendDeadline
timeouts := keywhizfs.Timeouts{freshThreshold, backendDeadline, maxWait}
client := keywhizfs.NewClient(*certFile, *keyFile, *caFile, serverURL, clientTimeout, logConfig, *ping)
ownership := keywhizfs.NewOwnership(*user, *group)
kwfs, root, err := keywhizfs.NewKeywhizFs(&client, ownership, timeouts, logConfig)
if err != nil {
log.Fatalf("KeywhizFs init fail: %v\n", err)
}
mountOptions := &fuse.MountOptions{
AllowOther: true,
Name: kwfs.String(),
Options: []string{"default_permissions"},
}
// Empty Options struct avoids setting a global uid/gid override.
conn := nodefs.NewFileSystemConnector(root, &nodefs.Options{})
server, err := fuse.NewServer(conn.RawFS(), mountpoint, mountOptions)
if err != nil {
log.Fatalf("Mount fail: %v\n", err)
}
server.Serve()
}
示例10: NewTestCase
// Create and mount filesystem.
func NewTestCase(t *testing.T) *testCase {
tc := &testCase{}
tc.tester = t
// Make sure system setting does not affect test.
syscall.Umask(0)
const name string = "hello.txt"
const subdir string = "subdir"
var err error
tc.tmpDir, err = ioutil.TempDir("", "go-fuse")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
tc.orig = tc.tmpDir + "/orig"
tc.mnt = tc.tmpDir + "/mnt"
tc.Mkdir(tc.orig, 0700)
tc.Mkdir(tc.mnt, 0700)
tc.mountFile = filepath.Join(tc.mnt, name)
tc.mountSubdir = filepath.Join(tc.mnt, subdir)
tc.origFile = filepath.Join(tc.orig, name)
tc.origSubdir = filepath.Join(tc.orig, subdir)
var pfs pathfs.FileSystem
pfs = pathfs.NewLoopbackFileSystem(tc.orig)
pfs = pathfs.NewLockingFileSystem(pfs)
tc.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{
ClientInodes: true})
tc.connector = nodefs.NewFileSystemConnector(tc.pathFs.Root(),
&nodefs.Options{
EntryTimeout: testTtl,
AttrTimeout: testTtl,
NegativeTimeout: 0.0,
Debug: VerboseTest(),
})
tc.state, err = fuse.NewServer(
fuse.NewRawFileSystem(tc.connector.RawFS()), tc.mnt, &fuse.MountOptions{
SingleThreaded: true,
Debug: VerboseTest(),
})
if err != nil {
t.Fatal("NewServer:", err)
}
go tc.state.Serve()
if err := tc.state.WaitMount(); err != nil {
t.Fatal("WaitMount", err)
}
return tc
}
示例11: NewTestCase
// Create and mount filesystem.
func NewTestCase(t *testing.T) *testCase {
me := &testCase{}
me.tester = t
// Make sure system setting does not affect test.
syscall.Umask(0)
const name string = "hello.txt"
const subdir string = "subdir"
var err error
me.tmpDir, err = ioutil.TempDir("", "go-fuse")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
me.orig = me.tmpDir + "/orig"
me.mnt = me.tmpDir + "/mnt"
os.Mkdir(me.orig, 0700)
os.Mkdir(me.mnt, 0700)
me.mountFile = filepath.Join(me.mnt, name)
me.mountSubdir = filepath.Join(me.mnt, subdir)
me.origFile = filepath.Join(me.orig, name)
me.origSubdir = filepath.Join(me.orig, subdir)
var pfs pathfs.FileSystem
pfs = pathfs.NewLoopbackFileSystem(me.orig)
pfs = pathfs.NewLockingFileSystem(pfs)
me.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{
ClientInodes: true})
me.connector = nodefs.NewFileSystemConnector(me.pathFs.Root(),
&nodefs.Options{
EntryTimeout: testTtl,
AttrTimeout: testTtl,
NegativeTimeout: 0.0,
})
me.connector.SetDebug(VerboseTest())
me.state, err = fuse.NewServer(
fuse.NewRawFileSystem(me.connector.RawFS()), me.mnt, &fuse.MountOptions{SingleThreaded: true})
if err != nil {
t.Fatal("NewServer:", err)
}
me.state.SetDebug(VerboseTest())
// Unthreaded, but in background.
go me.state.Serve()
me.state.WaitMount()
return me
}
示例12: main
func main() {
fsdebug := flag.Bool("fs-debug", false, "switch on FS debugging")
p4port := flag.String("p4-server", "", "address for P4 server")
p4binary := flag.String("p4-binary", "p4", "binary for P4 commandline client")
backingDir := flag.String("backing", "", "directory to store file contents.")
profile := flag.String("profile", "", "record cpu profile.")
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatal("Usage: p4fs MOUNT-POINT")
}
mountpoint := flag.Arg(0)
opts := p4.ConnOptions{
Binary: *p4binary,
Address: *p4port,
}
p4conn := p4.NewConn(opts)
if *backingDir == "" {
d, err := ioutil.TempDir("", "p4fs")
if err != nil {
log.Fatalf("TempDir failed: %v", err)
}
*backingDir = d
defer os.RemoveAll(d)
}
root := NewP4FSRoot(p4conn, *backingDir)
conn := nodefs.NewFileSystemConnector(root, nodefs.NewOptions())
mount, err := fuse.NewServer(conn.RawFS(), mountpoint, nil)
if err != nil {
log.Fatalf("mount failed: %v", err)
}
conn.SetDebug(*fsdebug)
mount.SetDebug(*fsdebug)
log.Println("starting FUSE.")
if *profile != "" {
profFile, err := os.Create(*profile)
if err != nil {
log.Fatalf("os.Create: %v", err)
}
pprof.StartCPUProfile(profFile)
defer pprof.StopCPUProfile()
}
mount.Serve()
}
示例13: mountServer
func (d *keywhizDriver) mountServer(mountpoint string) (*fuse.Server, error) {
logConfig := klog.Config{
Debug: d.config.Debug,
Mountpoint: mountpoint,
}
if err := os.MkdirAll(filepath.Dir(mountpoint), 0755); err != nil {
return nil, err
}
freshThreshold := 200 * time.Millisecond
backendDeadline := 500 * time.Millisecond
maxWait := d.config.TimeoutSeconds + backendDeadline
timeouts := keywhizfs.Timeouts{
Fresh: freshThreshold,
BackendDeadline: backendDeadline,
MaxWait: maxWait,
}
client := keywhizfs.NewClient(d.config.CertFile, d.config.KeyFile, d.config.CaFile,
d.config.ServerURL, d.config.TimeoutSeconds, logConfig, d.config.Ping)
ownership := keywhizfs.NewOwnership(d.config.User, d.config.Group)
kwfs, root, err := keywhizfs.NewKeywhizFs(&client, ownership, timeouts, logConfig)
if err != nil {
client.Errorf("Mount fail: %v\n", err)
return nil, err
}
mountOptions := &fuse.MountOptions{
AllowOther: true,
Name: kwfs.String(),
Options: []string{"default_permissions"},
}
// Empty Options struct avoids setting a global uid/gid override.
conn := nodefs.NewFileSystemConnector(root, &nodefs.Options{})
server, err := fuse.NewServer(conn.RawFS(), mountpoint, mountOptions)
if err != nil {
client.Errorf("Mount fail: %v\n", err)
return nil, err
}
go server.Serve()
return server, nil
}
示例14: MountVfs
func MountVfs(store *storage.Storage, mountPath string, options []string) (*FuseVfs, error) {
fuseVfs := FuseVfs{nil, "", nil}
pathFs := pathfs.NewPathNodeFs(&fuseVfs, nil)
conn := nodefs.NewFileSystemConnector(pathFs.Root(), nil)
mountOptions := &fuse.MountOptions{Options: options}
server, err := fuse.NewServer(conn.RawFS(), mountPath, mountOptions)
if err != nil {
return nil, fmt.Errorf("could not mount virtual filesystem at '%v': %v", mountPath, err)
}
fuseVfs.store = store
fuseVfs.mountPath = mountPath
fuseVfs.server = server
return &fuseVfs, nil
}
示例15: main
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
other := flag.Bool("allow-other", false, "mount with -o allowother.")
flag.Parse()
if flag.NArg() < 2 {
// TODO - where to get program name?
fmt.Println("usage: main MOUNTPOINT ORIGINAL")
os.Exit(2)
}
var finalFs pathfs.FileSystem
orig := flag.Arg(1)
loopbackfs := pathfs.NewLoopbackFileSystem(orig)
finalFs = loopbackfs
opts := &nodefs.Options{
// These options are to be compatible with libfuse defaults,
// making benchmarking easier.
NegativeTimeout: time.Second,
AttrTimeout: time.Second,
EntryTimeout: time.Second,
}
pathFs := pathfs.NewPathNodeFs(finalFs, nil)
conn := nodefs.NewFileSystemConnector(pathFs.Root(), opts)
mountPoint := flag.Arg(0)
origAbs, _ := filepath.Abs(orig)
mOpts := &fuse.MountOptions{
AllowOther: *other,
Name: "loopbackfs",
FsName: origAbs,
}
state, err := fuse.NewServer(conn.RawFS(), mountPoint, mOpts)
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
}
state.SetDebug(*debug)
fmt.Println("Mounted!")
state.Serve()
}