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