mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added implementation of low level functions lookup and readdir
This commit is contained in:
parent
d4b0912ef1
commit
ad798654df
@ -57,6 +57,26 @@ class FileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lookup(parent, name) {
|
||||||
|
const parentEntry = this._getEntry(parent);
|
||||||
|
const entry = (parentEntry && parentEntry.entries && parentEntry.entries[name]) || null;
|
||||||
|
if (entry) {
|
||||||
|
return {
|
||||||
|
inode: entry.inode,
|
||||||
|
mode: entry.mode || parseInt("755", 8),
|
||||||
|
type: entry.type || 'file',
|
||||||
|
size: entry.size || (entry.contents && entry.contents.length) || 0,
|
||||||
|
atime: entry.atime || 0,
|
||||||
|
mtime: entry.mtime || 0,
|
||||||
|
ctime: entry.ctime || 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return FileSystem.BAD_NOENTRY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getattr(path) {
|
getattr(path) {
|
||||||
let entry = this._getEntry(path);
|
let entry = this._getEntry(path);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
@ -79,9 +99,14 @@ class FileSystem {
|
|||||||
let entry = this._getEntry(path);
|
let entry = this._getEntry(path);
|
||||||
|
|
||||||
if ((entry) && ("dir" === entry.type)) {
|
if ((entry) && ("dir" === entry.type)) {
|
||||||
result = [".", ".."];
|
result = [
|
||||||
for(let subdir of Object.keys(entry.entries)) {
|
{name: '.', inode: entry.inode},
|
||||||
result.push(subdir);
|
{name: '..', inode: 0}
|
||||||
|
];
|
||||||
|
for(let subdir of Object.entries(entry.entries)) {
|
||||||
|
const name = subdir[0];
|
||||||
|
const inode = subdir[1].inode;
|
||||||
|
result.push({name: name, inode: inode});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,13 @@ class FileSystemHandler {
|
|||||||
(request.params)) {
|
(request.params)) {
|
||||||
switch(request.method)
|
switch(request.method)
|
||||||
{
|
{
|
||||||
|
case "lookup":
|
||||||
|
{
|
||||||
|
const parent = request.params[0];
|
||||||
|
const name = request.params[1];
|
||||||
|
result = this._fs.lookup(parent, name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "getattr":
|
case "getattr":
|
||||||
{
|
{
|
||||||
const path = request.params[0];
|
const path = request.params[0];
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#include "wsfs/operations.h"
|
#include "wsfs/operations.h"
|
||||||
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -17,8 +15,6 @@ extern void wsfs_operation_ll_getattr (
|
|||||||
fuse_ino_t inode,
|
fuse_ino_t inode,
|
||||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||||
{
|
{
|
||||||
printf("getattr: inode=%lu\n", inode);
|
|
||||||
|
|
||||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||||
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||||
struct wsfs_jsonrpc * rpc = user_data->rpc;
|
struct wsfs_jsonrpc * rpc = user_data->rpc;
|
||||||
|
@ -1,15 +1,75 @@
|
|||||||
#include "wsfs/operations.h"
|
#include "wsfs/operations.h"
|
||||||
#include <errno.h>
|
|
||||||
#include "wsfs/util.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "wsfs/jsonrpc.h"
|
||||||
|
#include "wsfs/util.h"
|
||||||
|
|
||||||
void wsfs_operation_ll_lookup (
|
void wsfs_operation_ll_lookup (
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t parent,
|
fuse_ino_t parent,
|
||||||
char const * name)
|
char const * name)
|
||||||
{
|
{
|
||||||
|
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||||
|
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||||
|
struct wsfs_jsonrpc * rpc = user_data->rpc;
|
||||||
|
|
||||||
printf("lookup: inode=%lu, name=%s\n", parent, name);
|
struct fuse_entry_param buffer;
|
||||||
|
json_t * data = NULL;
|
||||||
|
wsfs_status status = wsfs_jsonrpc_invoke(rpc, &data, "lookup", "is", parent, name);
|
||||||
|
if (NULL != data)
|
||||||
|
{
|
||||||
|
json_t * inode_holder = json_object_get(data, "inode");
|
||||||
|
json_t * mode_holder = json_object_get(data, "mode");
|
||||||
|
json_t * type_holder = json_object_get(data, "type");
|
||||||
|
if ((NULL != inode_holder) && (json_is_integer(inode_holder)) &&
|
||||||
|
(NULL != mode_holder) && (json_is_integer(mode_holder)) &&
|
||||||
|
(NULL != type_holder) && (json_is_string(type_holder)))
|
||||||
|
{
|
||||||
|
memset(&buffer, 0, sizeof(struct stat));
|
||||||
|
|
||||||
|
buffer.ino = json_integer_value(inode_holder);
|
||||||
|
buffer.attr.st_mode = json_integer_value(mode_holder) & 0555;
|
||||||
|
char const * type = json_string_value(type_holder);
|
||||||
|
if (0 == strcmp("file", type))
|
||||||
|
{
|
||||||
|
buffer.attr.st_mode |= S_IFREG;
|
||||||
|
}
|
||||||
|
else if (0 == strcmp("dir", type))
|
||||||
|
{
|
||||||
|
buffer.attr.st_mode |= S_IFDIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
buffer.attr_timeout = user_data->timeout;
|
||||||
|
buffer.entry_timeout = user_data->timeout;
|
||||||
|
buffer.attr.st_uid = context->uid;
|
||||||
|
buffer.attr.st_gid = context->gid;
|
||||||
|
buffer.attr.st_nlink = 1;
|
||||||
|
buffer.attr.st_size = wsfs_json_get_int(data, "size", 0);
|
||||||
|
buffer.attr.st_atime = wsfs_json_get_int(data, "atime", 0);
|
||||||
|
buffer.attr.st_mtime = wsfs_json_get_int(data, "mtime", 0);
|
||||||
|
buffer.attr.st_ctime = wsfs_json_get_int(data, "ctime", 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = WSFS_BAD_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decref(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WSFS_GOOD == status)
|
||||||
|
{
|
||||||
|
fuse_reply_entry(request, &buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fuse_reply_err(request, ENOENT);
|
fuse_reply_err(request, ENOENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,129 @@
|
|||||||
#include "wsfs/operations.h"
|
#include "wsfs/operations.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "wsfs/jsonrpc.h"
|
||||||
#include "wsfs/util.h"
|
#include "wsfs/util.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
#define WSFS_DIRBUFFER_INITIAL_SIZE 1024
|
||||||
|
|
||||||
|
struct wsfs_dirbuffer
|
||||||
|
{
|
||||||
|
char * data;
|
||||||
|
size_t position;
|
||||||
|
size_t capacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void wsfs_dirbuffer_init(
|
||||||
|
struct wsfs_dirbuffer * buffer)
|
||||||
|
{
|
||||||
|
buffer->data = malloc(WSFS_DIRBUFFER_INITIAL_SIZE);
|
||||||
|
buffer->position = 0;
|
||||||
|
buffer->capacity = WSFS_DIRBUFFER_INITIAL_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wsfs_dirbuffer_dispose(
|
||||||
|
struct wsfs_dirbuffer * buffer)
|
||||||
|
{
|
||||||
|
free(buffer->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wsfs_dirbuffer_add(
|
||||||
|
fuse_req_t request,
|
||||||
|
struct wsfs_dirbuffer * buffer,
|
||||||
|
char const * name,
|
||||||
|
fuse_ino_t inode)
|
||||||
|
{
|
||||||
|
size_t const size = fuse_add_direntry(request, NULL, 0, name, NULL, 0);
|
||||||
|
size_t remaining = buffer->capacity - buffer->position;
|
||||||
|
while (remaining < size)
|
||||||
|
{
|
||||||
|
buffer->capacity *= 2;
|
||||||
|
buffer->data = realloc(buffer->data, buffer->capacity);
|
||||||
|
remaining = buffer->capacity - buffer->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat stat_buffer;
|
||||||
|
memset(&stat_buffer, 0, sizeof(struct stat));
|
||||||
|
stat_buffer.st_ino = inode;
|
||||||
|
fuse_add_direntry(request,
|
||||||
|
&buffer->data[buffer->position], remaining, name,
|
||||||
|
&stat_buffer, buffer->position + size);
|
||||||
|
buffer->position += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t min(size_t a, size_t b)
|
||||||
|
{
|
||||||
|
return (a < b) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
void wsfs_operation_ll_readdir (
|
void wsfs_operation_ll_readdir (
|
||||||
fuse_req_t request,
|
fuse_req_t request,
|
||||||
fuse_ino_t WSFS_UNUSED_PARAM(inode),
|
fuse_ino_t inode,
|
||||||
size_t WSFS_UNUSED_PARAM(size),
|
size_t size,
|
||||||
off_t WSFS_UNUSED_PARAM(offset),
|
off_t offset,
|
||||||
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
|
||||||
{
|
{
|
||||||
puts("readdir");
|
struct wsfs_operations_context * user_data = fuse_req_userdata(request);
|
||||||
|
struct wsfs_jsonrpc * rpc = user_data->rpc;
|
||||||
|
|
||||||
|
struct wsfs_dirbuffer buffer;
|
||||||
|
wsfs_dirbuffer_init(&buffer);
|
||||||
|
|
||||||
|
json_t * result = NULL;
|
||||||
|
wsfs_status const status = wsfs_jsonrpc_invoke(rpc, &result, "readdir", "i", inode);
|
||||||
|
if (NULL != result)
|
||||||
|
{
|
||||||
|
if (json_is_array(result))
|
||||||
|
{
|
||||||
|
bool buffer_full = false;
|
||||||
|
size_t const count = json_array_size(result);
|
||||||
|
for(size_t i = 0; (!buffer_full) && (i < count); i++)
|
||||||
|
{
|
||||||
|
json_t * entry =json_array_get(result, i);
|
||||||
|
if (json_is_object(entry))
|
||||||
|
{
|
||||||
|
json_t * name_holder = json_object_get(entry, "name");
|
||||||
|
json_t * inode_holder = json_object_get(entry, "inode");
|
||||||
|
|
||||||
|
if ((NULL != name_holder) && (json_is_string(name_holder)) &&
|
||||||
|
(NULL != inode_holder) && (json_is_integer(inode_holder)))
|
||||||
|
{
|
||||||
|
char const * name = json_string_value(name_holder);
|
||||||
|
fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder);
|
||||||
|
wsfs_dirbuffer_add(request, &buffer, name, entry_inode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decref(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WSFS_GOOD == status)
|
||||||
|
{
|
||||||
|
if (((size_t) offset) < buffer.position)
|
||||||
|
{
|
||||||
|
fuse_reply_buf(request, &buffer.data[offset],
|
||||||
|
min(buffer.position - offset, size));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fuse_reply_buf(request, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fuse_reply_err(request, ENOENT);
|
fuse_reply_err(request, ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
wsfs_dirbuffer_dispose(&buffer);
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,13 @@ int wsfs_operation_readdir(
|
|||||||
for(size_t i = 0; (!buffer_full) && (i < count); i++)
|
for(size_t i = 0; (!buffer_full) && (i < count); i++)
|
||||||
{
|
{
|
||||||
json_t * entry =json_array_get(result, i);
|
json_t * entry =json_array_get(result, i);
|
||||||
if (json_is_string(entry))
|
if (json_is_object(entry))
|
||||||
{
|
{
|
||||||
buffer_full = filler(buffer, json_string_value(entry), NULL, 0, 0);
|
json_t * name_holder = json_object_get(entry, "name");
|
||||||
|
if ((NULL != name_holder) && (json_is_string(name_holder)))
|
||||||
|
{
|
||||||
|
buffer_full = filler(buffer, json_string_value(name_holder), NULL, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user