fsproxy

package module
v0.0.0-...-7fe2fa8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2014 License: MIT Imports: 9 Imported by: 0

README

Current Status: UNSTABLE

Very unstable proof-of-concept. No tests!

fsproxy

A FUSE-based filesystem proxy with hooks!

This lets you (re)mount a portion of the filesystem elsewhere while hooking in to listing and reading functionality so you can add/remove/alter files and directories.

An example of using the hooks to uppercase the contents of all the files, check out uppercasefs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory struct {
	Proxy      *Proxy
	Path       string
	Name       string
	Attributes fuse.Attr
}

func (*Directory) Attr

func (dir *Directory) Attr() fuse.Attr

func (*Directory) Lookup

func (dir *Directory) Lookup(path string, intr fs.Intr) (fs.Node, fuse.Error)

func (*Directory) ReadDir

func (dir *Directory) ReadDir(fs.Intr) ([]fuse.Dirent, fuse.Error)

type File

type File struct {
	Proxy      *Proxy
	Path       string
	Attributes fuse.Attr
}

func (*File) Attr

func (file *File) Attr() fuse.Attr

func (*File) ReadAll

func (file *File) ReadAll(intr fs.Intr) ([]byte, fuse.Error)

type ListFunc

type ListFunc func(p *Proxy, path string) ([]fuse.Dirent, fuse.Error)
var DefaultList ListFunc = func(proxy *Proxy, path string) ([]fuse.Dirent, fuse.Error) {
	file, err := os.Open(path)
	if file == nil {
		fmt.Fprintf(os.Stderr, "cannot access %s: %v\n", path, err)
		os.Exit(1)
	}

	files, err := file.Readdirnames(-1)
	if err != nil {
		log.Fatalf("Could not read dir names %v", path)
	}

	dirs := []fuse.Dirent{}

	for j := 0; j < len(files); j++ {
		filepath := os_path.Join(path, files[j])
		info, err := os.Stat(filepath)
		if err != nil {
			return nil, fuse.Errno(syscall.ENOSYS)
		}
		var t fuse.DirentType

		if info.IsDir() {
			t = fuse.DT_Dir
		}

		dirs = append(dirs, fuse.Dirent{
			Inode: proxy.inodeForPath(filepath),
			Name:  files[j],
			Type:  t,
		})

	}

	return dirs, nil
}

type LookupFunc

type LookupFunc func(p *Proxy, path string, intr fs.Intr) (fs.Node, fuse.Error)
var DefaultLookup LookupFunc = func(p *Proxy, path string, intr fs.Intr) (fs.Node, fuse.Error) {
	fmt.Println("In default lookup for ", path)

	info, err := os.Stat(path)
	if err != nil {
		return nil, fuse.Errno(syscall.ENOSYS)
	}

	if info.IsDir() {
		return &Directory{
			Proxy:      p,
			Path:       path,
			Attributes: dirAttrsForPath(p, path),
		}, nil
	} else {
		return &File{
			Proxy: p,
			Path:  path,
			Attributes: fuse.Attr{
				Inode: p.inodeForPath(path),
				Mode:  0555,
			},
		}, nil
	}

	return nil, fuse.Errno(syscall.ENOSYS)
}

type Proxy

type Proxy struct {
	Mountpoint string
	Source     string
	List       ListFunc
	Lookup     LookupFunc
	ReadAll    ReadAllFunc
	// contains filtered or unexported fields
}

func New

func New(mountpoint, source string) *Proxy

func (*Proxy) Directory

func (proxy *Proxy) Directory(path string) (fs.Node, fuse.Error)

func (*Proxy) Root

func (proxy *Proxy) Root() (fs.Node, fuse.Error)

func (*Proxy) Serve

func (proxy *Proxy) Serve() error

type ReadAllFunc

type ReadAllFunc func(p *Proxy, path string) ([]byte, fuse.Error)
var DefaultReadAll ReadAllFunc = func(proxy *Proxy, path string) ([]byte, fuse.Error) {

	bytes, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, fuse.Errno(syscall.ENOSYS)
	}
	return bytes, nil
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL