-
Notifications
You must be signed in to change notification settings - Fork 86
/
hellofs.go
79 lines (69 loc) · 1.46 KB
/
hellofs.go
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
/*
* hellofs.go
*
* Copyright 2017-2022 Bill Zissimopoulos
*/
/*
* This file is part of Cgofuse.
*
* It is licensed under the MIT license. The full license text can be found
* in the License.txt file at the root of this project.
*/
package main
import (
"os"
"github.com/winfsp/cgofuse/fuse"
)
const (
filename = "hello"
contents = "hello, world\n"
)
type Hellofs struct {
fuse.FileSystemBase
}
func (self *Hellofs) Open(path string, flags int) (errc int, fh uint64) {
switch path {
case "/" + filename:
return 0, 0
default:
return -fuse.ENOENT, ^uint64(0)
}
}
func (self *Hellofs) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int) {
switch path {
case "/":
stat.Mode = fuse.S_IFDIR | 0555
return 0
case "/" + filename:
stat.Mode = fuse.S_IFREG | 0444
stat.Size = int64(len(contents))
return 0
default:
return -fuse.ENOENT
}
}
func (self *Hellofs) Read(path string, buff []byte, ofst int64, fh uint64) (n int) {
endofst := ofst + int64(len(buff))
if endofst > int64(len(contents)) {
endofst = int64(len(contents))
}
if endofst < ofst {
return 0
}
n = copy(buff, contents[ofst:endofst])
return
}
func (self *Hellofs) Readdir(path string,
fill func(name string, stat *fuse.Stat_t, ofst int64) bool,
ofst int64,
fh uint64) (errc int) {
fill(".", nil, 0)
fill("..", nil, 0)
fill(filename, nil, 0)
return 0
}
func main() {
hellofs := &Hellofs{}
host := fuse.NewFileSystemHost(hellofs)
host.Mount("", os.Args[1:])
}