1
0
mirror of https://github.com/fuse-friends/fuse-native synced 2024-10-27 18:34:01 +00:00
fuse-friends_fuse-native/index.js

723 lines
17 KiB
JavaScript
Raw Normal View History

2019-07-31 12:44:22 +00:00
const os = require('os')
const fs = require('fs')
const path = require('path')
2019-08-06 08:55:08 +00:00
const { exec } = require('child_process')
const Nanoresource = require('nanoresource')
2019-09-18 16:44:54 +00:00
const { beforeMount, beforeUnmount, configure, unconfigure, isConfigured } = require('fuse-shared-library')
2019-08-06 08:55:08 +00:00
const binding = require('node-gyp-build')(__dirname)
2019-07-31 12:44:22 +00:00
const IS_OSX = os.platform() === 'darwin'
const OSX_FOLDER_ICON = '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericFolderIcon.icns'
const HAS_FOLDER_ICON = IS_OSX && fs.existsSync(OSX_FOLDER_ICON)
2019-07-24 14:52:17 +00:00
2019-07-31 21:59:36 +00:00
const OpcodesAndDefaults = new Map([
2019-08-01 12:24:01 +00:00
['init', {
2019-08-06 08:55:08 +00:00
op: binding.op_init
2019-08-01 12:24:01 +00:00
}],
['error', {
2019-08-06 08:55:08 +00:00
op: binding.op_error
2019-08-01 12:24:01 +00:00
}],
['access', {
2019-08-06 08:55:08 +00:00
op: binding.op_access,
2019-08-01 12:24:01 +00:00
defaults: [0]
}],
['statfs', {
2019-08-06 08:55:08 +00:00
op: binding.op_statfs,
2019-08-01 12:24:01 +00:00
defaults: [getStatfsArray()]
}],
['fgetattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_fgetattr,
2019-08-01 12:24:01 +00:00
defaults: [getStatArray()]
}],
['getattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_getattr,
2019-08-01 12:24:01 +00:00
defaults: [getStatArray()]
}],
['flush', {
2019-08-06 08:55:08 +00:00
op: binding.op_flush
2019-08-01 12:24:01 +00:00
}],
['fsync', {
2019-08-06 08:55:08 +00:00
op: binding.op_fsync
2019-08-01 12:24:01 +00:00
}],
['fsyncdir', {
2019-08-06 08:55:08 +00:00
op: binding.op_fsyncdir
2019-08-01 12:24:01 +00:00
}],
['readdir', {
2019-08-06 09:24:04 +00:00
op: binding.op_readdir,
defaults: [[], []]
2019-08-01 12:24:01 +00:00
}],
['truncate', {
2019-08-06 08:55:08 +00:00
op: binding.op_truncate
2019-08-01 12:24:01 +00:00
}],
['ftruncate', {
2019-08-06 08:55:08 +00:00
op: binding.op_ftruncate
2019-08-01 12:24:01 +00:00
}],
['utimens', {
2019-08-06 08:55:08 +00:00
op: binding.op_utimens
2019-08-01 12:24:01 +00:00
}],
['readlink', {
2019-08-06 08:55:08 +00:00
op: binding.op_readlink,
2019-08-01 12:24:01 +00:00
defaults: ['']
}],
['chown', {
2019-08-06 08:55:08 +00:00
op: binding.op_chown
2019-08-01 12:24:01 +00:00
}],
['chmod', {
2019-08-06 08:55:08 +00:00
op: binding.op_chmod
2019-08-01 12:24:01 +00:00
}],
['mknod', {
2019-08-06 08:55:08 +00:00
op: binding.op_mknod
2019-08-01 12:24:01 +00:00
}],
['setxattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_setxattr
2019-08-01 12:24:01 +00:00
}],
['getxattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_getxattr
2019-08-01 12:24:01 +00:00
}],
['listxattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_listxattr
2019-08-01 12:24:01 +00:00
}],
['removexattr', {
2019-08-06 08:55:08 +00:00
op: binding.op_removexattr
2019-08-01 12:24:01 +00:00
}],
['open', {
2019-08-06 08:55:08 +00:00
op: binding.op_open,
2019-08-01 15:00:14 +00:00
defaults: [0]
2019-08-01 12:24:01 +00:00
}],
['opendir', {
2019-08-06 08:55:08 +00:00
op: binding.op_opendir,
2019-08-01 15:00:14 +00:00
defaults: [0]
2019-08-01 12:24:01 +00:00
}],
['read', {
2019-08-06 08:55:08 +00:00
op: binding.op_read,
2019-08-01 12:24:01 +00:00
defaults: [0]
}],
['write', {
2019-08-06 08:55:08 +00:00
op: binding.op_write,
2019-08-01 12:24:01 +00:00
defaults: [0]
}],
['release', {
2019-08-06 08:55:08 +00:00
op: binding.op_release
2019-08-01 12:24:01 +00:00
}],
['releasedir', {
2019-08-06 08:55:08 +00:00
op: binding.op_releasedir
2019-08-01 12:24:01 +00:00
}],
['create', {
2019-08-06 09:24:04 +00:00
op: binding.op_create,
defaults: [0]
2019-08-01 12:24:01 +00:00
}],
['unlink', {
2019-08-06 08:55:08 +00:00
op: binding.op_unlink
2019-08-01 12:24:01 +00:00
}],
['rename', {
2019-08-06 08:55:08 +00:00
op: binding.op_rename
2019-08-01 12:24:01 +00:00
}],
['link', {
2019-08-06 08:55:08 +00:00
op: binding.op_link
2019-08-01 12:24:01 +00:00
}],
['symlink', {
2019-08-06 08:55:08 +00:00
op: binding.op_symlink
2019-08-01 12:24:01 +00:00
}],
['mkdir', {
2019-08-06 08:55:08 +00:00
op: binding.op_mkdir
2019-08-01 12:24:01 +00:00
}],
['rmdir', {
2019-08-06 08:55:08 +00:00
op: binding.op_rmdir
2019-08-01 12:24:01 +00:00
}],
['destroy', {
2019-08-06 08:55:08 +00:00
op: binding.op_destroy
2019-08-01 12:24:01 +00:00
}]
2019-07-29 11:57:46 +00:00
])
2019-07-24 14:52:17 +00:00
2019-08-06 08:55:08 +00:00
class Fuse extends Nanoresource {
2019-07-29 11:57:46 +00:00
constructor (mnt, ops, opts = {}) {
2019-08-06 08:55:08 +00:00
super()
2019-07-29 11:57:46 +00:00
this.opts = opts
2019-07-31 12:44:22 +00:00
this.mnt = path.resolve(mnt)
2019-07-29 11:57:46 +00:00
2019-07-31 12:44:22 +00:00
this.ops = ops
2019-08-06 08:55:08 +00:00
this._thread = null
2019-07-31 21:59:36 +00:00
this._handlers = this._makeHandlerArray()
2019-08-07 10:54:00 +00:00
this._closed = false
2019-07-29 11:57:46 +00:00
2019-08-06 08:55:08 +00:00
const implemented = [binding.op_init, binding.op_error, binding.op_getattr]
2019-07-29 11:57:46 +00:00
if (ops) {
2019-08-01 12:24:01 +00:00
for (const [name, { op }] of OpcodesAndDefaults) {
if (ops[name]) implemented.push(op)
2019-07-29 11:57:46 +00:00
}
}
this._implemented = new Set(implemented)
// Used to determine if the user-defined callback needs to be nextTick'd.
this._sync = true
}
2019-08-01 15:00:14 +00:00
_getImplementedArray () {
const implemented = new Uint32Array(35)
2019-08-06 08:55:08 +00:00
for (const impl of this._implemented) {
2019-08-01 15:00:14 +00:00
implemented[impl] = 1
}
return implemented
}
2019-07-31 12:44:22 +00:00
_fuseOptions () {
const options = []
if ((/\*|(^,)fuse-bindings(,$)/.test(process.env.DEBUG)) || this.opts.debug) options.push('debug')
if (this.opts.allowOther) options.push('allow_other')
if (this.opts.allowRoot) options.push('allow_root')
if (this.opts.autoUnmount) options.push('auto_unmount')
if (this.opts.defaultPermissions) options.push('default_permissions')
if (this.opts.blkdev) options.push('blkdev')
if (this.opts.blksize) options.push('blksize=' + this.opts.blksize)
if (this.opts.maxRead) options.push('max_read=' + this.opts.maxRead)
if (this.opts.fd) options.push('fd=' + this.opts.fd)
if (this.opts.userId) options.push('user_id=', this.opts.userId)
if (this.opts.fsname) options.push('fsname=' + this.opts.fsname)
if (this.opts.subtype) options.push('subtype=' + this.opts.subtype)
if (this.opts.kernelCache) options.push('kernel_cache')
if (this.opts.autoCache) options.push('auto_cache')
if (this.opts.umask) options.push('umask=' + this.opts.umask)
if (this.opts.uid) options.push('uid=' + this.opts.uid)
if (this.opts.gid) options.push('gid=' + this.opts.gid)
if (this.opts.entryTimeout) options.push('entry_timeout=' + this.opts.entryTimeout)
if (this.opts.attrTimeout) options.push('attr_timeout=' + this.opts.attrTimeout)
if (this.opts.acAttrTimeout) options.push('ac_attr_timeout=' + this.opts.acAttrTimeout)
if (this.opts.noforget) options.push('noforget')
if (this.opts.remember) options.push('remember=' + this.opts.remember)
if (this.opts.modules) options.push('modules=' + this.opts.modules)
if (this.opts.displayFolder && IS_OSX) { // only works on osx
options.push('volname=' + path.basename(this.mnt))
if (HAS_FOLDER_ICON) options.push('volicon=' + OSX_FOLDER_ICON)
}
return options.map(o => '-o' + o).join(' ')
}
2019-07-31 21:59:36 +00:00
_makeHandlerArray () {
2019-08-01 12:24:01 +00:00
const self = this
2019-07-31 21:59:36 +00:00
const handlers = new Array(OpcodesAndDefaults.size)
2019-08-01 12:24:01 +00:00
2019-07-31 21:59:36 +00:00
for (const [name, { op, defaults }] of OpcodesAndDefaults) {
const nativeSignal = binding[`fuse_native_signal_${name}`]
if (!nativeSignal) continue
handlers[op] = makeHandler(name, op, defaults, nativeSignal)
}
return handlers
function makeHandler (name, op, defaults, nativeSignal) {
2019-08-01 12:24:01 +00:00
return function () {
const boundSignal = signal.bind(null, arguments[0])
2019-08-06 08:55:08 +00:00
const funcName = `_op_${name}`
2019-08-01 15:00:14 +00:00
if (!self[funcName] || !self._implemented.has(op)) return boundSignal(-1, ...defaults)
return self[funcName].apply(self, [boundSignal, ...[...arguments].slice(2)])
2019-07-31 21:59:36 +00:00
}
2019-08-01 12:24:01 +00:00
function signal (nativeHandler, err, ...args) {
2019-08-07 10:44:13 +00:00
var arr = [nativeHandler, err, ...args]
if (defaults && (!args || !args.length)) arr = arr.concat(defaults)
2019-08-06 09:24:04 +00:00
return process.nextTick(nativeSignal, ...arr)
2019-07-31 21:59:36 +00:00
}
}
}
2019-08-06 08:55:08 +00:00
// Lifecycle methods
_open (cb) {
2019-08-07 10:54:00 +00:00
if (this._closed) return process.nextTick(cb, new Error('Cannot reopen a closed FUSE instance.'))
2019-08-06 08:55:08 +00:00
this._thread = Buffer.alloc(binding.sizeof_fuse_thread_t)
this._openCallback = cb
const opts = this._fuseOptions()
const implemented = this._getImplementedArray()
return fs.stat(this.mnt, (err, stat) => {
if (err) return cb(new Error('Mountpoint does not exist'))
if (!stat.isDirectory()) return cb(new Error('Mountpoint is not a directory'))
return fs.stat(path.join(this.mnt, '..'), (_, parent) => {
if (parent && parent.dev !== stat.dev) return cb(new Error('Mountpoint in use'))
try {
// TODO: asyncify
binding.fuse_native_mount(this.mnt, opts, this._thread, this, this._handlers, implemented)
} catch (err) {
return cb(err)
}
})
})
}
_close (cb) {
2019-09-18 16:44:54 +00:00
if (this._closed) return process.nextTick(cb, null)
2019-08-06 08:55:08 +00:00
const self = this
const mnt = JSON.stringify(this.mnt)
2019-09-18 16:44:54 +00:00
const cmd = IS_OSX ? `diskutil umount ${mnt}` : `fusermount -uz ${mnt}`
2019-08-06 08:55:08 +00:00
2019-09-18 16:44:54 +00:00
exec(cmd, (err, stdout, stderr) => {
2019-08-06 08:55:08 +00:00
if (err) return cb(err)
2019-09-18 16:44:54 +00:00
nativeUnmount()
2019-08-06 08:55:08 +00:00
})
function nativeUnmount () {
try {
binding.fuse_native_unmount(self.mnt, self._thread)
} catch (err) {
return cb(err)
}
2019-08-07 10:54:00 +00:00
self._closed = true
2019-08-06 08:55:08 +00:00
return cb(null)
}
}
// Handlers
_op_init (signal) {
if (this._openCallback) {
process.nextTick(this._openCallback, null)
this._openCallback = null
}
if (!this.ops.init) {
signal(0)
return
}
2019-07-31 21:59:36 +00:00
this.ops.init(err => {
return signal(err)
2019-07-31 12:44:22 +00:00
})
}
2019-08-06 08:55:08 +00:00
_op_error (signal) {
if (!this.ops.error) {
signal(0)
return
}
2019-07-31 21:59:36 +00:00
this.ops.error(err => {
return signal(err)
})
}
2019-11-15 10:31:18 +00:00
_op_statfs (signal, path) {
this.ops.statfs(path, (err, statfs) => {
if (err) return signal(err)
const arr = getStatfsArray(statfs)
2019-11-15 10:31:18 +00:00
return signal(0, arr)
})
}
2019-08-06 08:55:08 +00:00
_op_getattr (signal, path) {
2019-07-31 21:59:36 +00:00
if (!this.ops.getattr) {
if (path !== '/') {
signal(Fuse.EPERM)
} else {
signal(0, getStatArray({ mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096 }))
}
return
2019-07-31 12:44:22 +00:00
}
2019-07-31 21:59:36 +00:00
this.ops.getattr(path, (err, stat) => {
2019-08-01 15:00:14 +00:00
if (err) return signal(err, getStatArray())
2019-07-31 21:59:36 +00:00
return signal(0, getStatArray(stat))
})
2019-07-24 14:52:17 +00:00
}
2019-08-06 08:55:08 +00:00
_op_fgetattr (signal, path, fd) {
if (!this.ops.fgetattr) {
if (path !== '/') {
signal(Fuse.EPERM)
} else {
signal(0, getStatArray({ mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096 }))
}
return
}
this.ops.getattr(path, (err, stat) => {
if (err) return signal(err)
return signal(0, getStatArray(stat))
})
2019-07-24 14:52:17 +00:00
}
2019-08-06 08:55:08 +00:00
_op_access (signal, path, mode) {
this.ops.access(path, mode, err => {
return signal(err)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_open (signal, path, flags) {
2019-08-01 15:00:14 +00:00
this.ops.open(path, flags, (err, fd) => {
return signal(err, fd)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_opendir (signal, path, flags) {
2019-08-01 15:00:14 +00:00
this.ops.opendir(path, flags, (err, fd) => {
return signal(err, fd)
})
2019-07-29 11:57:46 +00:00
}
2019-08-06 08:55:08 +00:00
_op_create (signal, path, mode) {
this.ops.create(path, mode, (err, fd) => {
return signal(err, fd)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_utimens (signal, path, atim, mtim) {
atim = getDoubleInt(atim, 0)
mtim = getDoubleInt(mtim, 0)
this.ops.utimens(path, atim, mtim, err => {
return signal(err)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_release (signal, path, fd) {
this.ops.release(path, fd, err => {
return signal(err)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_releasedir (signal, path, fd) {
this.ops.releasedir(path, fd, err => {
return signal(err)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_read (signal, path, fd, buf, len, offset) {
this.ops.read(path, fd, buf, len, offset, (err, bytesRead) => {
return signal(err, bytesRead)
})
2019-07-31 21:59:36 +00:00
}
2019-08-06 08:55:08 +00:00
_op_write (signal, path, fd, buf, len, offset) {
this.ops.write(path, fd, buf, len, offset, (err, bytesWritten) => {
return signal(err, bytesWritten)
})
2019-07-31 21:59:36 +00:00
}
2019-07-29 14:44:54 +00:00
2019-08-06 08:55:08 +00:00
_op_readdir (signal, path) {
2019-07-29 14:44:54 +00:00
this.ops.readdir(path, (err, names, stats) => {
2019-07-31 21:59:36 +00:00
if (err) return signal(err)
2019-07-29 14:44:54 +00:00
if (stats) stats = stats.map(getStatArray)
2019-08-01 15:00:14 +00:00
return signal(0, names, stats || [])
2019-07-29 14:44:54 +00:00
})
2019-07-29 11:57:46 +00:00
}
2019-08-06 08:55:08 +00:00
_op_setxattr (signal, path, name, value, size, position, flags) {
this.ops.setxattr(path, name, value, size, position, flags, err => {
return signal(err)
2019-07-25 10:37:14 +00:00
})
}
2019-07-29 11:57:46 +00:00
2019-08-06 08:55:08 +00:00
_op_getxattr (signal, path, name, value, size, position) {
this.ops.getxattr(path, name, value, size, position, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_listxattr (signal, path, list, size) {
this.ops.listxattr(path, list, size, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_removexattr (signal, path, name) {
this.ops.removexattr(path, name, err => {
return signal(err)
})
2019-07-30 16:58:39 +00:00
}
2019-08-06 08:55:08 +00:00
_op_flush (signal, path, datasync, fd) {
this.ops.flush(path, datasync, fd, err => {
return signal(err)
})
}
2019-07-29 11:57:46 +00:00
2019-08-06 08:55:08 +00:00
_op_fsync (signal, path, datasync, fd) {
this.ops.fsync(path, datasync, fd, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_fsyncdir (signal, path, datasync, fd) {
this.ops.fsyncdir(path, datasync, fd, err => {
return signal(err)
})
2019-07-29 11:57:46 +00:00
}
2019-08-06 08:55:08 +00:00
_op_truncate (signal, path, size) {
this.ops.truncate(path, size, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_ftruncate (signal, path, size, fd) {
this.ops.ftruncate(path, size, fd, err => {
return signal(err)
})
}
2019-07-29 11:57:46 +00:00
2019-08-06 08:55:08 +00:00
_op_readlink (signal, path) {
this.ops.readlink(path, (err, linkname) => {
return signal(err, linkname)
})
2019-07-30 16:58:39 +00:00
}
2019-08-06 08:55:08 +00:00
_op_chown (signal, path, uid, gid) {
this.ops.chown(path, uid, gid, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_chmod (signal, path, mode) {
this.ops.chmod(path, mode, err => {
return signal(err)
})
}
2019-07-30 16:58:39 +00:00
2019-08-06 08:55:08 +00:00
_op_mknod (signal, path, mode, dev) {
this.ops.mknod(path, mode, dev, err => {
return signal(err)
})
}
2019-08-06 08:55:08 +00:00
_op_unlink (signal, path) {
this.ops.unlink(path, err => {
return signal(err)
})
}
2019-08-06 15:23:10 +00:00
_op_rename (signal, src, dest) {
this.ops.rename(src, dest, err => {
return signal(err)
})
}
2019-08-06 08:55:08 +00:00
_op_link (signal, src, dest) {
this.ops.link(src, dest, err => {
return signal(err)
})
2019-07-29 11:57:46 +00:00
}
2019-07-31 21:59:36 +00:00
2019-08-06 08:55:08 +00:00
_op_symlink (signal, src, dest) {
this.ops.symlink(src, dest, err => {
return signal(err)
})
}
2019-07-31 21:59:36 +00:00
2019-08-06 08:55:08 +00:00
_op_mkdir (signal, path, mode) {
this.ops.mkdir(path, mode, err => {
return signal(err)
})
}
2019-08-06 08:55:08 +00:00
_op_rmdir (signal, path) {
this.ops.rmdir(path, err => {
return signal(err)
})
}
2019-08-06 08:55:08 +00:00
_op_destroy (signal) {
this.ops.destroy(err => {
return signal(err)
})
2019-07-31 21:59:36 +00:00
}
// Public API
mount (cb) {
2019-08-06 08:55:08 +00:00
return this._open(cb)
2019-07-31 21:59:36 +00:00
}
unmount (cb) {
2019-08-06 08:55:08 +00:00
return this._close(cb)
2019-07-31 21:59:36 +00:00
}
errno (code) {
return (code && Fuse[code.toUpperCase()]) || -1
}
2019-07-29 11:57:46 +00:00
}
2019-07-31 12:44:22 +00:00
Fuse.EPERM = -1
Fuse.ENOENT = -2
Fuse.ESRCH = -3
Fuse.EINTR = -4
Fuse.EIO = -5
Fuse.ENXIO = -6
Fuse.E2BIG = -7
Fuse.ENOEXEC = -8
Fuse.EBADF = -9
Fuse.ECHILD = -10
Fuse.EAGAIN = -11
Fuse.ENOMEM = -12
Fuse.EACCES = -13
Fuse.EFAULT = -14
Fuse.ENOTBLK = -15
Fuse.EBUSY = -16
Fuse.EEXIST = -17
Fuse.EXDEV = -18
Fuse.ENODEV = -19
Fuse.ENOTDIR = -20
Fuse.EISDIR = -21
Fuse.EINVAL = -22
Fuse.ENFILE = -23
Fuse.EMFILE = -24
Fuse.ENOTTY = -25
Fuse.ETXTBSY = -26
Fuse.EFBIG = -27
Fuse.ENOSPC = -28
Fuse.ESPIPE = -29
Fuse.EROFS = -30
Fuse.EMLINK = -31
Fuse.EPIPE = -32
Fuse.EDOM = -33
Fuse.ERANGE = -34
Fuse.EDEADLK = -35
Fuse.ENAMETOOLONG = -36
Fuse.ENOLCK = -37
Fuse.ENOSYS = -38
Fuse.ENOTEMPTY = -39
Fuse.ELOOP = -40
Fuse.EWOULDBLOCK = -11
Fuse.ENOMSG = -42
Fuse.EIDRM = -43
Fuse.ECHRNG = -44
Fuse.EL2NSYNC = -45
Fuse.EL3HLT = -46
Fuse.EL3RST = -47
Fuse.ELNRNG = -48
Fuse.EUNATCH = -49
Fuse.ENOCSI = -50
Fuse.EL2HLT = -51
Fuse.EBADE = -52
Fuse.EBADR = -53
Fuse.EXFULL = -54
Fuse.ENOANO = -55
Fuse.EBADRQC = -56
Fuse.EBADSLT = -57
Fuse.EDEADLOCK = -35
Fuse.EBFONT = -59
Fuse.ENOSTR = -60
Fuse.ENODATA = -61
Fuse.ETIME = -62
Fuse.ENOSR = -63
Fuse.ENONET = -64
Fuse.ENOPKG = -65
Fuse.EREMOTE = -66
Fuse.ENOLINK = -67
Fuse.EADV = -68
Fuse.ESRMNT = -69
Fuse.ECOMM = -70
Fuse.EPROTO = -71
Fuse.EMULTIHOP = -72
Fuse.EDOTDOT = -73
Fuse.EBADMSG = -74
Fuse.EOVERFLOW = -75
Fuse.ENOTUNIQ = -76
Fuse.EBADFD = -77
Fuse.EREMCHG = -78
Fuse.ELIBACC = -79
Fuse.ELIBBAD = -80
Fuse.ELIBSCN = -81
Fuse.ELIBMAX = -82
Fuse.ELIBEXEC = -83
Fuse.EILSEQ = -84
Fuse.ERESTART = -85
Fuse.ESTRPIPE = -86
Fuse.EUSERS = -87
Fuse.ENOTSOCK = -88
Fuse.EDESTADDRREQ = -89
Fuse.EMSGSIZE = -90
Fuse.EPROTOTYPE = -91
Fuse.ENOPROTOOPT = -92
Fuse.EPROTONOSUPPORT = -93
Fuse.ESOCKTNOSUPPORT = -94
Fuse.EOPNOTSUPP = -95
Fuse.EPFNOSUPPORT = -96
Fuse.EAFNOSUPPORT = -97
Fuse.EADDRINUSE = -98
Fuse.EADDRNOTAVAIL = -99
Fuse.ENETDOWN = -100
Fuse.ENETUNREACH = -101
Fuse.ENETRESET = -102
Fuse.ECONNABORTED = -103
Fuse.ECONNRESET = -104
Fuse.ENOBUFS = -105
Fuse.EISCONN = -106
Fuse.ENOTCONN = -107
Fuse.ESHUTDOWN = -108
Fuse.ETOOMANYREFS = -109
Fuse.ETIMEDOUT = -110
Fuse.ECONNREFUSED = -111
Fuse.EHOSTDOWN = -112
Fuse.EHOSTUNREACH = -113
Fuse.EALREADY = -114
Fuse.EINPROGRESS = -115
Fuse.ESTALE = -116
Fuse.EUCLEAN = -117
Fuse.ENOTNAM = -118
Fuse.ENAVAIL = -119
Fuse.EISNAM = -120
Fuse.EREMOTEIO = -121
Fuse.EDQUOT = -122
Fuse.ENOMEDIUM = -123
Fuse.EMEDIUMTYPE = -124
2019-09-18 16:44:54 +00:00
// Forward configuration functions through the exported class.
Fuse.beforeMount = beforeMount
Fuse.beforeUnmount = beforeUnmount
Fuse.configure = configure
Fuse.unconfigure = unconfigure
Fuse.isConfigured = isConfigured
2019-07-31 12:44:22 +00:00
module.exports = Fuse
2019-07-29 11:57:46 +00:00
function getStatfsArray (statfs) {
2019-07-29 14:44:54 +00:00
const ints = new Uint32Array(11)
2019-07-29 11:57:46 +00:00
ints[0] = (statfs && statfs.bsize) || 0
ints[1] = (statfs && statfs.frsize) || 0
ints[2] = (statfs && statfs.blocks) || 0
ints[3] = (statfs && statfs.bfree) || 0
ints[4] = (statfs && statfs.bavail) || 0
ints[5] = (statfs && statfs.files) || 0
ints[6] = (statfs && statfs.ffree) || 0
ints[7] = (statfs && statfs.favail) || 0
ints[8] = (statfs && statfs.fsid) || 0
ints[9] = (statfs && statfs.flag) || 0
ints[10] = (statfs && statfs.namemax) || 0
return ints
2019-07-25 10:37:14 +00:00
}
2019-07-24 14:52:17 +00:00
2019-07-29 14:44:54 +00:00
function setDoubleInt (arr, idx, num) {
arr[idx] = num % 4294967296
arr[idx + 1] = (num - arr[idx]) / 4294967296
}
2019-08-01 12:24:01 +00:00
function getDoubleInt (arr, idx) {
2019-07-30 16:58:39 +00:00
arr = new Uint32Array(arr)
var num = arr[idx + 1] * 4294967296
num += arr[idx]
return num
}
2019-07-29 11:57:46 +00:00
function getStatArray (stat) {
2019-07-29 14:44:54 +00:00
const ints = new Uint32Array(16)
2019-07-24 14:52:17 +00:00
2019-07-29 11:57:46 +00:00
ints[0] = (stat && stat.mode) || 0
ints[1] = (stat && stat.uid) || 0
2019-08-01 12:24:01 +00:00
ints[2] = (stat && stat.gid) || 0
ints[3] = (stat && stat.size) || 0
ints[4] = (stat && stat.dev) || 0
ints[5] = (stat && stat.nlink) || 1
ints[6] = (stat && stat.ino) || 0
ints[7] = (stat && stat.rdev) || 0
ints[8] = (stat && stat.blksize) || 0
ints[9] = (stat && stat.blocks) || 0
2019-07-29 14:44:54 +00:00
setDoubleInt(ints, 10, (stat && stat.atim) || Date.now())
setDoubleInt(ints, 12, (stat && stat.atim) || Date.now())
setDoubleInt(ints, 14, (stat && stat.atim) || Date.now())
2019-07-29 11:57:46 +00:00
return ints
}