/hookfs

A Usermode Hookable Filesystem Library

Primary LanguageGoApache License 2.0Apache-2.0

HookFS: A Usermode Hookable Filesystem Library

GoDoc

Possible Recipes

  • Fault Injection (Example: Namazu)
  • Cache
  • Malware Detection

and so on..

HookFS was originally developed for Namazu, but we believe HookFS can be also used for other purposes.

Install

$ go get github.com/osrg/hookfs/hookfs

Running an Example

$ cd example/ex01
$ go build
$ ./ex01 "/mnt/hookfs" "/original"
^C
$ fusermount -u "/mnt/hookfs"

API Design

You have to implement HookXXX (e.g. HookOnOpen, HookOnRead, HookOnWrite, ..) interfaces.

type HookOnRead interface {
	// if hooked is true, the real read() would not be called	
	PreRead(path string, length int64, offset int64) (buf []byte, err error, hooked bool, ctx HookContext)
	PostRead(realRetCode int32, realBuf []byte, prehookCtx HookContext) (buf []byte, err error, hooked bool)
}

Then, regist your hook implementation to the HookFS server.

fs, err := NewHookFs("/original", "/mnt/hookfs", &YourHook{})
if err != nil { .. }
err = fs.Serve()

See hook.go for further information. GoDoc is also your friend.

Related Projects

How to Contribute

We welcome your contribution to HookFS. Please feel free to send your pull requests on github!

Copyright

Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.

Released under Apache License 2.0.