github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/third_party/bazil.org/fuse/hellofs/hello.go (about)

     1  // Hellofs implements a simple "hello world" file system.
     2  package main
     3  
     4  import (
     5  	"flag"
     6  	"fmt"
     7  	"log"
     8  	"os"
     9  
    10  	"camlistore.org/third_party/bazil.org/fuse"
    11  	"camlistore.org/third_party/bazil.org/fuse/fs"
    12  )
    13  
    14  var Usage = func() {
    15  	fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
    16  	fmt.Fprintf(os.Stderr, "  %s MOUNTPOINT\n", os.Args[0])
    17  	flag.PrintDefaults()
    18  }
    19  
    20  func main() {
    21  	flag.Usage = Usage
    22  	flag.Parse()
    23  
    24  	if flag.NArg() != 1 {
    25  		Usage()
    26  		os.Exit(2)
    27  	}
    28  	mountpoint := flag.Arg(0)
    29  
    30  	c, err := fuse.Mount(mountpoint)
    31  	if err != nil {
    32  		log.Fatal(err)
    33  	}
    34  
    35  	fs.Serve(c, FS{})
    36  }
    37  
    38  // FS implements the hello world file system.
    39  type FS struct{}
    40  
    41  func (FS) Root() (fs.Node, fuse.Error) {
    42  	return Dir{}, nil
    43  }
    44  
    45  // Dir implements both Node and Handle for the root directory.
    46  type Dir struct{}
    47  
    48  func (Dir) Attr() fuse.Attr {
    49  	return fuse.Attr{Inode: 1, Mode: os.ModeDir | 0555}
    50  }
    51  
    52  func (Dir) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
    53  	if name == "hello" {
    54  		return File{}, nil
    55  	}
    56  	return nil, fuse.ENOENT
    57  }
    58  
    59  var dirDirs = []fuse.Dirent{
    60  	{Inode: 2, Name: "hello", Type: fuse.DT_File},
    61  }
    62  
    63  func (Dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
    64  	return dirDirs, nil
    65  }
    66  
    67  // File implements both Node and Handle for the hello file.
    68  type File struct{}
    69  
    70  func (File) Attr() fuse.Attr {
    71  	return fuse.Attr{Mode: 0444}
    72  }
    73  
    74  func (File) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
    75  	return []byte("hello, world\n"), nil
    76  }