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

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

parent 035be141
...@@ -254,6 +254,10 @@ type MountOptions struct { ...@@ -254,6 +254,10 @@ type MountOptions struct {
// If RememberInodes is set, we will never forget inodes. // If RememberInodes is set, we will never forget inodes.
// This may be useful for NFS. // This may be useful for NFS.
RememberInodes bool 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. // DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
...@@ -271,6 +275,8 @@ type DefaultFile struct{} ...@@ -271,6 +275,8 @@ type DefaultFile struct{}
// //
// Include DefaultRawFileSystem to inherit a null implementation. // Include DefaultRawFileSystem to inherit a null implementation.
type RawFileSystem interface { type RawFileSystem interface {
String() string
Lookup(out *raw.EntryOut, header *raw.InHeader, name string) (status Status) Lookup(out *raw.EntryOut, header *raw.InHeader, name string) (status Status)
Forget(nodeid, nlookup uint64) Forget(nodeid, nlookup uint64)
......
...@@ -2,6 +2,8 @@ package fuse ...@@ -2,6 +2,8 @@ package fuse
import ( import (
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
"os"
) )
var _ = RawFileSystem((*DefaultRawFileSystem)(nil)) var _ = RawFileSystem((*DefaultRawFileSystem)(nil))
...@@ -9,6 +11,10 @@ var _ = RawFileSystem((*DefaultRawFileSystem)(nil)) ...@@ -9,6 +11,10 @@ var _ = RawFileSystem((*DefaultRawFileSystem)(nil))
func (fs *DefaultRawFileSystem) Init(init *RawFsInit) { 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 { func (fs *DefaultRawFileSystem) StatFs(out *StatfsOut, h *raw.InHeader) Status {
return ENOSYS return ENOSYS
} }
......
...@@ -12,6 +12,13 @@ import ( ...@@ -12,6 +12,13 @@ import (
var _ = log.Println 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) { func (c *FileSystemConnector) Init(fsInit *RawFsInit) {
c.fsInit = *fsInit c.fsInit = *fsInit
} }
......
...@@ -55,6 +55,8 @@ func (ms *MountState) MountPoint() string { ...@@ -55,6 +55,8 @@ func (ms *MountState) MountPoint() string {
return ms.mountPoint return ms.mountPoint
} }
const _MAX_NAME_LEN = 20
// Mount filesystem on mountPoint. // Mount filesystem on mountPoint.
func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error { func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
if opts == nil { if opts == nil {
...@@ -83,6 +85,17 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -83,6 +85,17 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
optStrs = append(optStrs, "allow_other") 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, ",")) file, mp, err := mount(mountPoint, strings.Join(optStrs, ","))
if err != nil { if err != nil {
return err return err
......
...@@ -23,6 +23,7 @@ type MemTreeFs struct { ...@@ -23,6 +23,7 @@ type MemTreeFs struct {
fuse.DefaultNodeFileSystem fuse.DefaultNodeFileSystem
root memNode root memNode
files map[string]MemFile files map[string]MemFile
Name string
} }
func NewMemTreeFs() *MemTreeFs { func NewMemTreeFs() *MemTreeFs {
...@@ -30,6 +31,10 @@ func NewMemTreeFs() *MemTreeFs { ...@@ -30,6 +31,10 @@ func NewMemTreeFs() *MemTreeFs {
return d return d
} }
func (fs *MemTreeFs) String() string {
return fs.Name
}
func (fs *MemTreeFs) OnMount(conn *fuse.FileSystemConnector) { func (fs *MemTreeFs) OnMount(conn *fuse.FileSystemConnector) {
for k, v := range fs.files { for k, v := range fs.files {
fs.addFile(k, v) fs.addFile(k, v)
......
...@@ -61,7 +61,10 @@ func NewZipTree(name string) (map[string]MemFile, error) { ...@@ -61,7 +61,10 @@ func NewZipTree(name string) (map[string]MemFile, error) {
} }
func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) { func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) {
mfs = &MemTreeFs{} mfs = &MemTreeFs{
Name: fmt.Sprintf("fs(%s)", name),
}
if strings.HasSuffix(name, ".zip") { if strings.HasSuffix(name, ".zip") {
mfs.files, err = NewZipTree(name) 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