1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

added implementation for ll_getatt

This commit is contained in:
Falk Werner 2019-02-02 14:25:57 +01:00
parent a9eca12b0b
commit 8960f1ff64
12 changed files with 134 additions and 27 deletions

View File

@ -20,9 +20,28 @@ class FileSystem {
constructor(root) { constructor(root) {
this.root = root; this.root = root;
this._inodes = { };
this._walk(this.root, (entry) => { this._inodes[entry.inode] = entry; });
}
_walk(node, callback) {
callback(node);
const entries = node.entries;
if (entries) {
for(let entry of Object.entries(entries)) {
this._walk(entry[1], callback);
}
}
} }
_getEntry(path) { _getEntry(path) {
if ("number" === typeof(path)) {
const inode = path;
return this._inodes[inode];
}
else {
let curItem = this.root; let curItem = this.root;
for(let item of path.split('/')) { for(let item of path.split('/')) {
@ -36,6 +55,7 @@ class FileSystem {
return curItem; return curItem;
} }
}
getattr(path) { getattr(path) {
let entry = this._getEntry(path); let entry = this._getEntry(path);

View File

@ -28,6 +28,12 @@ class FileSystemHandler {
result = this._fs.getattr(path); result = this._fs.getattr(path);
} }
break; break;
case "getattr_ll":
{
const inode = request.params[0];
result = this._fs.getattr(inode);
}
break;
case "readdir": case "readdir":
{ {
const path = request.params[0]; const path = request.params[0];

View File

@ -46,11 +46,12 @@ function startup() {
document.getElementById('connection').appendChild(connectionView.element); document.getElementById('connection').appendChild(connectionView.element);
let fs = new FileSystem({ let fs = new FileSystem({
inode: 1,
mode: 0755, mode: 0755,
type: "dir", type: "dir",
entries: { entries: {
"hello.txt" : { mode: 0444, type: "file", contents: "Hello, World!"}, "hello.txt" : { inode: 2, mode: 0444, type: "file", contents: "Hello, World!"},
"say_hello.sh": { mode: 0555, type: "file", contents: "#!/bin/sh\necho hello\n"} "say_hello.sh": { inode: 3, mode: 0555, type: "file", contents: "#!/bin/sh\necho hello\n"}
} }
}); });
let handler = new FileSystemHandler(fs, connection); let handler = new FileSystemHandler(fs, connection);

View File

@ -230,3 +230,15 @@ void wsfs_jsonrpc_on_message(
} }
} }
int wsfs_json_get_int(json_t * object, char const * key, int default_value)
{
int result = default_value;
json_t * holder = json_object_get(object, key);
if ((NULL != holder) && (json_is_integer(holder)))
{
result = json_integer_value(holder);
}
return result;
}

View File

@ -48,6 +48,9 @@ extern void wsfs_jsonrpc_on_message(
size_t length, size_t length,
void * user_data); void * user_data);
extern int wsfs_json_get_int(json_t * object, char const * key, int default_value);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -10,19 +10,6 @@
#include "wsfs/util.h" #include "wsfs/util.h"
#include "wsfs/jsonrpc.h" #include "wsfs/jsonrpc.h"
static int wsfs_json_get_int(json_t * object, char const * key, int default_value)
{
int result = default_value;
json_t * holder = json_object_get(object, key);
if ((NULL != holder) && (json_is_integer(holder)))
{
result = json_integer_value(holder);
}
return result;
}
int wsfs_operation_getattr( int wsfs_operation_getattr(
char const * path, char const * path,
struct stat * buffer, struct stat * buffer,

View File

@ -2,10 +2,13 @@
#include <errno.h> #include <errno.h>
#include "wsfs/util.h" #include "wsfs/util.h"
#include <stdio.h>
void wsfs_operation_ll_close( void wsfs_operation_ll_close(
fuse_req_t request, fuse_req_t request,
fuse_ino_t WSFS_UNUSED_PARAM(inode), fuse_ino_t WSFS_UNUSED_PARAM(inode),
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{ {
puts("close");
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }

View File

@ -1,11 +1,73 @@
#include "wsfs/operations.h" #include "wsfs/operations.h"
#include <errno.h> #include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "wsfs/jsonrpc.h"
#include "wsfs/util.h" #include "wsfs/util.h"
extern void wsfs_operation_ll_getattr ( extern void wsfs_operation_ll_getattr (
fuse_req_t request, fuse_req_t request,
fuse_ino_t WSFS_UNUSED_PARAM(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 wsfs_jsonrpc * rpc = fuse_req_userdata(request);
struct stat buffer;
json_t * data = NULL;
wsfs_status status = wsfs_jsonrpc_invoke(rpc, &data, "getattr", "i", inode);
if (NULL != data)
{
json_t * mode_holder = json_object_get(data, "mode");
json_t * type_holder = json_object_get(data, "type");
if ((NULL != mode_holder) && (json_is_integer(mode_holder)) &&
(NULL != type_holder) && (json_is_string(type_holder)))
{
memset(&buffer, 0, sizeof(struct stat));
buffer.st_mode = json_integer_value(mode_holder) & 0555;
char const * type = json_string_value(type_holder);
if (0 == strcmp("file", type))
{
buffer.st_mode |= S_IFREG;
}
else if (0 == strcmp("dir", type))
{
buffer.st_mode |= S_IFDIR;
}
buffer.st_uid = context->uid;
buffer.st_gid = context->gid;
buffer.st_nlink = 1;
buffer.st_size = wsfs_json_get_int(data, "size", 0);
buffer.st_atime = wsfs_json_get_int(data, "atime", 0);
buffer.st_mtime = wsfs_json_get_int(data, "mtime", 0);
buffer.st_ctime = wsfs_json_get_int(data, "ctime", 0);
}
else
{
status = WSFS_BAD_FORMAT;
}
json_decref(data);
}
if (WSFS_GOOD == status)
{
fuse_reply_attr(request, &buffer, 1.0);
}
else
{ {
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }
}

View File

@ -2,10 +2,14 @@
#include <errno.h> #include <errno.h>
#include "wsfs/util.h" #include "wsfs/util.h"
#include <stdio.h>
void wsfs_operation_ll_lookup ( void wsfs_operation_ll_lookup (
fuse_req_t request, fuse_req_t request,
fuse_ino_t WSFS_UNUSED_PARAM(parent), fuse_ino_t parent,
char const * WSFS_UNUSED_PARAM(name)) char const * name)
{ {
printf("lookup: inode=%lu, name=%s\n", parent, name);
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }

View File

@ -2,10 +2,13 @@
#include <errno.h> #include <errno.h>
#include "wsfs/util.h" #include "wsfs/util.h"
#include <stdio.h>
void wsfs_operation_ll_open( void wsfs_operation_ll_open(
fuse_req_t request, fuse_req_t request,
fuse_ino_t WSFS_UNUSED_PARAM(inode), fuse_ino_t WSFS_UNUSED_PARAM(inode),
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{ {
puts("open");
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }

View File

@ -2,6 +2,8 @@
#include <errno.h> #include <errno.h>
#include "wsfs/util.h" #include "wsfs/util.h"
#include <stdio.h>
void wsfs_operation_ll_read( void wsfs_operation_ll_read(
fuse_req_t request, fuse_req_t request,
fuse_ino_t WSFS_UNUSED_PARAM(inode), fuse_ino_t WSFS_UNUSED_PARAM(inode),
@ -9,5 +11,6 @@ void wsfs_operation_ll_read(
off_t WSFS_UNUSED_PARAM(offset), off_t WSFS_UNUSED_PARAM(offset),
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{ {
puts("read");
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }

View File

@ -2,6 +2,8 @@
#include <errno.h> #include <errno.h>
#include "wsfs/util.h" #include "wsfs/util.h"
#include <stdio.h>
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 WSFS_UNUSED_PARAM(inode),
@ -9,5 +11,6 @@ void wsfs_operation_ll_readdir (
off_t WSFS_UNUSED_PARAM(offset), off_t WSFS_UNUSED_PARAM(offset),
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info)) struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
{ {
puts("readdir");
fuse_reply_err(request, ENOENT); fuse_reply_err(request, ENOENT);
} }