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

fixed C function signatures + added JS methods

This commit is contained in:
Andrew Osheroff 2019-08-01 11:28:05 +02:00
parent a4f225b78b
commit bd9d36fb2f
2 changed files with 216 additions and 155 deletions

View File

@ -294,10 +294,11 @@ FUSE_METHOD(opendir, 0, 0, (const char *path, struct fuse_file_info *info), {
l->info = info; l->info = info;
}, },
{ {
napi_create_string_utf8(env, l->path, NAPI_AUTO_LENGTH, &(argv[2]));
if (l->info != NULL) { if (l->info != NULL) {
napi_create_uint32(env, l->info->fh, &(argv[2])); napi_create_uint32(env, l->info->fh, &(argv[3]));
} else { } else {
napi_create_uint32(env, 0, &(argv[2])); napi_create_uint32(env, 0, &(argv[3]));
} }
}, },
{ {
@ -329,8 +330,9 @@ FUSE_METHOD(utimens, 2, 0, (const char *path, const struct timespec tv[2]), {
from_timespec(&tv[1], l->mtim); from_timespec(&tv[1], l->mtim);
}, },
{ {
napi_create_external_arraybuffer(env, l->atim, 2 * sizeof(uint32_t), &fin, NULL, &argv[2]); napi_create_string_utf8(env, l->path, NAPI_AUTO_LENGTH, &(argv[2]));
napi_create_external_arraybuffer(env, l->mtim, 2 * sizeof(uint32_t), &fin, NULL, &argv[3]); napi_create_external_arraybuffer(env, l->atim, 2 * sizeof(uint32_t), &fin, NULL, &argv[3]);
napi_create_external_arraybuffer(env, l->mtim, 2 * sizeof(uint32_t), &fin, NULL, &argv[4]);
}, },
{}) {})

347
index.js
View File

@ -204,7 +204,7 @@ class Fuse {
const boundSignal = signal.bind(arguments[0]) const boundSignal = signal.bind(arguments[0])
const funcName = `_$name` const funcName = `_$name`
if (!this[funcName] || !this._implemented.has(op)) return boundSignal(-1, defaults) if (!this[funcName] || !this._implemented.has(op)) return boundSignal(-1, defaults)
this[funcName].apply(null, [boundSignal, [...arguments].slice(1) ]) return this[funcName].apply(null, [boundSignal, [...arguments].slice(1) ])
} }
function signal (nativeHandler, err, args) { function signal (nativeHandler, err, args) {
@ -216,78 +216,25 @@ class Fuse {
} }
_init (signal) { _init (signal) {
if (!this.ops.init) return signal(0) if (!this.ops.init) {
signal(0)
return
}
this.ops.init(err => { this.ops.init(err => {
return signal(err) return signal(err)
}) })
} }
_error (signal) { _error (signal) {
if (!this.ops.error) return signal(0) if (!this.ops.error) {
signal(0)
return
}
this.ops.error(err => { this.ops.error(err => {
return signal(err) return signal(err)
}) })
} }
_getattr (signal, path) {
if (!this.ops.getattr) {
if (path !== '/') return signal(Fuse.EPERM)
return signal(0, getStatArray({ mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096 }))
}
this.ops.getattr(path, (err, stat) => {
if (err) return signal(err)
return signal(0, getStatArray(stat))
})
}
_fgetattr (signal, path, fd) {
}
_setxattr (signal, path, name, value, size, position, flags) {
}
_getxattr (signal, path, name, value, size, position) {
}
_listxattr (signal, path, list, size) {
}
_open (signal, path) {
}
_create (signal, path, mode) {
}
_read (signal, path, fd, buf, len, offset) {
}
_write (signal, path, fd, buf, len, offset) {
}
_release (signal, path, fd) {
}
_releasedir (signal, path, fd) {
}
_readdir (signal, path) {
this.ops.readdir(path, (err, names, stats) => {
if (err) return signal(err)
if (stats) stats = stats.map(getStatArray)
return signal(null, [names, stats || []])
})
}
_statfs (signal) { _statfs (signal) {
this.ops.statfs((err, statfs) => { this.ops.statfs((err, statfs) => {
if (err) return signal(err) if (err) return signal(err)
@ -296,106 +243,218 @@ class Fuse {
}) })
} }
_fd_op (handle, op, path, fd, buf, len, offset) { _getattr (signal, path) {
const signalFunc = binding.fuse_native_signal_buffer.bind(binding) if (!this.ops.getattr) {
if (!this._implemented.has(op)) return this._signal(signalFunc, [handle, -1]) if (path !== '/') {
signal(Fuse.EPERM)
const cb = (bytesProcessed) => { } else {
return this._signal(signalFunc, [handle, bytesProcessed || 0]) 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))
})
} }
switch (op) { _fgetattr (signal, path, fd) {
case (binding.op_read): if (!this.ops.fgetattr) {
this.ops.read(path, fd, buf, len, offset, cb) if (path !== '/') {
break signal(Fuse.EPERM)
case (binding.op_write): } else {
this.ops.write(path, fd, buf, len, offset, cb) signal(0, getStatArray({ mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096 }))
break
case(binding.op_release):
this.ops.release(path, fd, cb)
break
case(binding.op_releasedir):
this.ops.releasedir(path, fd, cb)
break
default:
return this._signal(signalFunc, [handle, 0])
} }
return
}
this.ops.getattr(path, (err, stat) => {
if (err) return signal(err)
return signal(0, getStatArray(stat))
})
} }
on_stat_op (handle, op, path, fd) { _access (signal, path, mode) {
const signalFunc = binding.fuse_native_signal_stat.bind(binding) this.ops.access(path, mode, err => {
if (!this._implemented.has(op)) return this._signal(signalFunc, [handle, -1, getStatArray()]) return signal(err)
})
const cb = (err, stat) => {
const arr = getStatArray(stat)
return this._signal(signalFunc, [handle, err, arr])
} }
switch (op) { _open (signal, path) {
case (binding.op_getattr): this.ops.open(path, (err, fd) => {
this.ops.getattr(path, cb) return signal(err, fd)
break })
case (binding.op_fgetattr):
this.ops.fgetattr(path, fd, cb)
default:
return this._signal(signalFunc, [handle, -1, getStatArray()])
}
} }
on_path_op (handle, op, path, mode, flags, atim, mtim) { _opendir (signal, path) {
const signalFunc = binding.fuse_native_signal_path.bind(binding) this.ops.opendir(path, (err, fd) => {
if (!this._implemented.has(op)) return this._signal(signalFunc, [handle, -1, 0]) return signal(err, fd)
})
const cb = (err, fd) => {
return this._signal(signalFunc, [handle, err, fd || 0])
} }
switch (op) { _create (signal, path, mode) {
case (binding.op_open): this.ops.create(path, mode, (err, fd) => {
this.ops.open(path, flags, cb) return signal(err, fd)
break })
case (binding.op_create):
this.ops.create(path, mode, cb)
break
case (binding.op_access):
this.ops.access(path, mode, cb)
break
case (binding.op_utimens):
this.ops.utimens(path, getDoubleInt(atim, 0), getDoubleInt(mtim, 0), cb)
break
default:
return this._signal(signalFunc, [handle, -1, 0])
}
} }
on_xattr_op (handle, op, path, name, value, list, size, flags, position) { _utimens (signal, path, atim, mtim) {
const signalFunc = binding.fuse_native_signal_xattr.bind(binding) atim = getDoubleInt(atim, 0)
if (!this._implemented.has(op)) return this._signal(signalFunc, [handle, -1, 0]) mtim = getDoubleInt(mtim, 0)
this.ops.utimens(path, atim, mtim, err => {
const cb = err => { return signal(err)
return this._signal(signalFunc, [handle, -1]) })
} }
switch (op) { _release (signal, path, fd) {
case (binding.op_setxattr): this.ops.release(path, fd, err => {
this.ops.setxattr(path, name, value, size, position || 0, flags, cb) return signal(err)
break })
case (binding.op_getxattr):
this.ops.getxattr(path, name, value, size, position || 0, cb)
break
case (binding.op_listxattr):
this.ops.listxattr(path, list, size, cb)
break
case (binding.op_removexattr):
this.ops.removexattr(path, name, cb)
break
default:
return this._signal(signalFunc, [handle, -1])
}
} }
on_symlink (path, target) { _releasedir (signal, path, fd) {
this.ops.releasedir(path, fd, err => {
return signal(err)
})
}
_read (signal, path, fd, buf, len, offset) {
this.ops.read(path, fd, buf, len, offset, (err, bytesRead) => {
return signal(err, bytesRead)
})
}
_write (signal, path, fd, buf, len, offset) {
this.ops.write(path, fd, buf, len, offset, (err, bytesWritten) => {
return signal(err, bytesWritten)
})
}
_readdir (signal, path) {
this.ops.readdir(path, (err, names, stats) => {
if (err) return signal(err)
if (stats) stats = stats.map(getStatArray)
return signal(null, [names, stats || []])
})
}
_setxattr (signal, path, name, value, size, position, flags) {
this.ops.setxattr(path, name, value, size, position, flags, err => {
return signal(err)
})
}
_getxattr (signal, path, name, value, size, position) {
this.ops.getxattr(path, name, value, size, position, err => {
return signal(err)
})
}
_listxattr (signal, path, list, size) {
this.ops.listxattr(path, list, size, err => {
return signal(err)
})
}
_removexattr (signal, path, name) {
this.ops.removexattr(path, name, err => {
return signal(err)
})
}
_flush (signal, path, datasync, fd) {
this.ops.flush(path, datasync, fd, err => {
return signal(err)
})
}
_fsync (signal, path, datasync, fd) {
this.ops.fsync(path, datasync, fd, err => {
return signal(err)
})
}
_fsyncdir (signal, path, datasync, fd) {
this.ops.fsyncdir(path, datasync, fd, err => {
return signal(err)
})
}
_truncate (signal, path, size) {
this.ops.truncate(path, size, err => {
return signal(err)
})
}
_ftruncate (signal, path, size, fd) {
this.ops.ftruncate(path, size, fd, err => {
return signal(err)
})
}
_readlink (signal, path) {
this.ops.readlink(path, (err, linkname) => {
return signal(err, linkname)
})
}
_chown (signal, path, uid, gid) {
this.ops.chown(path, uid, gid, err => {
return signal(err)
})
}
_chmod (signal, path, mode) {
this.ops.chmod(path, mode, err => {
return signal(err)
})
}
_mknod (signal, path, mode, dev) {
this.ops.mknod(path, mode, dev, err => {
return signal(err)
})
}
_unlink (signal, path) {
this.ops.unlink(path, err => {
return signal(err)
})
}
_rename (signal, src, dest, flags) {
this.ops.rename(src, dest, flags, err => {
return signal(err)
})
}
_link (signal, src, dest) {
this.ops.link(src, dest, err => {
return signal(err)
})
}
_symlink (signal, src, dest) {
this.ops.symlink(src, dest, err => {
return signal(err)
})
}
_mkdir (signal, path, mode) {
this.ops.mkdir(path, mode, err => {
return signal(err)
})
}
_rmdir (signal, path) {
this.ops.rmdir(path, err => {
return signal(err)
})
}
_destroy (signal) {
this.ops.destroy(err => {
return signal(err)
})
} }
// Public API // Public API