mpvfs

9P file server for controlling mpv playback

git clone https://git.8pit.net/mpvfs.git

 1package fileserver
 2
 3import (
 4	"go.rbn.im/neinp/qid"
 5	"go.rbn.im/neinp/stat"
 6
 7	"hash/fnv"
 8	"time"
 9)
10
11func createStat(name string, mode stat.Mode) stat.Stat {
12	now := time.Now()
13
14	var qtype qid.Type
15	if mode&stat.Dir != 0 {
16		qtype = qid.TypeDir
17	} else {
18		qtype = qid.TypeFile
19	}
20
21	q := qid.Qid{Type: qtype, Version: 0, Path: hashPath(name)}
22	s := stat.Stat{
23		Qid:    q,
24		Mode:   mode,
25		Atime:  now,
26		Mtime:  now,
27		Length: 0,
28		Name:   name,
29	}
30
31	return s
32}
33
34func hashPath(s string) uint64 {
35	h := fnv.New64a()
36	h.Write([]byte(s))
37	return h.Sum64()
38}