func (h *MyHook) PreMkdir(path string, mode uint32) (bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(95) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPreMkdir: returning EACCES")
		return true, ctx, syscall.EACCES
	}
	return false, ctx, nil
}
PreMkdir implements hookfs.HookOnMkdir
package example
import (
	"math/rand"
	"syscall"
	"time"
	hookfs "github.com/osrg/hookfs/pkg/hookfs"
	log "github.com/sirupsen/logrus"
)
type MyHookContext struct {
	path string
}
type MyHook struct{}
func (h *MyHook) Init() error {
	log.WithFields(log.Fields{
		"h": h,
	}).Info("MyInit: initializing")
	return nil
}
func (h *MyHook) PreOpen(path string, flags uint32) (bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(5) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPreOpen: returning EIO")
		return true, ctx, syscall.EIO
	}
	return false, ctx, nil
}
func (h *MyHook) PostOpen(realRetCode int32, ctx hookfs.HookContext) (bool, error) {
	if probab(5) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPostOpen: returning EPERM")
		return true, syscall.EPERM
	}
	return false, nil
}
func (h *MyHook) PreRead(path string, length int64, offset int64) ([]byte, bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(3) {
		sleep := 3 * time.Second
		log.WithFields(log.Fields{
			"h":     h,
			"ctx":   ctx,
			"sleep": sleep,
		}).Info("MyPreRead: sleeping")
		time.Sleep(sleep)
	}
	return nil, false, ctx, nil
}
func (h *MyHook) PostRead(realRetCode int32, realBuf []byte, ctx hookfs.HookContext) ([]byte, bool, error) {
	if probab(70) {
		buf := []byte("Hello HookFS hooked Data!\n")
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
			"buf": buf,
		}).Info("MyPostRead: returning injected buffer")
		return buf, true, nil
	}
	return nil, false, nil
}
func (h *MyHook) PreWrite(path string, buf []byte, offset int64) (bool, hookfs.HookContext, error) {
	ctx := MyHookContext{path: path}
	if probab(3) {
		sleep := 3 * time.Second
		log.WithFields(log.Fields{
			"h":     h,
			"ctx":   ctx,
			"sleep": sleep,
		}).Info("MyPreWrite: sleeping")
		time.Sleep(sleep)
	}
	return false, ctx, nil
}
func (h *MyHook) PostWrite(realRetCode int32, ctx hookfs.HookContext) (bool, error) {
	if probab(70) {
		log.WithFields(log.Fields{
			"h":   h,
			"ctx": ctx,
		}).Info("MyPostWrite: returning ENOSPC")
		return true, syscall.ENOSPC
	}
	return false, nil
}