From f47868ded719038f931f31d9b0679896cef61189 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 29 Jan 2019 23:47:08 +0100 Subject: [PATCH] added close operation --- CMakeLists.txt | 1 + src/app/www/js/filesystem.js | 9 +++++-- src/app/www/js/filesystem_handler.js | 40 ++++++++++++++++++++++------ src/app/www/js/startup.js | 3 ++- src/wsfs/operation/close.c | 25 +++++++++++++++++ src/wsfs/operation/open.c | 13 +++++++-- src/wsfs/operation/read.c | 7 ++--- src/wsfs/operations.c | 1 + src/wsfs/operations.h | 4 +++ 9 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 src/wsfs/operation/close.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 781d24e..56f0c07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/app/www/js/filesystem.js b/src/app/www/js/filesystem.js index 8a5cb88..40f6d2b 100644 --- a/src/app/www/js/filesystem.js +++ b/src/app/www/js/filesystem.js @@ -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); diff --git a/src/app/www/js/filesystem_handler.js b/src/app/www/js/filesystem_handler.js index a5f36f8..53c573b 100644 --- a/src/app/www/js/filesystem_handler.js +++ b/src/app/www/js/filesystem_handler.js @@ -23,17 +23,41 @@ class FileSystemHandler { switch(request.method) { case "getattr": - result = this._fs.getattr(request.params[0]); - break; + { + const path = request.params[0]; + result = this._fs.getattr(path); + } + break; case "readdir": - result = this._fs.readdir(request.params[0]); - break; + { + const path = request.params[0]; + result = this._fs.readdir(path); + } + break; case "open": - result = this._fs.open(request.params[0], request.params[1]); - break; + { + 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]); - break; + { + 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; } diff --git a/src/app/www/js/startup.js b/src/app/www/js/startup.js index 4bb0545..b411656 100644 --- a/src/app/www/js/startup.js +++ b/src/app/www/js/startup.js @@ -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); diff --git a/src/wsfs/operation/close.c b/src/wsfs/operation/close.c new file mode 100644 index 0000000..cf4d945 --- /dev/null +++ b/src/wsfs/operation/close.c @@ -0,0 +1,25 @@ +#include "wsfs/operations.h" + +#include + +#include +#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); +} diff --git a/src/wsfs/operation/open.c b/src/wsfs/operation/open.c index 0cf1d2d..2e307b0 100644 --- a/src/wsfs/operation/open.c +++ b/src/wsfs/operation/open.c @@ -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); } diff --git a/src/wsfs/operation/read.c b/src/wsfs/operation/read.c index 35ab390..266c442 100644 --- a/src/wsfs/operation/read.c +++ b/src/wsfs/operation/read.c @@ -1,9 +1,9 @@ #include "wsfs/operations.h" #include +#include #include -#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"); diff --git a/src/wsfs/operations.c b/src/wsfs/operations.c index 794c019..d6a9ef6 100644 --- a/src/wsfs/operations.c +++ b/src/wsfs/operations.c @@ -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; } diff --git a/src/wsfs/operations.h b/src/wsfs/operations.h index ba9debd..a47adb1 100644 --- a/src/wsfs/operations.h +++ b/src/wsfs/operations.h @@ -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,