File: lockingfile.go

package info (click to toggle)
golang-github-hanwen-go-fuse 0.0~git20161210.0.6c2b7d8-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 920 kB
  • ctags: 1,666
  • sloc: cpp: 78; sh: 77; makefile: 21
file content (103 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package nodefs

import (
	"fmt"
	"sync"
	"time"

	"github.com/hanwen/go-fuse/fuse"
)

type lockingFile struct {
	mu   *sync.Mutex
	file File
}

// NewLockingFile serializes operations an existing File.
func NewLockingFile(mu *sync.Mutex, f File) File {
	return &lockingFile{
		mu:   mu,
		file: f,
	}
}

func (f *lockingFile) SetInode(*Inode) {
}

func (f *lockingFile) InnerFile() File {
	return f.file
}

func (f *lockingFile) String() string {
	return fmt.Sprintf("lockingFile(%s)", f.file.String())
}

func (f *lockingFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Read(buf, off)
}

func (f *lockingFile) Write(data []byte, off int64) (uint32, fuse.Status) {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Write(data, off)
}

func (f *lockingFile) Flush() fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Flush()
}

func (f *lockingFile) Release() {
	f.mu.Lock()
	defer f.mu.Unlock()
	f.file.Release()
}

func (f *lockingFile) GetAttr(a *fuse.Attr) fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.GetAttr(a)
}

func (f *lockingFile) Fsync(flags int) (code fuse.Status) {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Fsync(flags)
}

func (f *lockingFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Utimens(atime, mtime)
}

func (f *lockingFile) Truncate(size uint64) fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Truncate(size)
}

func (f *lockingFile) Chown(uid uint32, gid uint32) fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Chown(uid, gid)
}

func (f *lockingFile) Chmod(perms uint32) fuse.Status {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Chmod(perms)
}

func (f *lockingFile) Allocate(off uint64, size uint64, mode uint32) (code fuse.Status) {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Allocate(off, size, mode)
}