forked from refinio/fuse-native
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
101 lines (91 loc) · 3.07 KB
/
example.js
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
import Fuse, { ENOENT } from "./";
const directory = 0o40000;
const regularFile = 0o100000;
const ops = {
readdir: function (path, cb) {
console.log("readdir(%s)", path);
if (path === "/")
return process.nextTick(
cb,
0,
["test"],
[
{
mtime: new Date(),
atime: new Date(),
ctime: new Date(),
nlink: 1,
size: 12,
mode: regularFile | 0o777,
uid: process.getuid ? process.getuid() : 0,
gid: process.getgid ? process.getgid() : 0,
},
]
);
return process.nextTick(cb, 0);
},
/*
access: function (path, cb) {
return process.nextTick(cb, 0)
},
*/
getattr: function (path, cb) {
console.log("getattr(%s)", path);
if (path === "/") {
return process.nextTick(cb, 0, {
mtime: new Date(),
atime: new Date(),
ctime: new Date(),
nlink: 1,
size: 100,
mode: directory | 0o777,
uid: process.getuid ? process.getuid() : 0,
gid: process.getgid ? process.getgid() : 0,
});
}
if (path === "/test") {
return process.nextTick(cb, 0, {
mtime: new Date(),
atime: new Date(),
ctime: new Date(),
nlink: 1,
size: 12,
mode: regularFile | 0o777,
uid: process.getuid ? process.getuid() : 0,
gid: process.getgid ? process.getgid() : 0,
});
}
return process.nextTick(cb, ENOENT);
},
open: function (path, flags, cb) {
console.log("open(%s, %d)", path, flags);
return process.nextTick(cb, 0, 42); // 42 is an fd
},
read: function (path, fd, buf, len, pos, cb) {
console.log("read(%s, %d, %d, %d)", path, fd, len, pos);
var str = "hello world\n".slice(pos);
if (!str) return process.nextTick(cb, 0);
buf.write(str);
return process.nextTick(cb, str.length);
},
};
// Examples:
// Mount as drive letter on Windows.
// const fuse = new Fuse("M:", ops, { debug: true, displayFolder: true, volname: "Test Drive" });
// Mount as path on Windows (folder must not exist).
// const fuse = new Fuse("C:\\Test\\Drive", ops, { debug: true, displayFolder: true, volname: "Test Drive" });
// Mount as path on POSIX systems.
const fuse = new Fuse("./mnt", ops, { debug: true, displayFolder: true });
fuse.mount((err) => {
if (err) throw err;
console.log("filesystem mounted on " + fuse.mnt);
});
process.once("SIGINT", function () {
fuse.unmount((err) => {
if (err) {
console.log("filesystem at " + fuse.mnt + " not unmounted", err);
} else {
console.log("filesystem at " + fuse.mnt + " unmounted");
}
});
});