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

Add hello example.

parent 3ad26b23
include $(GOROOT)/src/Make.inc
TARG=hello
GOFILES=hello.go
DEPS=../../fuse
include $(GOROOT)/src/Make.cmd
// A Go mirror of libfuse's hello.c
package main
import (
"flag"
"log"
"github.com/hanwen/go-fuse/fuse"
"os"
)
type HelloFs struct {
fuse.DefaultFileSystem
}
func (me *HelloFs) GetAttr(name string) (*os.FileInfo, fuse.Status) {
switch name {
case "file.txt":
return &os.FileInfo{
Mode: fuse.S_IFREG | 0644, Size: int64(len(name)),
}, fuse.OK
case "":
return &os.FileInfo{
Mode: fuse.S_IFDIR | 0755,
}, fuse.OK
}
return nil, fuse.ENOENT
}
func (me *HelloFs) OpenDir(name string) (c chan fuse.DirEntry, code fuse.Status) {
if name == "" {
c = make(chan fuse.DirEntry, 1)
c <- fuse.DirEntry{Name: "file.txt",Mode: fuse.S_IFREG}
close(c)
return c, fuse.OK
}
return nil, fuse.ENOENT
}
func (me *HelloFs) Open(name string, flags uint32) (file fuse.File, code fuse.Status) {
if name != "file.txt" {
return nil, fuse.ENOENT
}
if flags & fuse.O_ANYWRITE != 0 {
return nil, fuse.EPERM
}
return fuse.NewReadOnlyFile([]byte(name)), fuse.OK
}
func main() {
if len(flag.Args()) < 1 {
log.Fatal("Usage:\n hello MOUNTPOINT")
}
state, conn, err := fuse.MountFileSystem(flag.Arg(0), &HelloFs{}, nil)
if err != nil {
log.Fatal("Mount fail: %v\n", err)
}
state.Loop(true)
}
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