github.com/hanwen/go-fuse@v1.0.0/fuse/nodefs/lockingfile.go (about)

     1  // Copyright 2016 the Go-FUSE Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package nodefs
     6  
     7  import (
     8  	"fmt"
     9  	"sync"
    10  	"time"
    11  
    12  	"github.com/hanwen/go-fuse/fuse"
    13  )
    14  
    15  type lockingFile struct {
    16  	mu   *sync.Mutex
    17  	file File
    18  }
    19  
    20  // NewLockingFile serializes operations an existing File.
    21  func NewLockingFile(mu *sync.Mutex, f File) File {
    22  	return &lockingFile{
    23  		mu:   mu,
    24  		file: f,
    25  	}
    26  }
    27  
    28  func (f *lockingFile) SetInode(*Inode) {
    29  }
    30  
    31  func (f *lockingFile) InnerFile() File {
    32  	return f.file
    33  }
    34  
    35  func (f *lockingFile) String() string {
    36  	return fmt.Sprintf("lockingFile(%s)", f.file.String())
    37  }
    38  
    39  func (f *lockingFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
    40  	f.mu.Lock()
    41  	defer f.mu.Unlock()
    42  	return f.file.Read(buf, off)
    43  }
    44  
    45  func (f *lockingFile) Write(data []byte, off int64) (uint32, fuse.Status) {
    46  	f.mu.Lock()
    47  	defer f.mu.Unlock()
    48  	return f.file.Write(data, off)
    49  }
    50  
    51  func (f *lockingFile) Flush() fuse.Status {
    52  	f.mu.Lock()
    53  	defer f.mu.Unlock()
    54  	return f.file.Flush()
    55  }
    56  
    57  func (f *lockingFile) GetLk(owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (code fuse.Status) {
    58  	f.mu.Lock()
    59  	defer f.mu.Unlock()
    60  	return f.file.GetLk(owner, lk, flags, out)
    61  }
    62  
    63  func (f *lockingFile) SetLk(owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) {
    64  	f.mu.Lock()
    65  	defer f.mu.Unlock()
    66  	return f.file.SetLk(owner, lk, flags)
    67  }
    68  
    69  func (f *lockingFile) SetLkw(owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) {
    70  	f.mu.Lock()
    71  	defer f.mu.Unlock()
    72  	return f.file.SetLkw(owner, lk, flags)
    73  }
    74  
    75  func (f *lockingFile) Release() {
    76  	f.mu.Lock()
    77  	defer f.mu.Unlock()
    78  	f.file.Release()
    79  }
    80  
    81  func (f *lockingFile) GetAttr(a *fuse.Attr) fuse.Status {
    82  	f.mu.Lock()
    83  	defer f.mu.Unlock()
    84  	return f.file.GetAttr(a)
    85  }
    86  
    87  func (f *lockingFile) Fsync(flags int) (code fuse.Status) {
    88  	f.mu.Lock()
    89  	defer f.mu.Unlock()
    90  	return f.file.Fsync(flags)
    91  }
    92  
    93  func (f *lockingFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
    94  	f.mu.Lock()
    95  	defer f.mu.Unlock()
    96  	return f.file.Utimens(atime, mtime)
    97  }
    98  
    99  func (f *lockingFile) Truncate(size uint64) fuse.Status {
   100  	f.mu.Lock()
   101  	defer f.mu.Unlock()
   102  	return f.file.Truncate(size)
   103  }
   104  
   105  func (f *lockingFile) Chown(uid uint32, gid uint32) fuse.Status {
   106  	f.mu.Lock()
   107  	defer f.mu.Unlock()
   108  	return f.file.Chown(uid, gid)
   109  }
   110  
   111  func (f *lockingFile) Chmod(perms uint32) fuse.Status {
   112  	f.mu.Lock()
   113  	defer f.mu.Unlock()
   114  	return f.file.Chmod(perms)
   115  }
   116  
   117  func (f *lockingFile) Allocate(off uint64, size uint64, mode uint32) (code fuse.Status) {
   118  	f.mu.Lock()
   119  	defer f.mu.Unlock()
   120  	return f.file.Allocate(off, size, mode)
   121  }