ref: 295d55901af45d32853794745613ae741dab66e8
author: penny <penny@limitedideas.org>
date: Tue Nov 25 22:31:29 EST 2025
initial snarflogger
--- /dev/null
+++ b/go.mod
@@ -1,0 +1,12 @@
+module snarflogger
+
+go 1.25.4
+
+require github.com/knusbaum/go9p v1.18.0
+
+require (
+ 9fans.net/go v0.0.2 // indirect
+ github.com/Plan9-Archive/libauth v0.0.0-20180917063427-d1ca9e94969d // indirect
+ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
+ github.com/fhs/mux9p v0.3.1 // indirect
+)
--- /dev/null
+++ b/go.sum
@@ -1,0 +1,25 @@
+9fans.net/go v0.0.2 h1:RYM6lWITV8oADrwLfdzxmt8ucfW6UtP9v1jg4qAbqts=
+9fans.net/go v0.0.2/go.mod h1:lfPdxjq9v8pVQXUMBCx5EO5oLXWQFlKRQgs1kEkjoIM=
+github.com/Plan9-Archive/libauth v0.0.0-20180917063427-d1ca9e94969d h1:xH/U6K+HYxh1480TkQYRqRO8F2RJsg+R6wFiVJzdldg=
+github.com/Plan9-Archive/libauth v0.0.0-20180917063427-d1ca9e94969d/go.mod h1:UKp8dv9aeaZoQFWin7eQXtz89iHly1YAFZNn3MCutmQ=
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
+github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
+github.com/fhs/mux9p v0.3.1 h1:x1UswUWZoA9vrA02jfisndCq3xQm+wrQUxUt5N99E08=
+github.com/fhs/mux9p v0.3.1/go.mod h1:F4hwdenmit0WDoNVT2VMWlLJrBVCp/8UhzJa7scfjEQ=
+github.com/hanwen/go-fuse v1.0.0/go.mod h1:unqXarDXqzAk0rt98O2tVndEPIpUgLD9+rwFisZH3Ok=
+github.com/hanwen/go-fuse/v2 v2.0.3/go.mod h1:0EQM6aH2ctVpvZ6a+onrQ/vaykxh2GH7hy3e13vzTUY=
+github.com/knusbaum/go9p v1.18.0 h1:/Y67RNvNKX1ZV1IOdnO1lIetiF0X+CumOyvEc0011GI=
+github.com/knusbaum/go9p v1.18.0/go.mod h1:HtMoJKqZUe1Oqag5uJqG5RKQ9gWPSP+wolsnLLv44r8=
+github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
--- /dev/null
+++ b/main.go
@@ -1,0 +1,63 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "io"
+
+ "github.com/knusbaum/go9p/fs"
+ "github.com/knusbaum/go9p"
+ "github.com/knusbaum/go9p/proto"
+)
+
+type snarfile struct {+ fs.BaseFile
+ real *os.File
+ realwrite *os.File
+}
+
+func (f *snarfile) Write(fid uint64, offset uint64, data []byte) (uint32, error) {+ f.realwrite.Write(data)
+ fmt.Println(string(data))
+ return uint32(len(data)), nil
+}
+
+func (f *snarfile) Read(fid uint64, offset uint64, count uint64) ([]byte, error) {+ var reader io.Reader = f.real
+ content, err := io.ReadAll(reader)
+ return content, err
+}
+
+func newSnarf(fsys *fs.FS, name, uid, gid string, perm uint32, real *os.File, realwrite *os.File) *snarfile {+ stat := fsys.NewStat(name, uid, gid, perm)
+ return &snarfile{+ BaseFile: *fs.NewBaseFile(stat),
+ real: real,
+ realwrite: realwrite,
+ }
+}
+
+func main() {+ fid, dir := fs.NewFS("penny", "penny", proto.DMDIR|0644)+
+ realread, err := os.OpenFile("/dev/snarf", os.O_RDONLY, 0644)+ if err != nil {+ fmt.Printf("Coudn't open snarf: %s\n", err)+ return
+ }
+ realwrite, err := os.OpenFile("/dev/snarf", os.O_WRONLY, 0644)+ if err != nil {+ fmt.Printf("Coudn't open snarf for writing: %s\n", err)+ return
+ }
+ snarf := newSnarf(fid, "snarf", "penny", "penny", 0644, realread, realwrite)
+
+ if err := dir.AddChild(snarf); err != nil {+ fmt.Printf("Err: %s\n", err)+ return
+ }
+ if err := go9p.PostSrv("snarflogger", fid.Server()); err != nil {+ fmt.Printf("Failed to post server: %v\n", err)+ return
+ }
+}
--
⑨