2015-03-12 02:11:29 +00:00
|
|
|
var fuse = require('./')
|
|
|
|
|
2015-08-08 20:56:37 +00:00
|
|
|
var mountPath = process.platform !== 'win32' ? './mnt' : 'M:\\'
|
2015-08-06 19:33:27 +00:00
|
|
|
|
|
|
|
fuse.mount(mountPath, {
|
2015-03-12 02:11:29 +00:00
|
|
|
readdir: function (path, cb) {
|
2015-03-15 10:29:28 +00:00
|
|
|
console.log('readdir(%s)', path)
|
2015-03-12 02:11:29 +00:00
|
|
|
if (path === '/') return cb(0, ['test'])
|
|
|
|
cb(0)
|
|
|
|
},
|
|
|
|
getattr: function (path, cb) {
|
|
|
|
console.log('getattr(%s)', path)
|
|
|
|
if (path === '/') {
|
|
|
|
cb(0, {
|
|
|
|
mtime: new Date(),
|
|
|
|
atime: new Date(),
|
|
|
|
ctime: new Date(),
|
|
|
|
size: 100,
|
|
|
|
mode: 16877,
|
2015-08-06 21:29:42 +00:00
|
|
|
uid: process.getuid ? process.getuid() : 0,
|
|
|
|
gid: process.getgid ? process.getgid() : 0
|
2015-03-12 02:11:29 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path === '/test') {
|
|
|
|
cb(0, {
|
|
|
|
mtime: new Date(),
|
|
|
|
atime: new Date(),
|
|
|
|
ctime: new Date(),
|
|
|
|
size: 12,
|
2015-08-07 02:05:36 +00:00
|
|
|
mode: 33188,
|
2015-08-06 21:29:42 +00:00
|
|
|
uid: process.getuid ? process.getuid() : 0,
|
|
|
|
gid: process.getgid ? process.getgid() : 0
|
2015-03-12 02:11:29 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(fuse.ENOENT)
|
|
|
|
},
|
|
|
|
open: function (path, flags, cb) {
|
|
|
|
console.log('open(%s, %d)', path, flags)
|
|
|
|
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 cb(0)
|
|
|
|
buf.write(str)
|
|
|
|
return cb(str.length)
|
|
|
|
}
|
2015-03-17 12:32:09 +00:00
|
|
|
}, function (err) {
|
|
|
|
if (err) throw err
|
2015-08-06 19:33:27 +00:00
|
|
|
console.log('filesystem mounted on ' + mountPath)
|
2015-03-12 02:11:29 +00:00
|
|
|
})
|
2015-03-12 02:12:14 +00:00
|
|
|
|
|
|
|
process.on('SIGINT', function () {
|
2016-10-17 11:50:38 +00:00
|
|
|
fuse.unmount(mountPath, function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.log('filesystem at ' + mountPath + ' not unmounted', err)
|
|
|
|
} else {
|
|
|
|
console.log('filesystem at ' + mountPath + ' unmounted')
|
|
|
|
}
|
2015-03-12 02:12:14 +00:00
|
|
|
})
|
|
|
|
})
|