added close operation

pull/10/head
Falk Werner 6 years ago
parent 1e4647356d
commit f47868ded7

@ -41,6 +41,7 @@ add_library(fuse-wsfs
src/wsfs/operation/getattr.c
src/wsfs/operation/readdir.c
src/wsfs/operation/open.c
src/wsfs/operation/close.c
src/wsfs/operation/read.c
src/wsfs/response_parser.c
src/wsfs/server.c

@ -73,13 +73,18 @@ class FileSystem {
let entry = this._getEntry(path);
if (entry.type == "file") {
result = ((mode & FileSystem.O_ACCMODE) == FileSystem.O_RDONLY) ? true : FileSystem.BAD_NOACCESS;
result = ((mode & FileSystem.O_ACCMODE) == FileSystem.O_RDONLY) ? {handle: 1337} : FileSystem.BAD_NOACCESS;
}
return result;
}
read(path, offset, length) {
close(path, handle, mode) {
// do nothing
return true;
}
read(path, handle, offset, length) {
let result = FileSystem.BAD_NOENTRY;
let entry = this._getEntry(path);

@ -23,16 +23,40 @@ class FileSystemHandler {
switch(request.method)
{
case "getattr":
result = this._fs.getattr(request.params[0]);
{
const path = request.params[0];
result = this._fs.getattr(path);
}
break;
case "readdir":
result = this._fs.readdir(request.params[0]);
{
const path = request.params[0];
result = this._fs.readdir(path);
}
break;
case "open":
result = this._fs.open(request.params[0], request.params[1]);
{
const path = request.params[0];
const mode = request.params[1];
result = this._fs.open(path, mode);
}
break;
case "close":
{
const path = request.params[0];
const handle = request.params[1];
const mode = request.params[2];
result = this._fs.open(path, handle, mode);
}
break;
case "read":
result = this._fs.read(request.params[0], request.params[1], request.params[2]);
{
const path = request.params[0];
const handle = request.params[1];
const offset = request.params[2];
const length = request.params[3];
result = this._fs.read(path, handle, offset, length);
}
break;
default:
break;

@ -49,7 +49,8 @@ function startup() {
mode: 0755,
type: "dir",
entries: {
"hello": { mode: 0755, type: "file", /* size: 10 , */contents: "Hello, World!"}
"hello.txt" : { mode: 0444, type: "file", contents: "Hello, World!"},
"say_hello.sh": { mode: 0555, type: "file", contents: "#!/bin/sh\necho hello\n"}
}
});
let handler = new FileSystemHandler(fs, connection);

@ -0,0 +1,25 @@
#include "wsfs/operations.h"
#include <limits.h>
#include <jansson.h>
#include "wsfs/jsonrpc.h"
int wsfs_operation_close(
char const *path,
struct fuse_file_info * file_info)
{
struct fuse_context * context = fuse_get_context();
struct wsfs_jsonrpc * rpc = context->private_data;
json_t * result = NULL;
int handle = (int) (file_info->fh & INT_MAX);
wsfs_status const status = wsfs_jsonrpc_invoke(rpc, &result, "close", "sii", path, handle, file_info->flags);
if (NULL != result)
{
// unused
json_decref(result);
}
return wsfs_status_to_rc(status);
}

@ -11,10 +11,19 @@ int wsfs_operation_open(
struct wsfs_jsonrpc * rpc = context->private_data;
json_t * result = NULL;
wsfs_status const status = wsfs_jsonrpc_invoke(rpc, &result, "open", "si", path, file_info->flags);
wsfs_status status = wsfs_jsonrpc_invoke(rpc, &result, "open", "si", path, file_info->flags);
if (NULL != result)
{
// unused
json_t * handle_holder = json_object_get(result, "handle");
if ((NULL != handle_holder) && (json_is_integer(handle_holder)))
{
file_info->fh = json_integer_value(handle_holder);
}
else
{
status = WSFS_BAD_FORMAT;
}
json_decref(result);
}

@ -1,9 +1,9 @@
#include "wsfs/operations.h"
#include <string.h>
#include <limits.h>
#include <jansson.h>
#include "wsfs/util.h"
#include "wsfs/jsonrpc.h"
#define WSFS_MAX_READ_LENGTH 4096
@ -38,7 +38,7 @@ int wsfs_operation_read(
char * buffer,
size_t buffer_size,
off_t offset,
struct fuse_file_info * WSFS_UNUSED_PARAM(file_info))
struct fuse_file_info * file_info)
{
struct fuse_context * context = fuse_get_context();
struct wsfs_jsonrpc * rpc = context->private_data;
@ -46,7 +46,8 @@ int wsfs_operation_read(
int const length = (buffer_size <= WSFS_MAX_READ_LENGTH) ? (int) buffer_size : WSFS_MAX_READ_LENGTH;
int result = 0;
json_t * data = NULL;
wsfs_status status = wsfs_jsonrpc_invoke(rpc, &data, "read", "sii", path, (int) offset, length);
int handle = (file_info->fh & INT_MAX);
wsfs_status status = wsfs_jsonrpc_invoke(rpc, &data, "read", "siii", path, handle, (int) offset, length);
if (NULL != data)
{
json_t * data_holder = json_object_get(data, "data");

@ -23,6 +23,7 @@ void wsfs_operations_init(
operations->getattr = &wsfs_operation_getattr;
operations->readdir = &wsfs_operation_readdir;
operations->open = &wsfs_operation_open;
operations->release = &wsfs_operation_close;
operations->read = &wsfs_operation_read;
}

@ -23,6 +23,10 @@ extern int wsfs_operation_open(
char const *path,
struct fuse_file_info * file_info);
extern int wsfs_operation_close(
char const *path,
struct fuse_file_info * file_info);
extern int wsfs_operation_read(
const char * path,
char * buffer,

Loading…
Cancel
Save