github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/swarm/fuse/swarmfs.go (about) 1 // Copyright 2017 The Spectrum Authors 2 // This file is part of the Spectrum library. 3 // 4 // The Spectrum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The Spectrum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the Spectrum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package fuse 18 19 import ( 20 "github.com/SmartMeshFoundation/Spectrum/swarm/api" 21 "sync" 22 "time" 23 ) 24 25 const ( 26 Swarmfs_Version = "0.1" 27 mountTimeout = time.Second * 5 28 unmountTimeout = time.Second * 10 29 maxFuseMounts = 5 30 ) 31 32 var ( 33 swarmfs *SwarmFS // Swarm file system singleton 34 swarmfsLock sync.Once 35 36 inode uint64 = 1 // global inode 37 inodeLock sync.RWMutex 38 ) 39 40 type SwarmFS struct { 41 swarmApi *api.Api 42 activeMounts map[string]*MountInfo 43 swarmFsLock *sync.RWMutex 44 } 45 46 func NewSwarmFS(api *api.Api) *SwarmFS { 47 swarmfsLock.Do(func() { 48 swarmfs = &SwarmFS{ 49 swarmApi: api, 50 swarmFsLock: &sync.RWMutex{}, 51 activeMounts: map[string]*MountInfo{}, 52 } 53 }) 54 return swarmfs 55 56 } 57 58 // Inode numbers need to be unique, they are used for caching inside fuse 59 func NewInode() uint64 { 60 inodeLock.Lock() 61 defer inodeLock.Unlock() 62 inode += 1 63 return inode 64 }