1
0
mirror of https://github.com/fuse-friends/fuse-native synced 2024-10-27 18:34:01 +00:00
fuse-friends_fuse-native/example.js
Jan Kühle 8769284245 Fix possible deadlock because of never unlocked mutex during failed unmount (#31)
* Fix possible deadlock because of never unlocked mutex during failed unmount.

* Fix segmentation fault after unmounting.

Scenario:
1. Mount path /a
2. Mount path /b
3. Unmount path /b
4. Appempt to read from path /a will throw segmentation fault.

Reason:
The function bindings_alloc correctly allocates memory and sets the index property of the binding. Afterwards the mount function does memset again for the binding and resets the index to zero. Unmounting will now always NULL the binding at position zero. However the actual binding on position zero is still mounted and the next access to it results in segmentation fault.
2016-10-17 13:50:38 +02:00

66 lines
1.6 KiB
JavaScript

var fuse = require('./')
var mountPath = process.platform !== 'win32' ? './mnt' : 'M:\\'
fuse.mount(mountPath, {
readdir: function (path, cb) {
console.log('readdir(%s)', path)
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,
uid: process.getuid ? process.getuid() : 0,
gid: process.getgid ? process.getgid() : 0
})
return
}
if (path === '/test') {
cb(0, {
mtime: new Date(),
atime: new Date(),
ctime: new Date(),
size: 12,
mode: 33188,
uid: process.getuid ? process.getuid() : 0,
gid: process.getgid ? process.getgid() : 0
})
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)
}
}, function (err) {
if (err) throw err
console.log('filesystem mounted on ' + mountPath)
})
process.on('SIGINT', function () {
fuse.unmount(mountPath, function (err) {
if (err) {
console.log('filesystem at ' + mountPath + ' not unmounted', err)
} else {
console.log('filesystem at ' + mountPath + ' unmounted')
}
})
})