Commit ba9f7973 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Identify mounts by name rather than '/dev/fuse'.

parent 035be141
......@@ -146,7 +146,7 @@ type PathNodeFsOptions struct {
// A File object should be returned from FileSystem.Open and
// FileSystem.Create. Include DefaultFile into the struct to inherit
// a default null implementation.
// a default null implementation.
//
// TODO - should File be thread safe?
// TODO - should we pass a *Context argument?
......@@ -254,6 +254,10 @@ type MountOptions struct {
// If RememberInodes is set, we will never forget inodes.
// This may be useful for NFS.
RememberInodes bool
// The Name will show up on the output of the mount. Keep this string
// small.
Name string
}
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
......@@ -271,6 +275,8 @@ type DefaultFile struct{}
//
// Include DefaultRawFileSystem to inherit a null implementation.
type RawFileSystem interface {
String() string
Lookup(out *raw.EntryOut, header *raw.InHeader, name string) (status Status)
Forget(nodeid, nlookup uint64)
......
......@@ -2,6 +2,8 @@ package fuse
import (
"github.com/hanwen/go-fuse/raw"
"os"
)
var _ = RawFileSystem((*DefaultRawFileSystem)(nil))
......@@ -9,6 +11,10 @@ var _ = RawFileSystem((*DefaultRawFileSystem)(nil))
func (fs *DefaultRawFileSystem) Init(init *RawFsInit) {
}
func (fs *DefaultRawFileSystem) String() string {
return os.Args[0]
}
func (fs *DefaultRawFileSystem) StatFs(out *StatfsOut, h *raw.InHeader) Status {
return ENOSYS
}
......
......@@ -12,6 +12,13 @@ import (
var _ = log.Println
func (c *FileSystemConnector) String() string {
if c.rootNode == nil || c.rootNode.mount == nil {
return "go-fuse:unmounted"
}
return c.rootNode.mount.fs.String()
}
func (c *FileSystemConnector) Init(fsInit *RawFsInit) {
c.fsInit = *fsInit
}
......
......@@ -55,6 +55,8 @@ func (ms *MountState) MountPoint() string {
return ms.mountPoint
}
const _MAX_NAME_LEN = 20
// Mount filesystem on mountPoint.
func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
if opts == nil {
......@@ -83,6 +85,17 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
optStrs = append(optStrs, "allow_other")
}
name := opts.Name
if name == "" {
name = ms.fileSystem.String()
l := len(name)
if l > _MAX_NAME_LEN {
l = _MAX_NAME_LEN
}
name = strings.Replace(name[:l], ",", ";", -1)
}
optStrs = append(optStrs, "subtype=" + name)
file, mp, err := mount(mountPoint, strings.Join(optStrs, ","))
if err != nil {
return err
......
......@@ -23,6 +23,7 @@ type MemTreeFs struct {
fuse.DefaultNodeFileSystem
root memNode
files map[string]MemFile
Name string
}
func NewMemTreeFs() *MemTreeFs {
......@@ -30,6 +31,10 @@ func NewMemTreeFs() *MemTreeFs {
return d
}
func (fs *MemTreeFs) String() string {
return fs.Name
}
func (fs *MemTreeFs) OnMount(conn *fuse.FileSystemConnector) {
for k, v := range fs.files {
fs.addFile(k, v)
......
......@@ -61,7 +61,10 @@ func NewZipTree(name string) (map[string]MemFile, error) {
}
func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) {
mfs = &MemTreeFs{}
mfs = &MemTreeFs{
Name: fmt.Sprintf("fs(%s)", name),
}
if strings.HasSuffix(name, ".zip") {
mfs.files, err = NewZipTree(name)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment