github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/swarm/fuse/swarmfs.go (about)

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