/
main.go
42 lines (36 loc) · 872 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2019 NVI Inc. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package fs
import (
"unsafe"
"github.com/nvi-inc/fsgo/versions"
"github.com/nvi-inc/svipc"
)
type FieldSystem struct {
Version string `json:"version"`
Fscom *Fscom `json:"shm"`
// TODO(dh): Allow different installation paths
}
func (f *FieldSystem) Attach() (err error) {
key, err := svipc.Ftok(SHM_PATH, SHM_ID)
if err != nil {
return
}
id, err := svipc.Shmget(key, unsafe.Sizeof(&Fscom{}), 0666)
if err != nil {
return
}
//TODO(dh): test out writing
ptr, err := svipc.Shmat(id, 0, svipc.SHM_RDONLY)
if err != nil {
return
}
f.Fscom = (*Fscom)(ptr)
return
}
func init() {
versions.Add(FieldSystemVersion, func() versions.FieldSystem {
return &FieldSystem{Version: FieldSystemVersion}
})
}